@esengine/ecs-framework 2.1.44 → 2.1.46
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 +1 -1
- package/index.cjs.map +1 -1
- package/index.d.ts +2290 -1952
- package/index.mjs +1 -1
- package/index.mjs.map +1 -1
- package/index.umd.js +1 -1
- package/index.umd.js.map +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @esengine/ecs-framework v2.1.
|
|
2
|
+
* @esengine/ecs-framework v2.1.46
|
|
3
3
|
* TypeScript definitions
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -1123,380 +1123,263 @@ declare abstract class Component implements IComponent {
|
|
|
1123
1123
|
}
|
|
1124
1124
|
|
|
1125
1125
|
/**
|
|
1126
|
-
*
|
|
1127
|
-
* 管理场景中的所有实体,支持快速查找和批量操作
|
|
1126
|
+
* 64位掩码兼容层
|
|
1128
1127
|
*/
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1128
|
+
/**
|
|
1129
|
+
* 64位掩码数据结构,使用两个32位整数表示
|
|
1130
|
+
*/
|
|
1131
|
+
interface BitMask64Data {
|
|
1132
|
+
/** 低32位 */
|
|
1133
|
+
lo: number;
|
|
1134
|
+
/** 高32位 */
|
|
1135
|
+
hi: number;
|
|
1136
|
+
}
|
|
1137
|
+
declare class BitMask64Utils {
|
|
1138
|
+
/** 零掩码常量,所有位都为0 */
|
|
1139
|
+
static readonly ZERO: BitMask64Data;
|
|
1139
1140
|
/**
|
|
1140
|
-
*
|
|
1141
|
-
* @param
|
|
1141
|
+
* 根据位索引创建64位掩码
|
|
1142
|
+
* @param bitIndex 位索引,范围 [0, 63]
|
|
1143
|
+
* @returns 包含指定位设置为1的掩码
|
|
1144
|
+
* @throws 当位索引超出范围时抛出错误
|
|
1142
1145
|
*/
|
|
1143
|
-
|
|
1146
|
+
static create(bitIndex: number): BitMask64Data;
|
|
1144
1147
|
/**
|
|
1145
|
-
*
|
|
1146
|
-
* @param
|
|
1148
|
+
* 从32位数字创建64位掩码
|
|
1149
|
+
* @param value 32位数字值
|
|
1150
|
+
* @returns 低32位为输入值、高32位为0的掩码
|
|
1147
1151
|
*/
|
|
1148
|
-
|
|
1152
|
+
static fromNumber(value: number): BitMask64Data;
|
|
1149
1153
|
/**
|
|
1150
|
-
*
|
|
1151
|
-
* @param
|
|
1154
|
+
* 检查掩码是否包含任意指定的位
|
|
1155
|
+
* @param mask 要检查的掩码
|
|
1156
|
+
* @param bits 指定的位模式
|
|
1157
|
+
* @returns 如果掩码包含bits中的任意位则返回true
|
|
1152
1158
|
*/
|
|
1153
|
-
|
|
1159
|
+
static hasAny(mask: BitMask64Data, bits: BitMask64Data): boolean;
|
|
1154
1160
|
/**
|
|
1155
|
-
*
|
|
1156
|
-
* @param
|
|
1161
|
+
* 检查掩码是否包含所有指定的位
|
|
1162
|
+
* @param mask 要检查的掩码
|
|
1163
|
+
* @param bits 指定的位模式
|
|
1164
|
+
* @returns 如果掩码包含bits中的所有位则返回true
|
|
1157
1165
|
*/
|
|
1158
|
-
|
|
1166
|
+
static hasAll(mask: BitMask64Data, bits: BitMask64Data): boolean;
|
|
1159
1167
|
/**
|
|
1160
|
-
*
|
|
1168
|
+
* 检查掩码是否不包含任何指定的位
|
|
1169
|
+
* @param mask 要检查的掩码
|
|
1170
|
+
* @param bits 指定的位模式
|
|
1171
|
+
* @returns 如果掩码不包含bits中的任何位则返回true
|
|
1161
1172
|
*/
|
|
1162
|
-
|
|
1173
|
+
static hasNone(mask: BitMask64Data, bits: BitMask64Data): boolean;
|
|
1163
1174
|
/**
|
|
1164
|
-
*
|
|
1175
|
+
* 检查掩码是否为零
|
|
1176
|
+
* @param mask 要检查的掩码
|
|
1177
|
+
* @returns 如果掩码所有位都为0则返回true
|
|
1165
1178
|
*/
|
|
1166
|
-
|
|
1179
|
+
static isZero(mask: BitMask64Data): boolean;
|
|
1167
1180
|
/**
|
|
1168
|
-
*
|
|
1181
|
+
* 检查两个掩码是否相等
|
|
1182
|
+
* @param a 第一个掩码
|
|
1183
|
+
* @param b 第二个掩码
|
|
1184
|
+
* @returns 如果两个掩码完全相等则返回true
|
|
1169
1185
|
*/
|
|
1170
|
-
|
|
1186
|
+
static equals(a: BitMask64Data, b: BitMask64Data): boolean;
|
|
1171
1187
|
/**
|
|
1172
|
-
*
|
|
1173
|
-
* @param
|
|
1174
|
-
* @
|
|
1188
|
+
* 设置掩码中指定位为1
|
|
1189
|
+
* @param mask 要修改的掩码(原地修改)
|
|
1190
|
+
* @param bitIndex 位索引,范围 [0, 63]
|
|
1191
|
+
* @throws 当位索引超出范围时抛出错误
|
|
1175
1192
|
*/
|
|
1176
|
-
|
|
1193
|
+
static setBit(mask: BitMask64Data, bitIndex: number): void;
|
|
1177
1194
|
/**
|
|
1178
|
-
*
|
|
1179
|
-
* @param
|
|
1180
|
-
* @
|
|
1195
|
+
* 清除掩码中指定位为0
|
|
1196
|
+
* @param mask 要修改的掩码(原地修改)
|
|
1197
|
+
* @param bitIndex 位索引,范围 [0, 63]
|
|
1198
|
+
* @throws 当位索引超出范围时抛出错误
|
|
1181
1199
|
*/
|
|
1182
|
-
|
|
1200
|
+
static clearBit(mask: BitMask64Data, bitIndex: number): void;
|
|
1183
1201
|
/**
|
|
1184
|
-
*
|
|
1185
|
-
* @param
|
|
1186
|
-
* @
|
|
1202
|
+
* 对目标掩码执行按位或操作
|
|
1203
|
+
* @param target 目标掩码(原地修改)
|
|
1204
|
+
* @param other 用于按位或的掩码
|
|
1187
1205
|
*/
|
|
1188
|
-
|
|
1206
|
+
static orInPlace(target: BitMask64Data, other: BitMask64Data): void;
|
|
1189
1207
|
/**
|
|
1190
|
-
*
|
|
1191
|
-
* @param
|
|
1192
|
-
* @
|
|
1208
|
+
* 对目标掩码执行按位与操作
|
|
1209
|
+
* @param target 目标掩码(原地修改)
|
|
1210
|
+
* @param other 用于按位与的掩码
|
|
1193
1211
|
*/
|
|
1194
|
-
|
|
1212
|
+
static andInPlace(target: BitMask64Data, other: BitMask64Data): void;
|
|
1195
1213
|
/**
|
|
1196
|
-
*
|
|
1197
|
-
* @param
|
|
1198
|
-
* @
|
|
1214
|
+
* 对目标掩码执行按位异或操作
|
|
1215
|
+
* @param target 目标掩码(原地修改)
|
|
1216
|
+
* @param other 用于按位异或的掩码
|
|
1199
1217
|
*/
|
|
1200
|
-
|
|
1218
|
+
static xorInPlace(target: BitMask64Data, other: BitMask64Data): void;
|
|
1201
1219
|
/**
|
|
1202
|
-
*
|
|
1203
|
-
* @param
|
|
1220
|
+
* 清除掩码的所有位为0
|
|
1221
|
+
* @param mask 要清除的掩码(原地修改)
|
|
1204
1222
|
*/
|
|
1205
|
-
|
|
1223
|
+
static clear(mask: BitMask64Data): void;
|
|
1206
1224
|
/**
|
|
1207
|
-
*
|
|
1208
|
-
* @param
|
|
1209
|
-
* @param
|
|
1225
|
+
* 将源掩码的值复制到目标掩码
|
|
1226
|
+
* @param source 源掩码
|
|
1227
|
+
* @param target 目标掩码(原地修改)
|
|
1210
1228
|
*/
|
|
1211
|
-
|
|
1229
|
+
static copy(source: BitMask64Data, target: BitMask64Data): void;
|
|
1212
1230
|
/**
|
|
1213
|
-
*
|
|
1214
|
-
* @param
|
|
1215
|
-
* @
|
|
1231
|
+
* 创建掩码的深拷贝
|
|
1232
|
+
* @param mask 要拷贝的掩码
|
|
1233
|
+
* @returns 新的掩码对象,内容与源掩码相同
|
|
1216
1234
|
*/
|
|
1217
|
-
|
|
1235
|
+
static clone(mask: BitMask64Data): BitMask64Data;
|
|
1218
1236
|
/**
|
|
1219
|
-
*
|
|
1220
|
-
* @
|
|
1237
|
+
* 将掩码转换为字符串表示
|
|
1238
|
+
* @param mask 要转换的掩码
|
|
1239
|
+
* @param radix 进制,支持2(二进制)或16(十六进制),默认为2
|
|
1240
|
+
* @returns 掩码的字符串表示,二进制不带前缀,十六进制带0x前缀
|
|
1241
|
+
* @throws 当进制不支持时抛出错误
|
|
1221
1242
|
*/
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1243
|
+
static toString(mask: BitMask64Data, radix?: number): string;
|
|
1244
|
+
/**
|
|
1245
|
+
* 计算掩码中设置为1的位数
|
|
1246
|
+
* @param mask 要计算的掩码
|
|
1247
|
+
* @returns 掩码中1的位数
|
|
1248
|
+
*/
|
|
1249
|
+
static popCount(mask: BitMask64Data): number;
|
|
1229
1250
|
}
|
|
1230
1251
|
|
|
1231
1252
|
/**
|
|
1232
|
-
*
|
|
1253
|
+
* 启用SoA优化装饰器
|
|
1254
|
+
* 默认关闭SoA,只有在大规模批量操作场景下才建议开启
|
|
1233
1255
|
*/
|
|
1234
|
-
|
|
1256
|
+
declare function EnableSoA<T extends ComponentType>(target: T): T;
|
|
1235
1257
|
/**
|
|
1236
|
-
*
|
|
1258
|
+
* 高精度数值装饰器
|
|
1259
|
+
* 标记字段需要保持完整精度,存储为复杂对象而非TypedArray
|
|
1237
1260
|
*/
|
|
1238
|
-
|
|
1261
|
+
declare function HighPrecision(target: any, propertyKey: string | symbol): void;
|
|
1239
1262
|
/**
|
|
1240
|
-
*
|
|
1263
|
+
* 64位浮点数装饰器
|
|
1264
|
+
* 标记字段使用Float64Array存储(更高精度但更多内存)
|
|
1241
1265
|
*/
|
|
1242
|
-
|
|
1243
|
-
/** 是否只执行一次 */
|
|
1244
|
-
once?: boolean;
|
|
1245
|
-
/** 优先级(数字越大优先级越高) */
|
|
1246
|
-
priority?: number;
|
|
1247
|
-
/** 是否异步执行 */
|
|
1248
|
-
async?: boolean;
|
|
1249
|
-
/** 执行上下文 */
|
|
1250
|
-
context?: any;
|
|
1251
|
-
}
|
|
1266
|
+
declare function Float64(target: any, propertyKey: string | symbol): void;
|
|
1252
1267
|
/**
|
|
1253
|
-
*
|
|
1268
|
+
* 32位浮点数装饰器
|
|
1269
|
+
* 标记字段使用Float32Array存储(默认类型,平衡性能和精度)
|
|
1254
1270
|
*/
|
|
1255
|
-
|
|
1256
|
-
/** 事件类型 */
|
|
1257
|
-
eventType: string;
|
|
1258
|
-
/** 监听器数量 */
|
|
1259
|
-
listenerCount: number;
|
|
1260
|
-
/** 触发次数 */
|
|
1261
|
-
triggerCount: number;
|
|
1262
|
-
/** 总执行时间(毫秒) */
|
|
1263
|
-
totalExecutionTime: number;
|
|
1264
|
-
/** 平均执行时间(毫秒) */
|
|
1265
|
-
averageExecutionTime: number;
|
|
1266
|
-
/** 最后触发时间 */
|
|
1267
|
-
lastTriggerTime: number;
|
|
1268
|
-
}
|
|
1271
|
+
declare function Float32(target: any, propertyKey: string | symbol): void;
|
|
1269
1272
|
/**
|
|
1270
|
-
*
|
|
1273
|
+
* 32位整数装饰器
|
|
1274
|
+
* 标记字段使用Int32Array存储(适用于整数值)
|
|
1271
1275
|
*/
|
|
1272
|
-
|
|
1273
|
-
/** 批处理大小 */
|
|
1274
|
-
batchSize: number;
|
|
1275
|
-
/** 批处理延迟(毫秒) */
|
|
1276
|
-
delay: number;
|
|
1277
|
-
/** 是否启用批处理 */
|
|
1278
|
-
enabled: boolean;
|
|
1279
|
-
}
|
|
1276
|
+
declare function Int32(target: any, propertyKey: string | symbol): void;
|
|
1280
1277
|
/**
|
|
1281
|
-
*
|
|
1282
|
-
*
|
|
1278
|
+
* 序列化Map装饰器
|
|
1279
|
+
* 标记Map字段需要序列化/反序列化存储
|
|
1283
1280
|
*/
|
|
1284
|
-
declare
|
|
1281
|
+
declare function SerializeMap(target: any, propertyKey: string | symbol): void;
|
|
1282
|
+
/**
|
|
1283
|
+
* SoA存储器(需要装饰器启用)
|
|
1284
|
+
* 使用Structure of Arrays存储模式,在大规模批量操作时提供优异性能
|
|
1285
|
+
*/
|
|
1286
|
+
declare class SoAStorage<T extends Component> {
|
|
1285
1287
|
private static readonly _logger;
|
|
1286
|
-
private
|
|
1287
|
-
private
|
|
1288
|
-
private
|
|
1289
|
-
private
|
|
1290
|
-
private
|
|
1291
|
-
private
|
|
1292
|
-
private
|
|
1293
|
-
private
|
|
1288
|
+
private fields;
|
|
1289
|
+
private stringFields;
|
|
1290
|
+
private serializedFields;
|
|
1291
|
+
private complexFields;
|
|
1292
|
+
private entityToIndex;
|
|
1293
|
+
private indexToEntity;
|
|
1294
|
+
private freeIndices;
|
|
1295
|
+
private _size;
|
|
1296
|
+
private _capacity;
|
|
1297
|
+
readonly type: ComponentType<T>;
|
|
1298
|
+
constructor(componentType: ComponentType<T>);
|
|
1299
|
+
private initializeFields;
|
|
1300
|
+
addComponent(entityId: number, component: T): void;
|
|
1301
|
+
private updateComponentAtIndex;
|
|
1294
1302
|
/**
|
|
1295
|
-
*
|
|
1296
|
-
* @param eventType 事件类型
|
|
1297
|
-
* @param handler 事件处理器
|
|
1298
|
-
* @param config 监听器配置
|
|
1299
|
-
* @returns 监听器ID(用于移除)
|
|
1303
|
+
* 序列化值为JSON字符串
|
|
1300
1304
|
*/
|
|
1301
|
-
|
|
1305
|
+
private serializeValue;
|
|
1302
1306
|
/**
|
|
1303
|
-
*
|
|
1304
|
-
* @param eventType 事件类型
|
|
1305
|
-
* @param handler 事件处理器
|
|
1306
|
-
* @param config 监听器配置
|
|
1307
|
-
* @returns 监听器ID
|
|
1307
|
+
* 反序列化JSON字符串为值
|
|
1308
1308
|
*/
|
|
1309
|
-
|
|
1309
|
+
private deserializeValue;
|
|
1310
1310
|
/**
|
|
1311
|
-
*
|
|
1312
|
-
* @param eventType 事件类型
|
|
1313
|
-
* @param handler 异步事件处理器
|
|
1314
|
-
* @param config 监听器配置
|
|
1315
|
-
* @returns 监听器ID
|
|
1311
|
+
* 深拷贝对象
|
|
1316
1312
|
*/
|
|
1317
|
-
|
|
1313
|
+
private deepClone;
|
|
1314
|
+
getComponent(entityId: number): T | null;
|
|
1315
|
+
private getFieldType;
|
|
1316
|
+
hasComponent(entityId: number): boolean;
|
|
1317
|
+
removeComponent(entityId: number): T | null;
|
|
1318
|
+
private resize;
|
|
1319
|
+
getActiveIndices(): number[];
|
|
1320
|
+
getFieldArray(fieldName: string): Float32Array | Float64Array | Int32Array | null;
|
|
1321
|
+
getTypedFieldArray<K extends keyof T>(fieldName: K): Float32Array | Float64Array | Int32Array | null;
|
|
1322
|
+
getEntityIndex(entityId: number): number | undefined;
|
|
1323
|
+
getEntityIdByIndex(index: number): number | undefined;
|
|
1324
|
+
size(): number;
|
|
1325
|
+
clear(): void;
|
|
1326
|
+
compact(): void;
|
|
1327
|
+
getStats(): any;
|
|
1318
1328
|
/**
|
|
1319
|
-
*
|
|
1320
|
-
* @param
|
|
1321
|
-
* @param listenerId 监听器ID
|
|
1322
|
-
* @returns 是否成功移除
|
|
1329
|
+
* 执行向量化批量操作
|
|
1330
|
+
* @param operation 操作函数,接收字段数组和活跃索引
|
|
1323
1331
|
*/
|
|
1324
|
-
|
|
1332
|
+
performVectorizedOperation(operation: (fieldArrays: Map<string, Float32Array | Float64Array | Int32Array>, activeIndices: number[]) => void): void;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* 日志级别
|
|
1337
|
+
*/
|
|
1338
|
+
declare enum LogLevel {
|
|
1339
|
+
Debug = 0,
|
|
1340
|
+
Info = 1,
|
|
1341
|
+
Warn = 2,
|
|
1342
|
+
Error = 3,
|
|
1343
|
+
Fatal = 4,
|
|
1344
|
+
None = 5
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* 日志接口
|
|
1348
|
+
*/
|
|
1349
|
+
interface ILogger {
|
|
1350
|
+
debug(message: string, ...args: unknown[]): void;
|
|
1351
|
+
info(message: string, ...args: unknown[]): void;
|
|
1352
|
+
warn(message: string, ...args: unknown[]): void;
|
|
1353
|
+
error(message: string, ...args: unknown[]): void;
|
|
1354
|
+
fatal(message: string, ...args: unknown[]): void;
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* 日志配置
|
|
1358
|
+
*/
|
|
1359
|
+
interface LoggerConfig {
|
|
1360
|
+
/** 日志级别 */
|
|
1361
|
+
level: LogLevel;
|
|
1362
|
+
/** 是否启用时间戳 */
|
|
1363
|
+
enableTimestamp: boolean;
|
|
1364
|
+
/** 是否启用颜色 */
|
|
1365
|
+
enableColors: boolean;
|
|
1366
|
+
/** 日志前缀 */
|
|
1367
|
+
prefix?: string;
|
|
1368
|
+
/** 自定义输出函数 */
|
|
1369
|
+
output?: (level: LogLevel, message: string) => void;
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* 默认控制台日志实现
|
|
1373
|
+
*/
|
|
1374
|
+
declare class ConsoleLogger implements ILogger {
|
|
1375
|
+
private _config;
|
|
1376
|
+
constructor(config?: Partial<LoggerConfig>);
|
|
1325
1377
|
/**
|
|
1326
|
-
*
|
|
1327
|
-
* @param
|
|
1378
|
+
* 输出调试级别日志
|
|
1379
|
+
* @param message 日志消息
|
|
1380
|
+
* @param args 附加参数
|
|
1328
1381
|
*/
|
|
1329
|
-
|
|
1330
|
-
/**
|
|
1331
|
-
* 触发事件
|
|
1332
|
-
* @param eventType 事件类型
|
|
1333
|
-
* @param event 事件数据
|
|
1334
|
-
* @returns Promise(如果有异步监听器)
|
|
1335
|
-
*/
|
|
1336
|
-
emit<T>(eventType: string, event: T): Promise<void>;
|
|
1337
|
-
/**
|
|
1338
|
-
* 同步触发事件(忽略异步监听器)
|
|
1339
|
-
* @param eventType 事件类型
|
|
1340
|
-
* @param event 事件数据
|
|
1341
|
-
*/
|
|
1342
|
-
emitSync<T>(eventType: string, event: T): void;
|
|
1343
|
-
/**
|
|
1344
|
-
* 设置事件批处理配置
|
|
1345
|
-
* @param eventType 事件类型
|
|
1346
|
-
* @param config 批处理配置
|
|
1347
|
-
*/
|
|
1348
|
-
setBatchConfig(eventType: string, config: EventBatchConfig): void;
|
|
1349
|
-
/**
|
|
1350
|
-
* 立即处理指定事件类型的批处理队列
|
|
1351
|
-
* @param eventType 事件类型
|
|
1352
|
-
*/
|
|
1353
|
-
flushBatch(eventType: string): void;
|
|
1354
|
-
/**
|
|
1355
|
-
* 获取事件统计信息
|
|
1356
|
-
* @param eventType 事件类型(可选)
|
|
1357
|
-
* @returns 统计信息
|
|
1358
|
-
*/
|
|
1359
|
-
getStats(eventType?: string): EventStats | Map<string, EventStats>;
|
|
1360
|
-
/**
|
|
1361
|
-
* 重置统计信息
|
|
1362
|
-
* @param eventType 事件类型(可选,不指定则重置所有)
|
|
1363
|
-
*/
|
|
1364
|
-
resetStats(eventType?: string): void;
|
|
1365
|
-
/**
|
|
1366
|
-
* 启用/禁用事件系统
|
|
1367
|
-
* @param enabled 是否启用
|
|
1368
|
-
*/
|
|
1369
|
-
setEnabled(enabled: boolean): void;
|
|
1370
|
-
/**
|
|
1371
|
-
* 检查是否有指定事件类型的监听器
|
|
1372
|
-
* @param eventType 事件类型
|
|
1373
|
-
* @returns 是否有监听器
|
|
1374
|
-
*/
|
|
1375
|
-
hasListeners(eventType: string): boolean;
|
|
1376
|
-
/**
|
|
1377
|
-
* 获取指定事件类型的监听器数量
|
|
1378
|
-
* @param eventType 事件类型
|
|
1379
|
-
* @returns 监听器数量
|
|
1380
|
-
*/
|
|
1381
|
-
getListenerCount(eventType: string): number;
|
|
1382
|
-
/**
|
|
1383
|
-
* 清空所有事件监听器和数据
|
|
1384
|
-
*/
|
|
1385
|
-
clear(): void;
|
|
1386
|
-
/**
|
|
1387
|
-
* 设置每个事件类型的最大监听器数量
|
|
1388
|
-
* @param max 最大数量
|
|
1389
|
-
*/
|
|
1390
|
-
setMaxListeners(max: number): void;
|
|
1391
|
-
/**
|
|
1392
|
-
* 添加监听器的内部实现
|
|
1393
|
-
* @param eventType 事件类型
|
|
1394
|
-
* @param handler 事件处理器
|
|
1395
|
-
* @param config 配置
|
|
1396
|
-
* @returns 监听器ID
|
|
1397
|
-
*/
|
|
1398
|
-
private addListener;
|
|
1399
|
-
/**
|
|
1400
|
-
* 执行事件的内部实现
|
|
1401
|
-
* @param eventType 事件类型
|
|
1402
|
-
* @param event 事件数据
|
|
1403
|
-
*/
|
|
1404
|
-
private executeEvent;
|
|
1405
|
-
/**
|
|
1406
|
-
* 按优先级排序监听器
|
|
1407
|
-
* @param listeners 监听器数组
|
|
1408
|
-
* @returns 排序后的监听器数组
|
|
1409
|
-
*/
|
|
1410
|
-
private sortListenersByPriority;
|
|
1411
|
-
/**
|
|
1412
|
-
* 移除指定的监听器
|
|
1413
|
-
* @param eventType 事件类型
|
|
1414
|
-
* @param listenerIds 要移除的监听器ID数组
|
|
1415
|
-
*/
|
|
1416
|
-
private removeListeners;
|
|
1417
|
-
/**
|
|
1418
|
-
* 添加事件到批处理队列
|
|
1419
|
-
* @param eventType 事件类型
|
|
1420
|
-
* @param event 事件数据
|
|
1421
|
-
*/
|
|
1422
|
-
private addToBatch;
|
|
1423
|
-
/**
|
|
1424
|
-
* 处理批处理事件
|
|
1425
|
-
* @param eventType 事件类型
|
|
1426
|
-
* @param batch 批处理事件数组
|
|
1427
|
-
*/
|
|
1428
|
-
private processBatch;
|
|
1429
|
-
/**
|
|
1430
|
-
* 清除指定事件类型的批处理
|
|
1431
|
-
* @param eventType 事件类型
|
|
1432
|
-
*/
|
|
1433
|
-
private clearBatch;
|
|
1434
|
-
/**
|
|
1435
|
-
* 清除所有批处理
|
|
1436
|
-
*/
|
|
1437
|
-
private clearAllBatches;
|
|
1438
|
-
/**
|
|
1439
|
-
* 更新事件统计信息
|
|
1440
|
-
* @param eventType 事件类型
|
|
1441
|
-
* @param executionTime 执行时间
|
|
1442
|
-
*/
|
|
1443
|
-
private updateStats;
|
|
1444
|
-
/**
|
|
1445
|
-
* 创建空的统计信息
|
|
1446
|
-
* @param eventType 事件类型
|
|
1447
|
-
* @returns 空的统计信息
|
|
1448
|
-
*/
|
|
1449
|
-
private createEmptyStats;
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
/**
|
|
1453
|
-
* 日志级别
|
|
1454
|
-
*/
|
|
1455
|
-
declare enum LogLevel {
|
|
1456
|
-
Debug = 0,
|
|
1457
|
-
Info = 1,
|
|
1458
|
-
Warn = 2,
|
|
1459
|
-
Error = 3,
|
|
1460
|
-
Fatal = 4,
|
|
1461
|
-
None = 5
|
|
1462
|
-
}
|
|
1463
|
-
/**
|
|
1464
|
-
* 日志接口
|
|
1465
|
-
*/
|
|
1466
|
-
interface ILogger {
|
|
1467
|
-
debug(message: string, ...args: unknown[]): void;
|
|
1468
|
-
info(message: string, ...args: unknown[]): void;
|
|
1469
|
-
warn(message: string, ...args: unknown[]): void;
|
|
1470
|
-
error(message: string, ...args: unknown[]): void;
|
|
1471
|
-
fatal(message: string, ...args: unknown[]): void;
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
* 日志配置
|
|
1475
|
-
*/
|
|
1476
|
-
interface LoggerConfig {
|
|
1477
|
-
/** 日志级别 */
|
|
1478
|
-
level: LogLevel;
|
|
1479
|
-
/** 是否启用时间戳 */
|
|
1480
|
-
enableTimestamp: boolean;
|
|
1481
|
-
/** 是否启用颜色 */
|
|
1482
|
-
enableColors: boolean;
|
|
1483
|
-
/** 日志前缀 */
|
|
1484
|
-
prefix?: string;
|
|
1485
|
-
/** 自定义输出函数 */
|
|
1486
|
-
output?: (level: LogLevel, message: string) => void;
|
|
1487
|
-
}
|
|
1488
|
-
/**
|
|
1489
|
-
* 默认控制台日志实现
|
|
1490
|
-
*/
|
|
1491
|
-
declare class ConsoleLogger implements ILogger {
|
|
1492
|
-
private _config;
|
|
1493
|
-
constructor(config?: Partial<LoggerConfig>);
|
|
1494
|
-
/**
|
|
1495
|
-
* 输出调试级别日志
|
|
1496
|
-
* @param message 日志消息
|
|
1497
|
-
* @param args 附加参数
|
|
1498
|
-
*/
|
|
1499
|
-
debug(message: string, ...args: unknown[]): void;
|
|
1382
|
+
debug(message: string, ...args: unknown[]): void;
|
|
1500
1383
|
/**
|
|
1501
1384
|
* 输出信息级别日志
|
|
1502
1385
|
* @param message 日志消息
|
|
@@ -1606,372 +1489,122 @@ declare function createLogger(name: string): ILogger;
|
|
|
1606
1489
|
declare function setGlobalLogLevel(level: LogLevel): void;
|
|
1607
1490
|
|
|
1608
1491
|
/**
|
|
1609
|
-
*
|
|
1610
|
-
*
|
|
1611
|
-
* 为不支持BigInt的环境提供兼容实现,确保ECS框架在所有平台上都能正常运行。
|
|
1612
|
-
* 自动检测运行时环境的BigInt支持情况,并提供统一的接口。
|
|
1613
|
-
*
|
|
1614
|
-
* @example
|
|
1615
|
-
* ```typescript
|
|
1616
|
-
* // 创建兼容的BigInt值
|
|
1617
|
-
* const value = BigIntFactory.create(123);
|
|
1618
|
-
*
|
|
1619
|
-
* // 位运算
|
|
1620
|
-
* const result = value.or(BigIntFactory.create(456));
|
|
1621
|
-
*
|
|
1622
|
-
* // 检查兼容性
|
|
1623
|
-
* console.log(BigIntFactory.isNativeSupported()); // true/false
|
|
1624
|
-
* ```
|
|
1492
|
+
* 组件类型定义
|
|
1625
1493
|
*/
|
|
1494
|
+
type ComponentType<T extends Component = Component> = new (...args: any[]) => T;
|
|
1626
1495
|
/**
|
|
1627
|
-
*
|
|
1628
|
-
*
|
|
1629
|
-
* 定义了BigInt的基本操作接口,支持原生BigInt和兼容实现的统一调用。
|
|
1496
|
+
* 组件注册表
|
|
1497
|
+
* 管理组件类型的位掩码分配
|
|
1630
1498
|
*/
|
|
1631
|
-
|
|
1499
|
+
declare class ComponentRegistry {
|
|
1500
|
+
protected static readonly _logger: ILogger;
|
|
1501
|
+
private static componentTypes;
|
|
1502
|
+
private static componentNameToType;
|
|
1503
|
+
private static componentNameToId;
|
|
1504
|
+
private static maskCache;
|
|
1505
|
+
private static nextBitIndex;
|
|
1506
|
+
private static maxComponents;
|
|
1632
1507
|
/**
|
|
1633
|
-
*
|
|
1634
|
-
* @
|
|
1508
|
+
* 注册组件类型并分配位掩码
|
|
1509
|
+
* @param componentType 组件类型
|
|
1510
|
+
* @returns 分配的位索引
|
|
1635
1511
|
*/
|
|
1636
|
-
|
|
1512
|
+
static register<T extends Component>(componentType: ComponentType<T>): number;
|
|
1637
1513
|
/**
|
|
1638
|
-
*
|
|
1639
|
-
* @param
|
|
1640
|
-
* @returns
|
|
1514
|
+
* 获取组件类型的位掩码
|
|
1515
|
+
* @param componentType 组件类型
|
|
1516
|
+
* @returns 位掩码
|
|
1641
1517
|
*/
|
|
1642
|
-
|
|
1518
|
+
static getBitMask<T extends Component>(componentType: ComponentType<T>): BitMask64Data;
|
|
1643
1519
|
/**
|
|
1644
|
-
*
|
|
1645
|
-
* @param
|
|
1646
|
-
* @returns
|
|
1520
|
+
* 获取组件类型的位索引
|
|
1521
|
+
* @param componentType 组件类型
|
|
1522
|
+
* @returns 位索引
|
|
1647
1523
|
*/
|
|
1648
|
-
|
|
1524
|
+
static getBitIndex<T extends Component>(componentType: ComponentType<T>): number;
|
|
1649
1525
|
/**
|
|
1650
|
-
*
|
|
1651
|
-
* @param
|
|
1652
|
-
* @returns
|
|
1526
|
+
* 检查组件类型是否已注册
|
|
1527
|
+
* @param componentType 组件类型
|
|
1528
|
+
* @returns 是否已注册
|
|
1653
1529
|
*/
|
|
1654
|
-
|
|
1530
|
+
static isRegistered<T extends Component>(componentType: ComponentType<T>): boolean;
|
|
1655
1531
|
/**
|
|
1656
|
-
*
|
|
1657
|
-
* @param
|
|
1658
|
-
* @returns
|
|
1532
|
+
* 通过名称获取组件类型
|
|
1533
|
+
* @param componentName 组件名称
|
|
1534
|
+
* @returns 组件类型构造函数
|
|
1659
1535
|
*/
|
|
1660
|
-
|
|
1536
|
+
static getComponentType(componentName: string): Function | null;
|
|
1661
1537
|
/**
|
|
1662
|
-
*
|
|
1663
|
-
* @
|
|
1664
|
-
* @returns 运算结果
|
|
1538
|
+
* 获取所有已注册的组件类型
|
|
1539
|
+
* @returns 组件类型映射
|
|
1665
1540
|
*/
|
|
1666
|
-
|
|
1541
|
+
static getAllRegisteredTypes(): Map<Function, number>;
|
|
1667
1542
|
/**
|
|
1668
|
-
*
|
|
1669
|
-
* @
|
|
1670
|
-
* @returns 运算结果
|
|
1543
|
+
* 获取所有组件名称到类型的映射
|
|
1544
|
+
* @returns 名称到类型的映射
|
|
1671
1545
|
*/
|
|
1672
|
-
|
|
1546
|
+
static getAllComponentNames(): Map<string, Function>;
|
|
1673
1547
|
/**
|
|
1674
|
-
*
|
|
1675
|
-
* @param
|
|
1676
|
-
* @returns
|
|
1548
|
+
* 通过名称获取组件类型ID
|
|
1549
|
+
* @param componentName 组件名称
|
|
1550
|
+
* @returns 组件类型ID
|
|
1677
1551
|
*/
|
|
1678
|
-
|
|
1552
|
+
static getComponentId(componentName: string): number | undefined;
|
|
1679
1553
|
/**
|
|
1680
|
-
*
|
|
1681
|
-
* @param
|
|
1682
|
-
* @returns
|
|
1554
|
+
* 注册组件类型(通过名称)
|
|
1555
|
+
* @param componentName 组件名称
|
|
1556
|
+
* @returns 分配的组件ID
|
|
1683
1557
|
*/
|
|
1684
|
-
|
|
1558
|
+
static registerComponentByName(componentName: string): number;
|
|
1685
1559
|
/**
|
|
1686
|
-
*
|
|
1687
|
-
* @
|
|
1560
|
+
* 创建单个组件的掩码
|
|
1561
|
+
* @param componentName 组件名称
|
|
1562
|
+
* @returns 组件掩码
|
|
1688
1563
|
*/
|
|
1689
|
-
|
|
1564
|
+
static createSingleComponentMask(componentName: string): BitMask64Data;
|
|
1690
1565
|
/**
|
|
1691
|
-
*
|
|
1692
|
-
* @
|
|
1566
|
+
* 创建多个组件的掩码
|
|
1567
|
+
* @param componentNames 组件名称数组
|
|
1568
|
+
* @returns 组合掩码
|
|
1693
1569
|
*/
|
|
1694
|
-
|
|
1695
|
-
}
|
|
1696
|
-
/**
|
|
1697
|
-
* BigInt工厂类
|
|
1698
|
-
*
|
|
1699
|
-
* 自动检测运行时环境的BigInt支持情况,并提供统一的创建接口。
|
|
1700
|
-
* 在支持BigInt的环境中使用原生实现,在不支持的环境中使用兼容实现。
|
|
1701
|
-
*/
|
|
1702
|
-
declare class BigIntFactory {
|
|
1703
|
-
private static _supportsBigInt;
|
|
1704
|
-
private static _cachedZero;
|
|
1705
|
-
private static _cachedOne;
|
|
1570
|
+
static createComponentMask(componentNames: string[]): BitMask64Data;
|
|
1706
1571
|
/**
|
|
1707
|
-
*
|
|
1708
|
-
* @returns 是否支持原生BigInt
|
|
1572
|
+
* 清除掩码缓存
|
|
1709
1573
|
*/
|
|
1710
|
-
static
|
|
1574
|
+
static clearMaskCache(): void;
|
|
1711
1575
|
/**
|
|
1712
|
-
*
|
|
1713
|
-
* @returns 是否支持BigInt
|
|
1576
|
+
* 重置注册表(用于测试)
|
|
1714
1577
|
*/
|
|
1715
|
-
|
|
1578
|
+
static reset(): void;
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
/**
|
|
1582
|
+
* 高性能组件存储器
|
|
1583
|
+
*/
|
|
1584
|
+
declare class ComponentStorage<T extends Component> {
|
|
1585
|
+
private dense;
|
|
1586
|
+
private entityIds;
|
|
1587
|
+
private entityToIndex;
|
|
1588
|
+
private componentType;
|
|
1589
|
+
constructor(componentType: ComponentType<T>);
|
|
1716
1590
|
/**
|
|
1717
|
-
*
|
|
1718
|
-
* @param
|
|
1719
|
-
* @
|
|
1591
|
+
* 添加组件
|
|
1592
|
+
* @param entityId 实体ID
|
|
1593
|
+
* @param component 组件实例
|
|
1720
1594
|
*/
|
|
1721
|
-
|
|
1595
|
+
addComponent(entityId: number, component: T): void;
|
|
1722
1596
|
/**
|
|
1723
|
-
*
|
|
1724
|
-
* @
|
|
1597
|
+
* 获取组件
|
|
1598
|
+
* @param entityId 实体ID
|
|
1599
|
+
* @returns 组件实例或null
|
|
1725
1600
|
*/
|
|
1726
|
-
|
|
1601
|
+
getComponent(entityId: number): T | null;
|
|
1727
1602
|
/**
|
|
1728
|
-
*
|
|
1729
|
-
* @
|
|
1603
|
+
* 检查实体是否有此组件
|
|
1604
|
+
* @param entityId 实体ID
|
|
1605
|
+
* @returns 是否有组件
|
|
1730
1606
|
*/
|
|
1731
|
-
|
|
1732
|
-
/**
|
|
1733
|
-
* 从二进制字符串创建
|
|
1734
|
-
* @param binary 二进制字符串
|
|
1735
|
-
* @returns IBigIntLike实例
|
|
1736
|
-
*/
|
|
1737
|
-
static fromBinaryString(binary: string): IBigIntLike;
|
|
1738
|
-
/**
|
|
1739
|
-
* 从十六进制字符串创建
|
|
1740
|
-
* @param hex 十六进制字符串
|
|
1741
|
-
* @returns IBigIntLike实例
|
|
1742
|
-
*/
|
|
1743
|
-
static fromHexString(hex: string): IBigIntLike;
|
|
1744
|
-
/**
|
|
1745
|
-
* 获取环境信息
|
|
1746
|
-
* @returns 环境信息对象
|
|
1747
|
-
*/
|
|
1748
|
-
static getEnvironmentInfo(): EnvironmentInfo;
|
|
1749
|
-
/**
|
|
1750
|
-
* 检测运行环境
|
|
1751
|
-
* @returns 环境类型
|
|
1752
|
-
*/
|
|
1753
|
-
private static detectEnvironment;
|
|
1754
|
-
/**
|
|
1755
|
-
* 检测JavaScript引擎
|
|
1756
|
-
* @returns JS引擎信息
|
|
1757
|
-
*/
|
|
1758
|
-
private static detectJSEngine;
|
|
1759
|
-
}
|
|
1760
|
-
/**
|
|
1761
|
-
* 环境信息接口
|
|
1762
|
-
*/
|
|
1763
|
-
interface EnvironmentInfo {
|
|
1764
|
-
/** 是否支持BigInt */
|
|
1765
|
-
supportsBigInt: boolean;
|
|
1766
|
-
/** 运行环境 */
|
|
1767
|
-
environment: string;
|
|
1768
|
-
/** JavaScript引擎 */
|
|
1769
|
-
jsEngine: string;
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1772
|
-
/**
|
|
1773
|
-
* 启用SoA优化装饰器
|
|
1774
|
-
* 默认关闭SoA,只有在大规模批量操作场景下才建议开启
|
|
1775
|
-
*/
|
|
1776
|
-
declare function EnableSoA<T extends ComponentType>(target: T): T;
|
|
1777
|
-
/**
|
|
1778
|
-
* 高精度数值装饰器
|
|
1779
|
-
* 标记字段需要保持完整精度,存储为复杂对象而非TypedArray
|
|
1780
|
-
*/
|
|
1781
|
-
declare function HighPrecision(target: any, propertyKey: string | symbol): void;
|
|
1782
|
-
/**
|
|
1783
|
-
* 64位浮点数装饰器
|
|
1784
|
-
* 标记字段使用Float64Array存储(更高精度但更多内存)
|
|
1785
|
-
*/
|
|
1786
|
-
declare function Float64(target: any, propertyKey: string | symbol): void;
|
|
1787
|
-
/**
|
|
1788
|
-
* 32位浮点数装饰器
|
|
1789
|
-
* 标记字段使用Float32Array存储(默认类型,平衡性能和精度)
|
|
1790
|
-
*/
|
|
1791
|
-
declare function Float32(target: any, propertyKey: string | symbol): void;
|
|
1792
|
-
/**
|
|
1793
|
-
* 32位整数装饰器
|
|
1794
|
-
* 标记字段使用Int32Array存储(适用于整数值)
|
|
1795
|
-
*/
|
|
1796
|
-
declare function Int32(target: any, propertyKey: string | symbol): void;
|
|
1797
|
-
/**
|
|
1798
|
-
* 序列化Map装饰器
|
|
1799
|
-
* 标记Map字段需要序列化/反序列化存储
|
|
1800
|
-
*/
|
|
1801
|
-
declare function SerializeMap(target: any, propertyKey: string | symbol): void;
|
|
1802
|
-
/**
|
|
1803
|
-
* SoA存储器(需要装饰器启用)
|
|
1804
|
-
* 使用Structure of Arrays存储模式,在大规模批量操作时提供优异性能
|
|
1805
|
-
*/
|
|
1806
|
-
declare class SoAStorage<T extends Component> {
|
|
1807
|
-
private static readonly _logger;
|
|
1808
|
-
private fields;
|
|
1809
|
-
private stringFields;
|
|
1810
|
-
private serializedFields;
|
|
1811
|
-
private complexFields;
|
|
1812
|
-
private entityToIndex;
|
|
1813
|
-
private indexToEntity;
|
|
1814
|
-
private freeIndices;
|
|
1815
|
-
private _size;
|
|
1816
|
-
private _capacity;
|
|
1817
|
-
readonly type: ComponentType<T>;
|
|
1818
|
-
constructor(componentType: ComponentType<T>);
|
|
1819
|
-
private initializeFields;
|
|
1820
|
-
addComponent(entityId: number, component: T): void;
|
|
1821
|
-
private updateComponentAtIndex;
|
|
1822
|
-
/**
|
|
1823
|
-
* 序列化值为JSON字符串
|
|
1824
|
-
*/
|
|
1825
|
-
private serializeValue;
|
|
1826
|
-
/**
|
|
1827
|
-
* 反序列化JSON字符串为值
|
|
1828
|
-
*/
|
|
1829
|
-
private deserializeValue;
|
|
1830
|
-
/**
|
|
1831
|
-
* 深拷贝对象
|
|
1832
|
-
*/
|
|
1833
|
-
private deepClone;
|
|
1834
|
-
getComponent(entityId: number): T | null;
|
|
1835
|
-
private getFieldType;
|
|
1836
|
-
hasComponent(entityId: number): boolean;
|
|
1837
|
-
removeComponent(entityId: number): T | null;
|
|
1838
|
-
private resize;
|
|
1839
|
-
getActiveIndices(): number[];
|
|
1840
|
-
getFieldArray(fieldName: string): Float32Array | Float64Array | Int32Array | null;
|
|
1841
|
-
getTypedFieldArray<K extends keyof T>(fieldName: K): Float32Array | Float64Array | Int32Array | null;
|
|
1842
|
-
getEntityIndex(entityId: number): number | undefined;
|
|
1843
|
-
getEntityIdByIndex(index: number): number | undefined;
|
|
1844
|
-
size(): number;
|
|
1845
|
-
clear(): void;
|
|
1846
|
-
compact(): void;
|
|
1847
|
-
getStats(): any;
|
|
1848
|
-
/**
|
|
1849
|
-
* 执行向量化批量操作
|
|
1850
|
-
* @param operation 操作函数,接收字段数组和活跃索引
|
|
1851
|
-
*/
|
|
1852
|
-
performVectorizedOperation(operation: (fieldArrays: Map<string, Float32Array | Float64Array | Int32Array>, activeIndices: number[]) => void): void;
|
|
1853
|
-
}
|
|
1854
|
-
|
|
1855
|
-
/**
|
|
1856
|
-
* 组件类型定义
|
|
1857
|
-
* 支持任意构造函数签名,提供更好的类型安全性
|
|
1858
|
-
*/
|
|
1859
|
-
type ComponentType<T extends Component = Component> = new (...args: any[]) => T;
|
|
1860
|
-
/**
|
|
1861
|
-
* 组件注册表
|
|
1862
|
-
* 管理组件类型的位掩码分配
|
|
1863
|
-
*/
|
|
1864
|
-
declare class ComponentRegistry {
|
|
1865
|
-
protected static readonly _logger: ILogger;
|
|
1866
|
-
private static componentTypes;
|
|
1867
|
-
private static componentNameToType;
|
|
1868
|
-
private static componentNameToId;
|
|
1869
|
-
private static maskCache;
|
|
1870
|
-
private static nextBitIndex;
|
|
1871
|
-
private static maxComponents;
|
|
1872
|
-
/**
|
|
1873
|
-
* 注册组件类型并分配位掩码
|
|
1874
|
-
* @param componentType 组件类型
|
|
1875
|
-
* @returns 分配的位索引
|
|
1876
|
-
*/
|
|
1877
|
-
static register<T extends Component>(componentType: ComponentType<T>): number;
|
|
1878
|
-
/**
|
|
1879
|
-
* 获取组件类型的位掩码
|
|
1880
|
-
* @param componentType 组件类型
|
|
1881
|
-
* @returns 位掩码
|
|
1882
|
-
*/
|
|
1883
|
-
static getBitMask<T extends Component>(componentType: ComponentType<T>): IBigIntLike;
|
|
1884
|
-
/**
|
|
1885
|
-
* 获取组件类型的位索引
|
|
1886
|
-
* @param componentType 组件类型
|
|
1887
|
-
* @returns 位索引
|
|
1888
|
-
*/
|
|
1889
|
-
static getBitIndex<T extends Component>(componentType: ComponentType<T>): number;
|
|
1890
|
-
/**
|
|
1891
|
-
* 检查组件类型是否已注册
|
|
1892
|
-
* @param componentType 组件类型
|
|
1893
|
-
* @returns 是否已注册
|
|
1894
|
-
*/
|
|
1895
|
-
static isRegistered<T extends Component>(componentType: ComponentType<T>): boolean;
|
|
1896
|
-
/**
|
|
1897
|
-
* 通过名称获取组件类型
|
|
1898
|
-
* @param componentName 组件名称
|
|
1899
|
-
* @returns 组件类型构造函数
|
|
1900
|
-
*/
|
|
1901
|
-
static getComponentType(componentName: string): Function | null;
|
|
1902
|
-
/**
|
|
1903
|
-
* 获取所有已注册的组件类型
|
|
1904
|
-
* @returns 组件类型映射
|
|
1905
|
-
*/
|
|
1906
|
-
static getAllRegisteredTypes(): Map<Function, number>;
|
|
1907
|
-
/**
|
|
1908
|
-
* 获取所有组件名称到类型的映射
|
|
1909
|
-
* @returns 名称到类型的映射
|
|
1910
|
-
*/
|
|
1911
|
-
static getAllComponentNames(): Map<string, Function>;
|
|
1912
|
-
/**
|
|
1913
|
-
* 通过名称获取组件类型ID
|
|
1914
|
-
* @param componentName 组件名称
|
|
1915
|
-
* @returns 组件类型ID
|
|
1916
|
-
*/
|
|
1917
|
-
static getComponentId(componentName: string): number | undefined;
|
|
1918
|
-
/**
|
|
1919
|
-
* 注册组件类型(通过名称)
|
|
1920
|
-
* @param componentName 组件名称
|
|
1921
|
-
* @returns 分配的组件ID
|
|
1922
|
-
*/
|
|
1923
|
-
static registerComponentByName(componentName: string): number;
|
|
1924
|
-
/**
|
|
1925
|
-
* 创建单个组件的掩码
|
|
1926
|
-
* @param componentName 组件名称
|
|
1927
|
-
* @returns 组件掩码
|
|
1928
|
-
*/
|
|
1929
|
-
static createSingleComponentMask(componentName: string): IBigIntLike;
|
|
1930
|
-
/**
|
|
1931
|
-
* 创建多个组件的掩码
|
|
1932
|
-
* @param componentNames 组件名称数组
|
|
1933
|
-
* @returns 组合掩码
|
|
1934
|
-
*/
|
|
1935
|
-
static createComponentMask(componentNames: string[]): IBigIntLike;
|
|
1936
|
-
/**
|
|
1937
|
-
* 清除掩码缓存
|
|
1938
|
-
*/
|
|
1939
|
-
static clearMaskCache(): void;
|
|
1940
|
-
/**
|
|
1941
|
-
* 重置注册表(用于测试)
|
|
1942
|
-
*/
|
|
1943
|
-
static reset(): void;
|
|
1944
|
-
}
|
|
1945
|
-
/**
|
|
1946
|
-
* 高性能组件存储器
|
|
1947
|
-
* 使用SoA(Structure of Arrays)模式存储组件
|
|
1948
|
-
*/
|
|
1949
|
-
declare class ComponentStorage<T extends Component> {
|
|
1950
|
-
private components;
|
|
1951
|
-
private entityToIndex;
|
|
1952
|
-
private indexToEntity;
|
|
1953
|
-
private freeIndices;
|
|
1954
|
-
private componentType;
|
|
1955
|
-
private _size;
|
|
1956
|
-
constructor(componentType: ComponentType<T>);
|
|
1957
|
-
/**
|
|
1958
|
-
* 添加组件
|
|
1959
|
-
* @param entityId 实体ID
|
|
1960
|
-
* @param component 组件实例
|
|
1961
|
-
*/
|
|
1962
|
-
addComponent(entityId: number, component: T): void;
|
|
1963
|
-
/**
|
|
1964
|
-
* 获取组件
|
|
1965
|
-
* @param entityId 实体ID
|
|
1966
|
-
* @returns 组件实例或null
|
|
1967
|
-
*/
|
|
1968
|
-
getComponent(entityId: number): T | null;
|
|
1969
|
-
/**
|
|
1970
|
-
* 检查实体是否有此组件
|
|
1971
|
-
* @param entityId 实体ID
|
|
1972
|
-
* @returns 是否有组件
|
|
1973
|
-
*/
|
|
1974
|
-
hasComponent(entityId: number): boolean;
|
|
1607
|
+
hasComponent(entityId: number): boolean;
|
|
1975
1608
|
/**
|
|
1976
1609
|
* 移除组件
|
|
1977
1610
|
* @param entityId 实体ID
|
|
@@ -1984,7 +1617,7 @@ declare class ComponentStorage<T extends Component> {
|
|
|
1984
1617
|
*/
|
|
1985
1618
|
forEach(callback: (component: T, entityId: number, index: number) => void): void;
|
|
1986
1619
|
/**
|
|
1987
|
-
*
|
|
1620
|
+
* 获取所有组件
|
|
1988
1621
|
* @returns 组件数组
|
|
1989
1622
|
*/
|
|
1990
1623
|
getDenseArray(): {
|
|
@@ -2003,10 +1636,6 @@ declare class ComponentStorage<T extends Component> {
|
|
|
2003
1636
|
* 获取组件类型
|
|
2004
1637
|
*/
|
|
2005
1638
|
get type(): ComponentType<T>;
|
|
2006
|
-
/**
|
|
2007
|
-
* 压缩存储(移除空洞)
|
|
2008
|
-
*/
|
|
2009
|
-
compact(): void;
|
|
2010
1639
|
/**
|
|
2011
1640
|
* 获取存储统计信息
|
|
2012
1641
|
*/
|
|
@@ -2113,11 +1742,7 @@ declare class ComponentStorageManager {
|
|
|
2113
1742
|
* @param entityId 实体ID
|
|
2114
1743
|
* @returns 组件位掩码
|
|
2115
1744
|
*/
|
|
2116
|
-
getComponentMask(entityId: number):
|
|
2117
|
-
/**
|
|
2118
|
-
* 压缩所有存储器
|
|
2119
|
-
*/
|
|
2120
|
-
compactAll(): void;
|
|
1745
|
+
getComponentMask(entityId: number): BitMask64Data;
|
|
2121
1746
|
/**
|
|
2122
1747
|
* 获取所有存储器的统计信息
|
|
2123
1748
|
*/
|
|
@@ -2129,43 +1754,710 @@ declare class ComponentStorageManager {
|
|
|
2129
1754
|
}
|
|
2130
1755
|
|
|
2131
1756
|
/**
|
|
2132
|
-
*
|
|
2133
|
-
|
|
2134
|
-
type ArchetypeId = string;
|
|
2135
|
-
/**
|
|
2136
|
-
* 原型数据结构
|
|
2137
|
-
*/
|
|
2138
|
-
interface Archetype {
|
|
2139
|
-
/** 原型唯一标识符 */
|
|
2140
|
-
id: ArchetypeId;
|
|
2141
|
-
/** 包含的组件类型 */
|
|
2142
|
-
componentTypes: ComponentType[];
|
|
2143
|
-
/** 属于该原型的实体列表 */
|
|
2144
|
-
entities: Entity[];
|
|
2145
|
-
/** 原型创建时间 */
|
|
2146
|
-
createdAt: number;
|
|
2147
|
-
/** 最后更新时间 */
|
|
2148
|
-
updatedAt: number;
|
|
2149
|
-
}
|
|
2150
|
-
/**
|
|
2151
|
-
* 原型查询结果
|
|
2152
|
-
*/
|
|
2153
|
-
interface ArchetypeQueryResult {
|
|
2154
|
-
/** 匹配的原型列表 */
|
|
2155
|
-
archetypes: Archetype[];
|
|
2156
|
-
/** 所有匹配实体的总数 */
|
|
2157
|
-
totalEntities: number;
|
|
2158
|
-
/** 查询执行时间(毫秒) */
|
|
2159
|
-
executionTime: number;
|
|
2160
|
-
/** 是否使用了缓存 */
|
|
2161
|
-
fromCache: boolean;
|
|
2162
|
-
}
|
|
2163
|
-
/**
|
|
2164
|
-
* Archetype系统
|
|
2165
|
-
*
|
|
2166
|
-
* 根据实体的组件组合将实体分组到不同的原型中,提供高效的查询性能。
|
|
1757
|
+
* 增强的事件总线实现
|
|
1758
|
+
* 基于TypeSafeEventSystem,提供类型安全的事件发布订阅机制
|
|
2167
1759
|
*/
|
|
2168
|
-
declare class
|
|
1760
|
+
declare class EventBus implements IEventBus {
|
|
1761
|
+
private static readonly _logger;
|
|
1762
|
+
private eventSystem;
|
|
1763
|
+
private eventIdCounter;
|
|
1764
|
+
private isDebugMode;
|
|
1765
|
+
constructor(debugMode?: boolean);
|
|
1766
|
+
/**
|
|
1767
|
+
* 发射事件
|
|
1768
|
+
* @param eventType 事件类型
|
|
1769
|
+
* @param data 事件数据
|
|
1770
|
+
*/
|
|
1771
|
+
emit<T>(eventType: string, data: T): void;
|
|
1772
|
+
/**
|
|
1773
|
+
* 异步发射事件
|
|
1774
|
+
* @param eventType 事件类型
|
|
1775
|
+
* @param data 事件数据
|
|
1776
|
+
*/
|
|
1777
|
+
emitAsync<T>(eventType: string, data: T): Promise<void>;
|
|
1778
|
+
/**
|
|
1779
|
+
* 监听事件
|
|
1780
|
+
* @param eventType 事件类型
|
|
1781
|
+
* @param handler 事件处理器
|
|
1782
|
+
* @param config 监听器配置
|
|
1783
|
+
* @returns 监听器ID
|
|
1784
|
+
*/
|
|
1785
|
+
on<T>(eventType: string, handler: (data: T) => void, config?: IEventListenerConfig): string;
|
|
1786
|
+
/**
|
|
1787
|
+
* 监听事件(一次性)
|
|
1788
|
+
* @param eventType 事件类型
|
|
1789
|
+
* @param handler 事件处理器
|
|
1790
|
+
* @param config 监听器配置
|
|
1791
|
+
* @returns 监听器ID
|
|
1792
|
+
*/
|
|
1793
|
+
once<T>(eventType: string, handler: (data: T) => void, config?: IEventListenerConfig): string;
|
|
1794
|
+
/**
|
|
1795
|
+
* 异步监听事件
|
|
1796
|
+
* @param eventType 事件类型
|
|
1797
|
+
* @param handler 异步事件处理器
|
|
1798
|
+
* @param config 监听器配置
|
|
1799
|
+
* @returns 监听器ID
|
|
1800
|
+
*/
|
|
1801
|
+
onAsync<T>(eventType: string, handler: (data: T) => Promise<void>, config?: IEventListenerConfig): string;
|
|
1802
|
+
/**
|
|
1803
|
+
* 移除事件监听器
|
|
1804
|
+
* @param eventType 事件类型
|
|
1805
|
+
* @param listenerId 监听器ID
|
|
1806
|
+
*/
|
|
1807
|
+
off(eventType: string, listenerId: string): boolean;
|
|
1808
|
+
/**
|
|
1809
|
+
* 移除指定事件类型的所有监听器
|
|
1810
|
+
* @param eventType 事件类型
|
|
1811
|
+
*/
|
|
1812
|
+
offAll(eventType: string): void;
|
|
1813
|
+
/**
|
|
1814
|
+
* 检查是否有指定事件的监听器
|
|
1815
|
+
* @param eventType 事件类型
|
|
1816
|
+
*/
|
|
1817
|
+
hasListeners(eventType: string): boolean;
|
|
1818
|
+
/**
|
|
1819
|
+
* 获取事件统计信息
|
|
1820
|
+
* @param eventType 事件类型(可选)
|
|
1821
|
+
*/
|
|
1822
|
+
getStats(eventType?: string): IEventStats | Map<string, IEventStats>;
|
|
1823
|
+
/**
|
|
1824
|
+
* 清空所有监听器
|
|
1825
|
+
*/
|
|
1826
|
+
clear(): void;
|
|
1827
|
+
/**
|
|
1828
|
+
* 启用或禁用事件系统
|
|
1829
|
+
* @param enabled 是否启用
|
|
1830
|
+
*/
|
|
1831
|
+
setEnabled(enabled: boolean): void;
|
|
1832
|
+
/**
|
|
1833
|
+
* 设置调试模式
|
|
1834
|
+
* @param debug 是否启用调试
|
|
1835
|
+
*/
|
|
1836
|
+
setDebugMode(debug: boolean): void;
|
|
1837
|
+
/**
|
|
1838
|
+
* 设置最大监听器数量
|
|
1839
|
+
* @param max 最大数量
|
|
1840
|
+
*/
|
|
1841
|
+
setMaxListeners(max: number): void;
|
|
1842
|
+
/**
|
|
1843
|
+
* 获取监听器数量
|
|
1844
|
+
* @param eventType 事件类型
|
|
1845
|
+
*/
|
|
1846
|
+
getListenerCount(eventType: string): number;
|
|
1847
|
+
/**
|
|
1848
|
+
* 设置事件批处理配置
|
|
1849
|
+
* @param eventType 事件类型
|
|
1850
|
+
* @param batchSize 批处理大小
|
|
1851
|
+
* @param delay 延迟时间(毫秒)
|
|
1852
|
+
*/
|
|
1853
|
+
setBatchConfig(eventType: string, batchSize: number, delay: number): void;
|
|
1854
|
+
/**
|
|
1855
|
+
* 刷新指定事件的批处理队列
|
|
1856
|
+
* @param eventType 事件类型
|
|
1857
|
+
*/
|
|
1858
|
+
flushBatch(eventType: string): void;
|
|
1859
|
+
/**
|
|
1860
|
+
* 重置事件统计
|
|
1861
|
+
* @param eventType 事件类型(可选)
|
|
1862
|
+
*/
|
|
1863
|
+
resetStats(eventType?: string): void;
|
|
1864
|
+
/**
|
|
1865
|
+
* 发射实体创建事件
|
|
1866
|
+
* @param entityData 实体事件数据
|
|
1867
|
+
*/
|
|
1868
|
+
emitEntityCreated(entityData: IEntityEventData): void;
|
|
1869
|
+
/**
|
|
1870
|
+
* 发射实体销毁事件
|
|
1871
|
+
* @param entityData 实体事件数据
|
|
1872
|
+
*/
|
|
1873
|
+
emitEntityDestroyed(entityData: IEntityEventData): void;
|
|
1874
|
+
/**
|
|
1875
|
+
* 发射组件添加事件
|
|
1876
|
+
* @param componentData 组件事件数据
|
|
1877
|
+
*/
|
|
1878
|
+
emitComponentAdded(componentData: IComponentEventData): void;
|
|
1879
|
+
/**
|
|
1880
|
+
* 发射组件移除事件
|
|
1881
|
+
* @param componentData 组件事件数据
|
|
1882
|
+
*/
|
|
1883
|
+
emitComponentRemoved(componentData: IComponentEventData): void;
|
|
1884
|
+
/**
|
|
1885
|
+
* 发射系统添加事件
|
|
1886
|
+
* @param systemData 系统事件数据
|
|
1887
|
+
*/
|
|
1888
|
+
emitSystemAdded(systemData: ISystemEventData): void;
|
|
1889
|
+
/**
|
|
1890
|
+
* 发射系统移除事件
|
|
1891
|
+
* @param systemData 系统事件数据
|
|
1892
|
+
*/
|
|
1893
|
+
emitSystemRemoved(systemData: ISystemEventData): void;
|
|
1894
|
+
/**
|
|
1895
|
+
* 发射场景变化事件
|
|
1896
|
+
* @param sceneData 场景事件数据
|
|
1897
|
+
*/
|
|
1898
|
+
emitSceneChanged(sceneData: ISceneEventData): void;
|
|
1899
|
+
/**
|
|
1900
|
+
* 发射性能警告事件
|
|
1901
|
+
* @param performanceData 性能事件数据
|
|
1902
|
+
*/
|
|
1903
|
+
emitPerformanceWarning(performanceData: IPerformanceEventData): void;
|
|
1904
|
+
/**
|
|
1905
|
+
* 监听实体创建事件
|
|
1906
|
+
* @param handler 事件处理器
|
|
1907
|
+
* @param config 监听器配置
|
|
1908
|
+
*/
|
|
1909
|
+
onEntityCreated(handler: (data: IEntityEventData) => void, config?: IEventListenerConfig): string;
|
|
1910
|
+
/**
|
|
1911
|
+
* 监听组件添加事件
|
|
1912
|
+
* @param handler 事件处理器
|
|
1913
|
+
* @param config 监听器配置
|
|
1914
|
+
*/
|
|
1915
|
+
onComponentAdded(handler: (data: IComponentEventData) => void, config?: IEventListenerConfig): string;
|
|
1916
|
+
/**
|
|
1917
|
+
* 监听系统错误事件
|
|
1918
|
+
* @param handler 事件处理器
|
|
1919
|
+
* @param config 监听器配置
|
|
1920
|
+
*/
|
|
1921
|
+
onSystemError(handler: (data: ISystemEventData) => void, config?: IEventListenerConfig): string;
|
|
1922
|
+
/**
|
|
1923
|
+
* 监听性能警告事件
|
|
1924
|
+
* @param handler 事件处理器
|
|
1925
|
+
* @param config 监听器配置
|
|
1926
|
+
*/
|
|
1927
|
+
onPerformanceWarning(handler: (data: IPerformanceEventData) => void, config?: IEventListenerConfig): string;
|
|
1928
|
+
/**
|
|
1929
|
+
* 验证事件类型
|
|
1930
|
+
* @param eventType 事件类型
|
|
1931
|
+
*/
|
|
1932
|
+
private validateEventType;
|
|
1933
|
+
/**
|
|
1934
|
+
* 增强事件数据
|
|
1935
|
+
* @param eventType 事件类型
|
|
1936
|
+
* @param data 原始数据
|
|
1937
|
+
*/
|
|
1938
|
+
private enhanceEventData;
|
|
1939
|
+
/**
|
|
1940
|
+
* 转换EventStats为IEventStats
|
|
1941
|
+
* @param stats EventStats实例
|
|
1942
|
+
*/
|
|
1943
|
+
private convertEventStats;
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* 全局事件总线实例
|
|
1947
|
+
* 提供全局访问的事件总线
|
|
1948
|
+
*/
|
|
1949
|
+
declare class GlobalEventBus {
|
|
1950
|
+
private static instance;
|
|
1951
|
+
/**
|
|
1952
|
+
* 获取全局事件总线实例
|
|
1953
|
+
* @param debugMode 是否启用调试模式
|
|
1954
|
+
*/
|
|
1955
|
+
static getInstance(debugMode?: boolean): EventBus;
|
|
1956
|
+
/**
|
|
1957
|
+
* 重置全局事件总线实例
|
|
1958
|
+
* @param debugMode 是否启用调试模式
|
|
1959
|
+
*/
|
|
1960
|
+
static reset(debugMode?: boolean): EventBus;
|
|
1961
|
+
}
|
|
1962
|
+
/**
|
|
1963
|
+
* 事件装饰器工厂
|
|
1964
|
+
* 用于自动注册事件监听器
|
|
1965
|
+
*/
|
|
1966
|
+
declare function EventHandler$1(eventType: string, config?: IEventListenerConfig): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
1967
|
+
/**
|
|
1968
|
+
* 异步事件装饰器工厂
|
|
1969
|
+
* 用于自动注册异步事件监听器
|
|
1970
|
+
*/
|
|
1971
|
+
declare function AsyncEventHandler$1(eventType: string, config?: IEventListenerConfig): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
1972
|
+
|
|
1973
|
+
/**
|
|
1974
|
+
* 高性能实体列表管理器
|
|
1975
|
+
* 管理场景中的所有实体,支持快速查找和批量操作
|
|
1976
|
+
*/
|
|
1977
|
+
declare class EntityList {
|
|
1978
|
+
buffer: Entity[];
|
|
1979
|
+
private _scene;
|
|
1980
|
+
private _idToEntity;
|
|
1981
|
+
private _nameToEntities;
|
|
1982
|
+
private _entitiesToAdd;
|
|
1983
|
+
private _entitiesToRemove;
|
|
1984
|
+
private _isUpdating;
|
|
1985
|
+
get count(): number;
|
|
1986
|
+
constructor(scene: any);
|
|
1987
|
+
/**
|
|
1988
|
+
* 添加实体(立即添加或延迟添加)
|
|
1989
|
+
* @param entity 要添加的实体
|
|
1990
|
+
*/
|
|
1991
|
+
add(entity: Entity): void;
|
|
1992
|
+
/**
|
|
1993
|
+
* 立即添加实体
|
|
1994
|
+
* @param entity 要添加的实体
|
|
1995
|
+
*/
|
|
1996
|
+
private addImmediate;
|
|
1997
|
+
/**
|
|
1998
|
+
* 移除实体(立即移除或延迟移除)
|
|
1999
|
+
* @param entity 要移除的实体
|
|
2000
|
+
*/
|
|
2001
|
+
remove(entity: Entity): void;
|
|
2002
|
+
/**
|
|
2003
|
+
* 立即移除实体
|
|
2004
|
+
* @param entity 要移除的实体
|
|
2005
|
+
*/
|
|
2006
|
+
private removeImmediate;
|
|
2007
|
+
/**
|
|
2008
|
+
* 移除所有实体
|
|
2009
|
+
*/
|
|
2010
|
+
removeAllEntities(): void;
|
|
2011
|
+
/**
|
|
2012
|
+
* 更新实体列表,处理延迟操作
|
|
2013
|
+
*/
|
|
2014
|
+
updateLists(): void;
|
|
2015
|
+
/**
|
|
2016
|
+
* 更新所有实体
|
|
2017
|
+
*/
|
|
2018
|
+
update(): void;
|
|
2019
|
+
/**
|
|
2020
|
+
* 根据名称查找实体(使用索引,O(1)复杂度)
|
|
2021
|
+
* @param name 实体名称
|
|
2022
|
+
* @returns 找到的第一个实体或null
|
|
2023
|
+
*/
|
|
2024
|
+
findEntity(name: string): Entity | null;
|
|
2025
|
+
/**
|
|
2026
|
+
* 根据名称查找所有实体
|
|
2027
|
+
* @param name 实体名称
|
|
2028
|
+
* @returns 找到的所有实体数组
|
|
2029
|
+
*/
|
|
2030
|
+
findEntitiesByName(name: string): Entity[];
|
|
2031
|
+
/**
|
|
2032
|
+
* 根据ID查找实体(使用索引,O(1)复杂度)
|
|
2033
|
+
* @param id 实体ID
|
|
2034
|
+
* @returns 找到的实体或null
|
|
2035
|
+
*/
|
|
2036
|
+
findEntityById(id: number): Entity | null;
|
|
2037
|
+
/**
|
|
2038
|
+
* 根据标签查找实体
|
|
2039
|
+
* @param tag 标签
|
|
2040
|
+
* @returns 找到的所有实体数组
|
|
2041
|
+
*/
|
|
2042
|
+
findEntitiesByTag(tag: number): Entity[];
|
|
2043
|
+
/**
|
|
2044
|
+
* 根据组件类型查找实体
|
|
2045
|
+
* @param componentType 组件类型
|
|
2046
|
+
* @returns 找到的所有实体数组
|
|
2047
|
+
*/
|
|
2048
|
+
findEntitiesWithComponent<T extends Component>(componentType: new (...args: unknown[]) => T): Entity[];
|
|
2049
|
+
/**
|
|
2050
|
+
* 批量操作:对所有实体执行指定操作
|
|
2051
|
+
* @param action 要执行的操作
|
|
2052
|
+
*/
|
|
2053
|
+
forEach(action: (entity: Entity) => void): void;
|
|
2054
|
+
/**
|
|
2055
|
+
* 批量操作:对符合条件的实体执行指定操作
|
|
2056
|
+
* @param predicate 筛选条件
|
|
2057
|
+
* @param action 要执行的操作
|
|
2058
|
+
*/
|
|
2059
|
+
forEachWhere(predicate: (entity: Entity) => boolean, action: (entity: Entity) => void): void;
|
|
2060
|
+
/**
|
|
2061
|
+
* 更新名称索引
|
|
2062
|
+
* @param entity 实体
|
|
2063
|
+
* @param isAdd 是否为添加操作
|
|
2064
|
+
*/
|
|
2065
|
+
private updateNameIndex;
|
|
2066
|
+
/**
|
|
2067
|
+
* 获取实体列表的统计信息
|
|
2068
|
+
* @returns 统计信息
|
|
2069
|
+
*/
|
|
2070
|
+
getStats(): {
|
|
2071
|
+
totalEntities: number;
|
|
2072
|
+
activeEntities: number;
|
|
2073
|
+
pendingAdd: number;
|
|
2074
|
+
pendingRemove: number;
|
|
2075
|
+
nameIndexSize: number;
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
/**
|
|
2080
|
+
* 查询条件类型
|
|
2081
|
+
*/
|
|
2082
|
+
interface QueryCondition {
|
|
2083
|
+
all: ComponentType[];
|
|
2084
|
+
any: ComponentType[];
|
|
2085
|
+
none: ComponentType[];
|
|
2086
|
+
tag?: number;
|
|
2087
|
+
name?: string;
|
|
2088
|
+
component?: ComponentType;
|
|
2089
|
+
}
|
|
2090
|
+
/**
|
|
2091
|
+
* 实体匹配条件描述符
|
|
2092
|
+
*
|
|
2093
|
+
* 用于描述实体查询条件,不执行实际查询
|
|
2094
|
+
*
|
|
2095
|
+
* @example
|
|
2096
|
+
* ```typescript
|
|
2097
|
+
* const matcher = Matcher.all(Position, Velocity)
|
|
2098
|
+
* .any(Health, Shield)
|
|
2099
|
+
* .none(Dead);
|
|
2100
|
+
*
|
|
2101
|
+
* // 获取查询条件
|
|
2102
|
+
* const condition = matcher.getCondition();
|
|
2103
|
+
* ```
|
|
2104
|
+
*/
|
|
2105
|
+
declare class Matcher {
|
|
2106
|
+
private readonly condition;
|
|
2107
|
+
private constructor();
|
|
2108
|
+
/**
|
|
2109
|
+
* 创建匹配器,要求所有指定的组件
|
|
2110
|
+
* @param types 组件类型
|
|
2111
|
+
*/
|
|
2112
|
+
static all(...types: ComponentType[]): Matcher;
|
|
2113
|
+
/**
|
|
2114
|
+
* 创建匹配器,要求至少一个指定的组件
|
|
2115
|
+
* @param types 组件类型
|
|
2116
|
+
*/
|
|
2117
|
+
static any(...types: ComponentType[]): Matcher;
|
|
2118
|
+
/**
|
|
2119
|
+
* 创建匹配器,排除指定的组件
|
|
2120
|
+
* @param types 组件类型
|
|
2121
|
+
*/
|
|
2122
|
+
static none(...types: ComponentType[]): Matcher;
|
|
2123
|
+
/**
|
|
2124
|
+
* 创建按标签查询的匙配器
|
|
2125
|
+
* @param tag 标签值
|
|
2126
|
+
*/
|
|
2127
|
+
static byTag(tag: number): Matcher;
|
|
2128
|
+
/**
|
|
2129
|
+
* 创建按名称查询的匙配器
|
|
2130
|
+
* @param name 实体名称
|
|
2131
|
+
*/
|
|
2132
|
+
static byName(name: string): Matcher;
|
|
2133
|
+
/**
|
|
2134
|
+
* 创建单组件查询的匙配器
|
|
2135
|
+
* @param componentType 组件类型
|
|
2136
|
+
*/
|
|
2137
|
+
static byComponent(componentType: ComponentType): Matcher;
|
|
2138
|
+
/**
|
|
2139
|
+
* 创建复杂查询构建器
|
|
2140
|
+
*/
|
|
2141
|
+
static complex(): Matcher;
|
|
2142
|
+
/**
|
|
2143
|
+
* 创建空匙配器(向后兼容)
|
|
2144
|
+
*/
|
|
2145
|
+
static empty(): Matcher;
|
|
2146
|
+
/**
|
|
2147
|
+
* 必须包含所有指定组件
|
|
2148
|
+
* @param types 组件类型
|
|
2149
|
+
*/
|
|
2150
|
+
all(...types: ComponentType[]): Matcher;
|
|
2151
|
+
/**
|
|
2152
|
+
* 必须包含至少一个指定组件
|
|
2153
|
+
* @param types 组件类型
|
|
2154
|
+
*/
|
|
2155
|
+
any(...types: ComponentType[]): Matcher;
|
|
2156
|
+
/**
|
|
2157
|
+
* 不能包含任何指定组件
|
|
2158
|
+
* @param types 组件类型
|
|
2159
|
+
*/
|
|
2160
|
+
none(...types: ComponentType[]): Matcher;
|
|
2161
|
+
/**
|
|
2162
|
+
* 排除指定组件(别名方法)
|
|
2163
|
+
* @param types 组件类型
|
|
2164
|
+
*/
|
|
2165
|
+
exclude(...types: ComponentType[]): Matcher;
|
|
2166
|
+
/**
|
|
2167
|
+
* 至少包含其中之一(别名方法)
|
|
2168
|
+
* @param types 组件类型
|
|
2169
|
+
*/
|
|
2170
|
+
one(...types: ComponentType[]): Matcher;
|
|
2171
|
+
/**
|
|
2172
|
+
* 按标签查询
|
|
2173
|
+
* @param tag 标签值
|
|
2174
|
+
*/
|
|
2175
|
+
withTag(tag: number): Matcher;
|
|
2176
|
+
/**
|
|
2177
|
+
* 按名称查询
|
|
2178
|
+
* @param name 实体名称
|
|
2179
|
+
*/
|
|
2180
|
+
withName(name: string): Matcher;
|
|
2181
|
+
/**
|
|
2182
|
+
* 单组件查询
|
|
2183
|
+
* @param componentType 组件类型
|
|
2184
|
+
*/
|
|
2185
|
+
withComponent(componentType: ComponentType): Matcher;
|
|
2186
|
+
/**
|
|
2187
|
+
* 移除标签条件
|
|
2188
|
+
*/
|
|
2189
|
+
withoutTag(): Matcher;
|
|
2190
|
+
/**
|
|
2191
|
+
* 移除名称条件
|
|
2192
|
+
*/
|
|
2193
|
+
withoutName(): Matcher;
|
|
2194
|
+
/**
|
|
2195
|
+
* 移除单组件条件
|
|
2196
|
+
*/
|
|
2197
|
+
withoutComponent(): Matcher;
|
|
2198
|
+
/**
|
|
2199
|
+
* 获取查询条件(只读)
|
|
2200
|
+
*/
|
|
2201
|
+
getCondition(): Readonly<QueryCondition>;
|
|
2202
|
+
/**
|
|
2203
|
+
* 检查是否为空条件
|
|
2204
|
+
*/
|
|
2205
|
+
isEmpty(): boolean;
|
|
2206
|
+
/**
|
|
2207
|
+
* 重置所有条件
|
|
2208
|
+
*/
|
|
2209
|
+
reset(): Matcher;
|
|
2210
|
+
/**
|
|
2211
|
+
* 克隆匹配器
|
|
2212
|
+
*/
|
|
2213
|
+
clone(): Matcher;
|
|
2214
|
+
/**
|
|
2215
|
+
* 字符串表示
|
|
2216
|
+
*/
|
|
2217
|
+
toString(): string;
|
|
2218
|
+
}
|
|
2219
|
+
|
|
2220
|
+
/**
|
|
2221
|
+
* 世代式ID池管理器
|
|
2222
|
+
*
|
|
2223
|
+
* 用于管理实体ID的分配和回收,支持世代版本控制以防止悬空引用问题。
|
|
2224
|
+
* 世代式ID由索引和版本组成,当ID被回收时版本会递增,确保旧引用失效。
|
|
2225
|
+
*
|
|
2226
|
+
* 支持动态扩展,理论上可以支持到65535个索引(16位),每个索引65535个版本(16位)。
|
|
2227
|
+
* 总计可以处理超过42亿个独特的ID组合,完全满足ECS大规模实体需求。
|
|
2228
|
+
*
|
|
2229
|
+
* @example
|
|
2230
|
+
* ```typescript
|
|
2231
|
+
* const pool = new IdentifierPool();
|
|
2232
|
+
*
|
|
2233
|
+
* // 分配ID
|
|
2234
|
+
* const id = pool.checkOut(); // 例如: 65536 (版本1,索引0)
|
|
2235
|
+
*
|
|
2236
|
+
* // 回收ID
|
|
2237
|
+
* pool.checkIn(id);
|
|
2238
|
+
*
|
|
2239
|
+
* // 验证ID是否有效
|
|
2240
|
+
* const isValid = pool.isValid(id); // false,因为版本已递增
|
|
2241
|
+
* ```
|
|
2242
|
+
*/
|
|
2243
|
+
declare class IdentifierPool {
|
|
2244
|
+
/**
|
|
2245
|
+
* 下一个可用的索引
|
|
2246
|
+
*/
|
|
2247
|
+
private _nextAvailableIndex;
|
|
2248
|
+
/**
|
|
2249
|
+
* 空闲的索引列表
|
|
2250
|
+
*/
|
|
2251
|
+
private _freeIndices;
|
|
2252
|
+
/**
|
|
2253
|
+
* 每个索引对应的世代版本
|
|
2254
|
+
* 动态扩展的Map,按需分配内存
|
|
2255
|
+
*/
|
|
2256
|
+
private _generations;
|
|
2257
|
+
/**
|
|
2258
|
+
* 延迟回收队列
|
|
2259
|
+
* 防止在同一帧内立即重用ID,避免时序问题
|
|
2260
|
+
*/
|
|
2261
|
+
private _pendingRecycle;
|
|
2262
|
+
/**
|
|
2263
|
+
* 延迟回收时间(毫秒)
|
|
2264
|
+
*/
|
|
2265
|
+
private _recycleDelay;
|
|
2266
|
+
/**
|
|
2267
|
+
* 最大索引限制(16位)
|
|
2268
|
+
* 这是框架设计选择:16位索引 + 16位版本 = 32位ID,确保高效位操作
|
|
2269
|
+
* 不是硬件限制,而是性能和内存效率的权衡
|
|
2270
|
+
*/
|
|
2271
|
+
private static readonly MAX_INDEX;
|
|
2272
|
+
/**
|
|
2273
|
+
* 最大世代限制(16位)
|
|
2274
|
+
*/
|
|
2275
|
+
private static readonly MAX_GENERATION;
|
|
2276
|
+
/**
|
|
2277
|
+
* 内存扩展块大小
|
|
2278
|
+
* 当需要更多内存时,一次性预分配的索引数量
|
|
2279
|
+
*/
|
|
2280
|
+
private _expansionBlockSize;
|
|
2281
|
+
/**
|
|
2282
|
+
* 统计信息
|
|
2283
|
+
*/
|
|
2284
|
+
private _stats;
|
|
2285
|
+
/**
|
|
2286
|
+
* 构造函数
|
|
2287
|
+
*
|
|
2288
|
+
* @param recycleDelay 延迟回收时间(毫秒),默认为100ms
|
|
2289
|
+
* @param expansionBlockSize 内存扩展块大小,默认为1024
|
|
2290
|
+
*/
|
|
2291
|
+
constructor(recycleDelay?: number, expansionBlockSize?: number);
|
|
2292
|
+
/**
|
|
2293
|
+
* 获取一个可用的ID
|
|
2294
|
+
*
|
|
2295
|
+
* 返回一个32位ID,高16位为世代版本,低16位为索引。
|
|
2296
|
+
*
|
|
2297
|
+
* @returns 新分配的实体ID
|
|
2298
|
+
* @throws {Error} 当达到索引限制时抛出错误
|
|
2299
|
+
*/
|
|
2300
|
+
checkOut(): number;
|
|
2301
|
+
/**
|
|
2302
|
+
* 回收一个ID
|
|
2303
|
+
*
|
|
2304
|
+
* 验证ID的有效性后,将其加入延迟回收队列。
|
|
2305
|
+
* ID不会立即可重用,而是在延迟时间后才真正回收。
|
|
2306
|
+
*
|
|
2307
|
+
* @param id 要回收的实体ID
|
|
2308
|
+
* @returns 是否成功回收(ID是否有效且未被重复回收)
|
|
2309
|
+
*/
|
|
2310
|
+
checkIn(id: number): boolean;
|
|
2311
|
+
/**
|
|
2312
|
+
* 验证ID是否有效
|
|
2313
|
+
*
|
|
2314
|
+
* 检查ID的索引和世代版本是否匹配当前状态。
|
|
2315
|
+
*
|
|
2316
|
+
* @param id 要验证的实体ID
|
|
2317
|
+
* @returns ID是否有效
|
|
2318
|
+
*/
|
|
2319
|
+
isValid(id: number): boolean;
|
|
2320
|
+
/**
|
|
2321
|
+
* 获取统计信息
|
|
2322
|
+
*
|
|
2323
|
+
* @returns 池的当前状态统计
|
|
2324
|
+
*/
|
|
2325
|
+
getStats(): {
|
|
2326
|
+
/** 已分配的总索引数 */
|
|
2327
|
+
totalAllocated: number;
|
|
2328
|
+
/** 总计回收次数 */
|
|
2329
|
+
totalRecycled: number;
|
|
2330
|
+
/** 当前活跃实体数 */
|
|
2331
|
+
currentActive: number;
|
|
2332
|
+
/** 当前空闲的索引数 */
|
|
2333
|
+
currentlyFree: number;
|
|
2334
|
+
/** 等待回收的ID数 */
|
|
2335
|
+
pendingRecycle: number;
|
|
2336
|
+
/** 理论最大实体数(设计限制) */
|
|
2337
|
+
maxPossibleEntities: number;
|
|
2338
|
+
/** 当前使用的最大索引 */
|
|
2339
|
+
maxUsedIndex: number;
|
|
2340
|
+
/** 内存使用(字节) */
|
|
2341
|
+
memoryUsage: number;
|
|
2342
|
+
/** 内存扩展次数 */
|
|
2343
|
+
memoryExpansions: number;
|
|
2344
|
+
/** 平均世代版本 */
|
|
2345
|
+
averageGeneration: number;
|
|
2346
|
+
/** 世代存储大小 */
|
|
2347
|
+
generationStorageSize: number;
|
|
2348
|
+
};
|
|
2349
|
+
/**
|
|
2350
|
+
* 强制执行延迟回收处理
|
|
2351
|
+
*
|
|
2352
|
+
* 在某些情况下可能需要立即处理延迟回收队列,
|
|
2353
|
+
* 比如内存压力大或者需要精确的统计信息时。
|
|
2354
|
+
*/
|
|
2355
|
+
forceProcessDelayedRecycle(): void;
|
|
2356
|
+
/**
|
|
2357
|
+
* 清理过期的延迟回收项
|
|
2358
|
+
*
|
|
2359
|
+
* 将超过延迟时间的回收项真正回收到空闲列表中。
|
|
2360
|
+
*
|
|
2361
|
+
* @param forceAll 是否强制处理所有延迟回收项
|
|
2362
|
+
* @private
|
|
2363
|
+
*/
|
|
2364
|
+
private _processDelayedRecycle;
|
|
2365
|
+
/**
|
|
2366
|
+
* 预分配世代信息
|
|
2367
|
+
*
|
|
2368
|
+
* @param startIndex 起始索引
|
|
2369
|
+
* @param count 分配数量
|
|
2370
|
+
* @private
|
|
2371
|
+
*/
|
|
2372
|
+
private _preAllocateGenerations;
|
|
2373
|
+
/**
|
|
2374
|
+
* 确保指定索引的世代信息存在
|
|
2375
|
+
*
|
|
2376
|
+
* @param index 索引
|
|
2377
|
+
* @private
|
|
2378
|
+
*/
|
|
2379
|
+
private _ensureGenerationCapacity;
|
|
2380
|
+
/**
|
|
2381
|
+
* 计算内存使用量
|
|
2382
|
+
*
|
|
2383
|
+
* @returns 内存使用字节数
|
|
2384
|
+
* @private
|
|
2385
|
+
*/
|
|
2386
|
+
private _calculateMemoryUsage;
|
|
2387
|
+
/**
|
|
2388
|
+
* 打包索引和世代为32位ID
|
|
2389
|
+
*
|
|
2390
|
+
* @param index 索引(16位)
|
|
2391
|
+
* @param generation 世代版本(16位)
|
|
2392
|
+
* @returns 打包后的32位ID
|
|
2393
|
+
* @private
|
|
2394
|
+
*/
|
|
2395
|
+
private _packId;
|
|
2396
|
+
/**
|
|
2397
|
+
* 从ID中解包索引
|
|
2398
|
+
*
|
|
2399
|
+
* @param id 32位ID
|
|
2400
|
+
* @returns 索引部分(16位)
|
|
2401
|
+
* @private
|
|
2402
|
+
*/
|
|
2403
|
+
private _unpackIndex;
|
|
2404
|
+
/**
|
|
2405
|
+
* 从ID中解包世代版本
|
|
2406
|
+
*
|
|
2407
|
+
* @param id 32位ID
|
|
2408
|
+
* @returns 世代版本部分(16位)
|
|
2409
|
+
* @private
|
|
2410
|
+
*/
|
|
2411
|
+
private _unpackGeneration;
|
|
2412
|
+
/**
|
|
2413
|
+
* 内部ID有效性检查
|
|
2414
|
+
*
|
|
2415
|
+
* @param index 索引
|
|
2416
|
+
* @param generation 世代版本
|
|
2417
|
+
* @returns 是否有效
|
|
2418
|
+
* @private
|
|
2419
|
+
*/
|
|
2420
|
+
private _isValidId;
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
/**
|
|
2424
|
+
* 原型标识符
|
|
2425
|
+
*/
|
|
2426
|
+
type ArchetypeId = string;
|
|
2427
|
+
/**
|
|
2428
|
+
* 原型数据结构
|
|
2429
|
+
*/
|
|
2430
|
+
interface Archetype {
|
|
2431
|
+
/** 原型唯一标识符 */
|
|
2432
|
+
id: ArchetypeId;
|
|
2433
|
+
/** 包含的组件类型 */
|
|
2434
|
+
componentTypes: ComponentType[];
|
|
2435
|
+
/** 属于该原型的实体列表 */
|
|
2436
|
+
entities: Entity[];
|
|
2437
|
+
/** 原型创建时间 */
|
|
2438
|
+
createdAt: number;
|
|
2439
|
+
/** 最后更新时间 */
|
|
2440
|
+
updatedAt: number;
|
|
2441
|
+
}
|
|
2442
|
+
/**
|
|
2443
|
+
* 原型查询结果
|
|
2444
|
+
*/
|
|
2445
|
+
interface ArchetypeQueryResult {
|
|
2446
|
+
/** 匹配的原型列表 */
|
|
2447
|
+
archetypes: Archetype[];
|
|
2448
|
+
/** 所有匹配实体的总数 */
|
|
2449
|
+
totalEntities: number;
|
|
2450
|
+
/** 查询执行时间(毫秒) */
|
|
2451
|
+
executionTime: number;
|
|
2452
|
+
/** 是否使用了缓存 */
|
|
2453
|
+
fromCache: boolean;
|
|
2454
|
+
}
|
|
2455
|
+
/**
|
|
2456
|
+
* Archetype系统
|
|
2457
|
+
*
|
|
2458
|
+
* 根据实体的组件组合将实体分组到不同的原型中,提供高效的查询性能。
|
|
2459
|
+
*/
|
|
2460
|
+
declare class ArchetypeSystem {
|
|
2169
2461
|
/** 所有原型的映射表 */
|
|
2170
2462
|
private _archetypes;
|
|
2171
2463
|
/** 实体到原型的映射 */
|
|
@@ -2634,1583 +2926,1228 @@ declare class QueryBuilder {
|
|
|
2634
2926
|
}
|
|
2635
2927
|
|
|
2636
2928
|
/**
|
|
2637
|
-
*
|
|
2638
|
-
* 基于TypeSafeEventSystem,提供类型安全的事件发布订阅机制
|
|
2929
|
+
* 事件处理器函数类型
|
|
2639
2930
|
*/
|
|
2640
|
-
|
|
2641
|
-
private static readonly _logger;
|
|
2642
|
-
private eventSystem;
|
|
2643
|
-
private eventIdCounter;
|
|
2644
|
-
private isDebugMode;
|
|
2645
|
-
constructor(debugMode?: boolean);
|
|
2646
|
-
/**
|
|
2647
|
-
* 发射事件
|
|
2648
|
-
* @param eventType 事件类型
|
|
2649
|
-
* @param data 事件数据
|
|
2650
|
-
*/
|
|
2651
|
-
emit<T>(eventType: string, data: T): void;
|
|
2652
|
-
/**
|
|
2653
|
-
* 异步发射事件
|
|
2654
|
-
* @param eventType 事件类型
|
|
2655
|
-
* @param data 事件数据
|
|
2656
|
-
*/
|
|
2657
|
-
emitAsync<T>(eventType: string, data: T): Promise<void>;
|
|
2658
|
-
/**
|
|
2659
|
-
* 监听事件
|
|
2660
|
-
* @param eventType 事件类型
|
|
2661
|
-
* @param handler 事件处理器
|
|
2662
|
-
* @param config 监听器配置
|
|
2663
|
-
* @returns 监听器ID
|
|
2664
|
-
*/
|
|
2665
|
-
on<T>(eventType: string, handler: (data: T) => void, config?: IEventListenerConfig): string;
|
|
2666
|
-
/**
|
|
2667
|
-
* 监听事件(一次性)
|
|
2668
|
-
* @param eventType 事件类型
|
|
2669
|
-
* @param handler 事件处理器
|
|
2670
|
-
* @param config 监听器配置
|
|
2671
|
-
* @returns 监听器ID
|
|
2672
|
-
*/
|
|
2673
|
-
once<T>(eventType: string, handler: (data: T) => void, config?: IEventListenerConfig): string;
|
|
2674
|
-
/**
|
|
2675
|
-
* 异步监听事件
|
|
2676
|
-
* @param eventType 事件类型
|
|
2677
|
-
* @param handler 异步事件处理器
|
|
2678
|
-
* @param config 监听器配置
|
|
2679
|
-
* @returns 监听器ID
|
|
2680
|
-
*/
|
|
2681
|
-
onAsync<T>(eventType: string, handler: (data: T) => Promise<void>, config?: IEventListenerConfig): string;
|
|
2682
|
-
/**
|
|
2683
|
-
* 移除事件监听器
|
|
2684
|
-
* @param eventType 事件类型
|
|
2685
|
-
* @param listenerId 监听器ID
|
|
2686
|
-
*/
|
|
2687
|
-
off(eventType: string, listenerId: string): boolean;
|
|
2688
|
-
/**
|
|
2689
|
-
* 移除指定事件类型的所有监听器
|
|
2690
|
-
* @param eventType 事件类型
|
|
2691
|
-
*/
|
|
2692
|
-
offAll(eventType: string): void;
|
|
2693
|
-
/**
|
|
2694
|
-
* 检查是否有指定事件的监听器
|
|
2695
|
-
* @param eventType 事件类型
|
|
2696
|
-
*/
|
|
2697
|
-
hasListeners(eventType: string): boolean;
|
|
2698
|
-
/**
|
|
2699
|
-
* 获取事件统计信息
|
|
2700
|
-
* @param eventType 事件类型(可选)
|
|
2701
|
-
*/
|
|
2702
|
-
getStats(eventType?: string): IEventStats | Map<string, IEventStats>;
|
|
2703
|
-
/**
|
|
2704
|
-
* 清空所有监听器
|
|
2705
|
-
*/
|
|
2706
|
-
clear(): void;
|
|
2707
|
-
/**
|
|
2708
|
-
* 启用或禁用事件系统
|
|
2709
|
-
* @param enabled 是否启用
|
|
2710
|
-
*/
|
|
2711
|
-
setEnabled(enabled: boolean): void;
|
|
2712
|
-
/**
|
|
2713
|
-
* 设置调试模式
|
|
2714
|
-
* @param debug 是否启用调试
|
|
2715
|
-
*/
|
|
2716
|
-
setDebugMode(debug: boolean): void;
|
|
2717
|
-
/**
|
|
2718
|
-
* 设置最大监听器数量
|
|
2719
|
-
* @param max 最大数量
|
|
2720
|
-
*/
|
|
2721
|
-
setMaxListeners(max: number): void;
|
|
2722
|
-
/**
|
|
2723
|
-
* 获取监听器数量
|
|
2724
|
-
* @param eventType 事件类型
|
|
2725
|
-
*/
|
|
2726
|
-
getListenerCount(eventType: string): number;
|
|
2727
|
-
/**
|
|
2728
|
-
* 设置事件批处理配置
|
|
2729
|
-
* @param eventType 事件类型
|
|
2730
|
-
* @param batchSize 批处理大小
|
|
2731
|
-
* @param delay 延迟时间(毫秒)
|
|
2732
|
-
*/
|
|
2733
|
-
setBatchConfig(eventType: string, batchSize: number, delay: number): void;
|
|
2734
|
-
/**
|
|
2735
|
-
* 刷新指定事件的批处理队列
|
|
2736
|
-
* @param eventType 事件类型
|
|
2737
|
-
*/
|
|
2738
|
-
flushBatch(eventType: string): void;
|
|
2739
|
-
/**
|
|
2740
|
-
* 重置事件统计
|
|
2741
|
-
* @param eventType 事件类型(可选)
|
|
2742
|
-
*/
|
|
2743
|
-
resetStats(eventType?: string): void;
|
|
2744
|
-
/**
|
|
2745
|
-
* 发射实体创建事件
|
|
2746
|
-
* @param entityData 实体事件数据
|
|
2747
|
-
*/
|
|
2748
|
-
emitEntityCreated(entityData: IEntityEventData): void;
|
|
2749
|
-
/**
|
|
2750
|
-
* 发射实体销毁事件
|
|
2751
|
-
* @param entityData 实体事件数据
|
|
2752
|
-
*/
|
|
2753
|
-
emitEntityDestroyed(entityData: IEntityEventData): void;
|
|
2754
|
-
/**
|
|
2755
|
-
* 发射组件添加事件
|
|
2756
|
-
* @param componentData 组件事件数据
|
|
2757
|
-
*/
|
|
2758
|
-
emitComponentAdded(componentData: IComponentEventData): void;
|
|
2759
|
-
/**
|
|
2760
|
-
* 发射组件移除事件
|
|
2761
|
-
* @param componentData 组件事件数据
|
|
2762
|
-
*/
|
|
2763
|
-
emitComponentRemoved(componentData: IComponentEventData): void;
|
|
2764
|
-
/**
|
|
2765
|
-
* 发射系统添加事件
|
|
2766
|
-
* @param systemData 系统事件数据
|
|
2767
|
-
*/
|
|
2768
|
-
emitSystemAdded(systemData: ISystemEventData): void;
|
|
2769
|
-
/**
|
|
2770
|
-
* 发射系统移除事件
|
|
2771
|
-
* @param systemData 系统事件数据
|
|
2772
|
-
*/
|
|
2773
|
-
emitSystemRemoved(systemData: ISystemEventData): void;
|
|
2774
|
-
/**
|
|
2775
|
-
* 发射场景变化事件
|
|
2776
|
-
* @param sceneData 场景事件数据
|
|
2777
|
-
*/
|
|
2778
|
-
emitSceneChanged(sceneData: ISceneEventData): void;
|
|
2779
|
-
/**
|
|
2780
|
-
* 发射性能警告事件
|
|
2781
|
-
* @param performanceData 性能事件数据
|
|
2782
|
-
*/
|
|
2783
|
-
emitPerformanceWarning(performanceData: IPerformanceEventData): void;
|
|
2784
|
-
/**
|
|
2785
|
-
* 监听实体创建事件
|
|
2786
|
-
* @param handler 事件处理器
|
|
2787
|
-
* @param config 监听器配置
|
|
2788
|
-
*/
|
|
2789
|
-
onEntityCreated(handler: (data: IEntityEventData) => void, config?: IEventListenerConfig): string;
|
|
2790
|
-
/**
|
|
2791
|
-
* 监听组件添加事件
|
|
2792
|
-
* @param handler 事件处理器
|
|
2793
|
-
* @param config 监听器配置
|
|
2794
|
-
*/
|
|
2795
|
-
onComponentAdded(handler: (data: IComponentEventData) => void, config?: IEventListenerConfig): string;
|
|
2796
|
-
/**
|
|
2797
|
-
* 监听系统错误事件
|
|
2798
|
-
* @param handler 事件处理器
|
|
2799
|
-
* @param config 监听器配置
|
|
2800
|
-
*/
|
|
2801
|
-
onSystemError(handler: (data: ISystemEventData) => void, config?: IEventListenerConfig): string;
|
|
2802
|
-
/**
|
|
2803
|
-
* 监听性能警告事件
|
|
2804
|
-
* @param handler 事件处理器
|
|
2805
|
-
* @param config 监听器配置
|
|
2806
|
-
*/
|
|
2807
|
-
onPerformanceWarning(handler: (data: IPerformanceEventData) => void, config?: IEventListenerConfig): string;
|
|
2808
|
-
/**
|
|
2809
|
-
* 验证事件类型
|
|
2810
|
-
* @param eventType 事件类型
|
|
2811
|
-
*/
|
|
2812
|
-
private validateEventType;
|
|
2813
|
-
/**
|
|
2814
|
-
* 增强事件数据
|
|
2815
|
-
* @param eventType 事件类型
|
|
2816
|
-
* @param data 原始数据
|
|
2817
|
-
*/
|
|
2818
|
-
private enhanceEventData;
|
|
2819
|
-
/**
|
|
2820
|
-
* 转换EventStats为IEventStats
|
|
2821
|
-
* @param stats EventStats实例
|
|
2822
|
-
*/
|
|
2823
|
-
private convertEventStats;
|
|
2824
|
-
}
|
|
2931
|
+
type EventHandler<T = any> = (event: T) => void;
|
|
2825
2932
|
/**
|
|
2826
|
-
*
|
|
2827
|
-
* 提供全局访问的事件总线
|
|
2933
|
+
* 异步事件处理器函数类型
|
|
2828
2934
|
*/
|
|
2829
|
-
|
|
2830
|
-
private static instance;
|
|
2831
|
-
/**
|
|
2832
|
-
* 获取全局事件总线实例
|
|
2833
|
-
* @param debugMode 是否启用调试模式
|
|
2834
|
-
*/
|
|
2835
|
-
static getInstance(debugMode?: boolean): EventBus;
|
|
2836
|
-
/**
|
|
2837
|
-
* 重置全局事件总线实例
|
|
2838
|
-
* @param debugMode 是否启用调试模式
|
|
2839
|
-
*/
|
|
2840
|
-
static reset(debugMode?: boolean): EventBus;
|
|
2841
|
-
}
|
|
2935
|
+
type AsyncEventHandler<T = any> = (event: T) => Promise<void>;
|
|
2842
2936
|
/**
|
|
2843
|
-
*
|
|
2844
|
-
* 用于自动注册事件监听器
|
|
2937
|
+
* 事件监听器配置
|
|
2845
2938
|
*/
|
|
2846
|
-
|
|
2939
|
+
interface EventListenerConfig {
|
|
2940
|
+
/** 是否只执行一次 */
|
|
2941
|
+
once?: boolean;
|
|
2942
|
+
/** 优先级(数字越大优先级越高) */
|
|
2943
|
+
priority?: number;
|
|
2944
|
+
/** 是否异步执行 */
|
|
2945
|
+
async?: boolean;
|
|
2946
|
+
/** 执行上下文 */
|
|
2947
|
+
context?: any;
|
|
2948
|
+
}
|
|
2847
2949
|
/**
|
|
2848
|
-
*
|
|
2849
|
-
* 用于自动注册异步事件监听器
|
|
2950
|
+
* 事件统计信息
|
|
2850
2951
|
*/
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2952
|
+
interface EventStats {
|
|
2953
|
+
/** 事件类型 */
|
|
2954
|
+
eventType: string;
|
|
2955
|
+
/** 监听器数量 */
|
|
2956
|
+
listenerCount: number;
|
|
2957
|
+
/** 触发次数 */
|
|
2958
|
+
triggerCount: number;
|
|
2959
|
+
/** 总执行时间(毫秒) */
|
|
2960
|
+
totalExecutionTime: number;
|
|
2961
|
+
/** 平均执行时间(毫秒) */
|
|
2962
|
+
averageExecutionTime: number;
|
|
2963
|
+
/** 最后触发时间 */
|
|
2964
|
+
lastTriggerTime: number;
|
|
2862
2965
|
}
|
|
2863
2966
|
/**
|
|
2864
|
-
*
|
|
2865
|
-
*
|
|
2866
|
-
* 用于比较两个实体的优先级,首先按更新顺序比较,然后按ID比较。
|
|
2967
|
+
* 事件批处理配置
|
|
2867
2968
|
*/
|
|
2868
|
-
|
|
2869
|
-
/**
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
*/
|
|
2876
|
-
compare(self: Entity, other: Entity): number;
|
|
2969
|
+
interface EventBatchConfig {
|
|
2970
|
+
/** 批处理大小 */
|
|
2971
|
+
batchSize: number;
|
|
2972
|
+
/** 批处理延迟(毫秒) */
|
|
2973
|
+
delay: number;
|
|
2974
|
+
/** 是否启用批处理 */
|
|
2975
|
+
enabled: boolean;
|
|
2877
2976
|
}
|
|
2878
2977
|
/**
|
|
2879
|
-
*
|
|
2880
|
-
*
|
|
2881
|
-
* ECS架构中的实体(Entity),作为组件的容器。
|
|
2882
|
-
* 实体本身不包含游戏逻辑,所有功能都通过组件来实现。
|
|
2883
|
-
* 支持父子关系,可以构建实体层次结构。
|
|
2884
|
-
*
|
|
2885
|
-
* @example
|
|
2886
|
-
* ```typescript
|
|
2887
|
-
* // 创建实体
|
|
2888
|
-
* const entity = new Entity("Player", 1);
|
|
2889
|
-
*
|
|
2890
|
-
* // 添加组件
|
|
2891
|
-
* const healthComponent = entity.addComponent(new HealthComponent(100));
|
|
2892
|
-
*
|
|
2893
|
-
* // 获取组件
|
|
2894
|
-
* const health = entity.getComponent(HealthComponent);
|
|
2895
|
-
*
|
|
2896
|
-
* // 添加位置组件
|
|
2897
|
-
* entity.addComponent(new PositionComponent(100, 200));
|
|
2898
|
-
*
|
|
2899
|
-
* // 添加子实体
|
|
2900
|
-
* const weapon = new Entity("Weapon", 2);
|
|
2901
|
-
* entity.addChild(weapon);
|
|
2902
|
-
* ```
|
|
2978
|
+
* 类型安全的高性能事件系统
|
|
2979
|
+
* 支持同步/异步事件、优先级、批处理等功能
|
|
2903
2980
|
*/
|
|
2904
|
-
declare class
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
private
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
* 全局事件总线实例
|
|
2915
|
-
* 用于发射组件相关事件
|
|
2916
|
-
*/
|
|
2917
|
-
static eventBus: EventBus | null;
|
|
2981
|
+
declare class TypeSafeEventSystem {
|
|
2982
|
+
private static readonly _logger;
|
|
2983
|
+
private listeners;
|
|
2984
|
+
private stats;
|
|
2985
|
+
private batchQueue;
|
|
2986
|
+
private batchTimers;
|
|
2987
|
+
private batchConfigs;
|
|
2988
|
+
private nextListenerId;
|
|
2989
|
+
private isEnabled;
|
|
2990
|
+
private maxListeners;
|
|
2918
2991
|
/**
|
|
2919
|
-
*
|
|
2920
|
-
*
|
|
2921
|
-
*
|
|
2992
|
+
* 添加事件监听器
|
|
2993
|
+
* @param eventType 事件类型
|
|
2994
|
+
* @param handler 事件处理器
|
|
2995
|
+
* @param config 监听器配置
|
|
2996
|
+
* @returns 监听器ID(用于移除)
|
|
2922
2997
|
*/
|
|
2923
|
-
|
|
2998
|
+
on<T>(eventType: string, handler: EventHandler<T>, config?: EventListenerConfig): string;
|
|
2924
2999
|
/**
|
|
2925
|
-
*
|
|
2926
|
-
*
|
|
2927
|
-
*
|
|
3000
|
+
* 添加一次性事件监听器
|
|
3001
|
+
* @param eventType 事件类型
|
|
3002
|
+
* @param handler 事件处理器
|
|
3003
|
+
* @param config 监听器配置
|
|
3004
|
+
* @returns 监听器ID
|
|
2928
3005
|
*/
|
|
2929
|
-
|
|
3006
|
+
once<T>(eventType: string, handler: EventHandler<T>, config?: EventListenerConfig): string;
|
|
2930
3007
|
/**
|
|
2931
|
-
*
|
|
2932
|
-
*
|
|
2933
|
-
*
|
|
3008
|
+
* 添加异步事件监听器
|
|
3009
|
+
* @param eventType 事件类型
|
|
3010
|
+
* @param handler 异步事件处理器
|
|
3011
|
+
* @param config 监听器配置
|
|
3012
|
+
* @returns 监听器ID
|
|
2934
3013
|
*/
|
|
2935
|
-
|
|
3014
|
+
onAsync<T>(eventType: string, handler: AsyncEventHandler<T>, config?: EventListenerConfig): string;
|
|
2936
3015
|
/**
|
|
2937
|
-
*
|
|
2938
|
-
*
|
|
2939
|
-
*
|
|
3016
|
+
* 移除事件监听器
|
|
3017
|
+
* @param eventType 事件类型
|
|
3018
|
+
* @param listenerId 监听器ID
|
|
3019
|
+
* @returns 是否成功移除
|
|
2940
3020
|
*/
|
|
2941
|
-
|
|
3021
|
+
off(eventType: string, listenerId: string): boolean;
|
|
2942
3022
|
/**
|
|
2943
|
-
*
|
|
2944
|
-
*
|
|
2945
|
-
* 控制实体更新的频率,值越大更新越不频繁。
|
|
3023
|
+
* 移除指定事件类型的所有监听器
|
|
3024
|
+
* @param eventType 事件类型
|
|
2946
3025
|
*/
|
|
2947
|
-
|
|
3026
|
+
offAll(eventType: string): void;
|
|
2948
3027
|
/**
|
|
2949
|
-
*
|
|
2950
|
-
*
|
|
2951
|
-
*
|
|
3028
|
+
* 触发事件
|
|
3029
|
+
* @param eventType 事件类型
|
|
3030
|
+
* @param event 事件数据
|
|
3031
|
+
* @returns Promise(如果有异步监听器)
|
|
2952
3032
|
*/
|
|
2953
|
-
|
|
3033
|
+
emit<T>(eventType: string, event: T): Promise<void>;
|
|
2954
3034
|
/**
|
|
2955
|
-
*
|
|
2956
|
-
*
|
|
2957
|
-
*
|
|
3035
|
+
* 同步触发事件(忽略异步监听器)
|
|
3036
|
+
* @param eventType 事件类型
|
|
3037
|
+
* @param event 事件数据
|
|
2958
3038
|
*/
|
|
2959
|
-
|
|
3039
|
+
emitSync<T>(eventType: string, event: T): void;
|
|
2960
3040
|
/**
|
|
2961
|
-
*
|
|
2962
|
-
*
|
|
2963
|
-
*
|
|
3041
|
+
* 设置事件批处理配置
|
|
3042
|
+
* @param eventType 事件类型
|
|
3043
|
+
* @param config 批处理配置
|
|
2964
3044
|
*/
|
|
2965
|
-
|
|
3045
|
+
setBatchConfig(eventType: string, config: EventBatchConfig): void;
|
|
2966
3046
|
/**
|
|
2967
|
-
*
|
|
2968
|
-
*
|
|
2969
|
-
* 控制实体是否处于激活状态。
|
|
3047
|
+
* 立即处理指定事件类型的批处理队列
|
|
3048
|
+
* @param eventType 事件类型
|
|
2970
3049
|
*/
|
|
2971
|
-
|
|
3050
|
+
flushBatch(eventType: string): void;
|
|
2972
3051
|
/**
|
|
2973
|
-
*
|
|
2974
|
-
*
|
|
2975
|
-
*
|
|
3052
|
+
* 获取事件统计信息
|
|
3053
|
+
* @param eventType 事件类型(可选)
|
|
3054
|
+
* @returns 统计信息
|
|
2976
3055
|
*/
|
|
2977
|
-
|
|
3056
|
+
getStats(eventType?: string): EventStats | Map<string, EventStats>;
|
|
2978
3057
|
/**
|
|
2979
|
-
*
|
|
2980
|
-
*
|
|
2981
|
-
* 控制实体是否启用更新和处理。
|
|
3058
|
+
* 重置统计信息
|
|
3059
|
+
* @param eventType 事件类型(可选,不指定则重置所有)
|
|
2982
3060
|
*/
|
|
2983
|
-
|
|
3061
|
+
resetStats(eventType?: string): void;
|
|
2984
3062
|
/**
|
|
2985
|
-
*
|
|
2986
|
-
*
|
|
2987
|
-
* 控制实体在系统中的更新优先级。
|
|
3063
|
+
* 启用/禁用事件系统
|
|
3064
|
+
* @param enabled 是否启用
|
|
2988
3065
|
*/
|
|
2989
|
-
|
|
3066
|
+
setEnabled(enabled: boolean): void;
|
|
2990
3067
|
/**
|
|
2991
|
-
*
|
|
2992
|
-
*
|
|
2993
|
-
*
|
|
3068
|
+
* 检查是否有指定事件类型的监听器
|
|
3069
|
+
* @param eventType 事件类型
|
|
3070
|
+
* @returns 是否有监听器
|
|
2994
3071
|
*/
|
|
2995
|
-
|
|
3072
|
+
hasListeners(eventType: string): boolean;
|
|
2996
3073
|
/**
|
|
2997
|
-
*
|
|
2998
|
-
*
|
|
2999
|
-
*
|
|
3074
|
+
* 获取指定事件类型的监听器数量
|
|
3075
|
+
* @param eventType 事件类型
|
|
3076
|
+
* @returns 监听器数量
|
|
3000
3077
|
*/
|
|
3001
|
-
|
|
3078
|
+
getListenerCount(eventType: string): number;
|
|
3002
3079
|
/**
|
|
3003
|
-
*
|
|
3004
|
-
*
|
|
3005
|
-
* @param name - 实体名称
|
|
3006
|
-
* @param id - 实体唯一标识符
|
|
3080
|
+
* 清空所有事件监听器和数据
|
|
3007
3081
|
*/
|
|
3008
|
-
|
|
3082
|
+
clear(): void;
|
|
3009
3083
|
/**
|
|
3010
|
-
*
|
|
3011
|
-
*
|
|
3012
|
-
* @returns 如果实体已被销毁则返回true
|
|
3084
|
+
* 设置每个事件类型的最大监听器数量
|
|
3085
|
+
* @param max 最大数量
|
|
3013
3086
|
*/
|
|
3014
|
-
|
|
3087
|
+
setMaxListeners(max: number): void;
|
|
3015
3088
|
/**
|
|
3016
|
-
*
|
|
3017
|
-
*
|
|
3018
|
-
* @
|
|
3089
|
+
* 添加监听器的内部实现
|
|
3090
|
+
* @param eventType 事件类型
|
|
3091
|
+
* @param handler 事件处理器
|
|
3092
|
+
* @param config 配置
|
|
3093
|
+
* @returns 监听器ID
|
|
3019
3094
|
*/
|
|
3020
|
-
|
|
3095
|
+
private addListener;
|
|
3021
3096
|
/**
|
|
3022
|
-
*
|
|
3023
|
-
*
|
|
3024
|
-
* @
|
|
3097
|
+
* 执行事件的内部实现
|
|
3098
|
+
* @param eventType 事件类型
|
|
3099
|
+
* @param event 事件数据
|
|
3025
3100
|
*/
|
|
3026
|
-
|
|
3101
|
+
private executeEvent;
|
|
3027
3102
|
/**
|
|
3028
|
-
*
|
|
3029
|
-
*
|
|
3030
|
-
* @returns
|
|
3103
|
+
* 按优先级排序监听器
|
|
3104
|
+
* @param listeners 监听器数组
|
|
3105
|
+
* @returns 排序后的监听器数组
|
|
3031
3106
|
*/
|
|
3032
|
-
|
|
3107
|
+
private sortListenersByPriority;
|
|
3033
3108
|
/**
|
|
3034
|
-
*
|
|
3035
|
-
*
|
|
3036
|
-
* @
|
|
3109
|
+
* 移除指定的监听器
|
|
3110
|
+
* @param eventType 事件类型
|
|
3111
|
+
* @param listenerIds 要移除的监听器ID数组
|
|
3037
3112
|
*/
|
|
3038
|
-
|
|
3113
|
+
private removeListeners;
|
|
3039
3114
|
/**
|
|
3040
|
-
*
|
|
3041
|
-
*
|
|
3042
|
-
*
|
|
3043
|
-
*
|
|
3044
|
-
* @param value - 新的活跃状态
|
|
3115
|
+
* 添加事件到批处理队列
|
|
3116
|
+
* @param eventType 事件类型
|
|
3117
|
+
* @param event 事件数据
|
|
3045
3118
|
*/
|
|
3046
|
-
|
|
3119
|
+
private addToBatch;
|
|
3047
3120
|
/**
|
|
3048
|
-
*
|
|
3049
|
-
*
|
|
3050
|
-
*
|
|
3051
|
-
*
|
|
3052
|
-
* @returns 有效的活跃状态
|
|
3121
|
+
* 处理批处理事件
|
|
3122
|
+
* @param eventType 事件类型
|
|
3123
|
+
* @param batch 批处理事件数组
|
|
3053
3124
|
*/
|
|
3054
|
-
|
|
3125
|
+
private processBatch;
|
|
3055
3126
|
/**
|
|
3056
|
-
*
|
|
3057
|
-
*
|
|
3058
|
-
* @returns 实体的数字标签
|
|
3127
|
+
* 清除指定事件类型的批处理
|
|
3128
|
+
* @param eventType 事件类型
|
|
3059
3129
|
*/
|
|
3060
|
-
|
|
3130
|
+
private clearBatch;
|
|
3061
3131
|
/**
|
|
3062
|
-
*
|
|
3063
|
-
*
|
|
3064
|
-
* @param value - 新的标签值
|
|
3132
|
+
* 清除所有批处理
|
|
3065
3133
|
*/
|
|
3066
|
-
|
|
3134
|
+
private clearAllBatches;
|
|
3067
3135
|
/**
|
|
3068
|
-
*
|
|
3069
|
-
*
|
|
3070
|
-
* @
|
|
3136
|
+
* 更新事件统计信息
|
|
3137
|
+
* @param eventType 事件类型
|
|
3138
|
+
* @param executionTime 执行时间
|
|
3071
3139
|
*/
|
|
3072
|
-
|
|
3140
|
+
private updateStats;
|
|
3073
3141
|
/**
|
|
3074
|
-
*
|
|
3075
|
-
*
|
|
3076
|
-
* @
|
|
3142
|
+
* 创建空的统计信息
|
|
3143
|
+
* @param eventType 事件类型
|
|
3144
|
+
* @returns 空的统计信息
|
|
3077
3145
|
*/
|
|
3078
|
-
|
|
3146
|
+
private createEmptyStats;
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
/**
|
|
3150
|
+
* 游戏场景默认实现类
|
|
3151
|
+
*
|
|
3152
|
+
* 实现IScene接口,提供场景的基础功能。
|
|
3153
|
+
* 推荐使用组合而非继承的方式来构建自定义场景。
|
|
3154
|
+
*/
|
|
3155
|
+
declare class Scene implements IScene {
|
|
3079
3156
|
/**
|
|
3080
|
-
*
|
|
3157
|
+
* 场景名称
|
|
3081
3158
|
*
|
|
3082
|
-
*
|
|
3159
|
+
* 用于标识和调试的友好名称。
|
|
3083
3160
|
*/
|
|
3084
|
-
|
|
3161
|
+
name: string;
|
|
3085
3162
|
/**
|
|
3086
|
-
*
|
|
3163
|
+
* 场景中的实体集合
|
|
3087
3164
|
*
|
|
3088
|
-
*
|
|
3165
|
+
* 管理场景内所有实体的生命周期。
|
|
3089
3166
|
*/
|
|
3090
|
-
|
|
3167
|
+
readonly entities: EntityList;
|
|
3091
3168
|
/**
|
|
3092
|
-
*
|
|
3169
|
+
* 实体系统处理器集合
|
|
3093
3170
|
*
|
|
3094
|
-
*
|
|
3171
|
+
* 管理场景内所有实体系统的执行。
|
|
3095
3172
|
*/
|
|
3096
|
-
|
|
3173
|
+
readonly entityProcessors: EntityProcessorList;
|
|
3097
3174
|
/**
|
|
3098
|
-
*
|
|
3175
|
+
* 实体ID池
|
|
3099
3176
|
*
|
|
3100
|
-
*
|
|
3101
|
-
* @param args - 组件构造函数参数
|
|
3102
|
-
* @returns 创建的组件实例
|
|
3177
|
+
* 用于分配和回收实体的唯一标识符。
|
|
3103
3178
|
*/
|
|
3104
|
-
|
|
3179
|
+
readonly identifierPool: IdentifierPool;
|
|
3105
3180
|
/**
|
|
3106
|
-
*
|
|
3181
|
+
* 组件存储管理器
|
|
3107
3182
|
*
|
|
3108
|
-
*
|
|
3109
|
-
* @returns 添加的组件实例
|
|
3183
|
+
* 高性能的组件存储和查询系统。
|
|
3110
3184
|
*/
|
|
3111
|
-
|
|
3185
|
+
readonly componentStorageManager: ComponentStorageManager;
|
|
3112
3186
|
/**
|
|
3113
|
-
*
|
|
3187
|
+
* 查询系统
|
|
3114
3188
|
*
|
|
3115
|
-
*
|
|
3116
|
-
* @returns 添加的组件实例
|
|
3117
|
-
* @throws {Error} 如果组件类型已存在
|
|
3189
|
+
* 基于位掩码的高性能实体查询系统。
|
|
3118
3190
|
*/
|
|
3119
|
-
|
|
3191
|
+
readonly querySystem: QuerySystem;
|
|
3120
3192
|
/**
|
|
3121
|
-
*
|
|
3193
|
+
* 事件系统
|
|
3122
3194
|
*
|
|
3123
|
-
*
|
|
3124
|
-
* @returns 组件实例或null
|
|
3195
|
+
* 类型安全的事件系统。
|
|
3125
3196
|
*/
|
|
3126
|
-
|
|
3197
|
+
readonly eventSystem: TypeSafeEventSystem;
|
|
3127
3198
|
/**
|
|
3128
|
-
*
|
|
3199
|
+
* 场景是否已开始运行
|
|
3129
3200
|
*/
|
|
3130
|
-
private
|
|
3201
|
+
private _didSceneBegin;
|
|
3131
3202
|
/**
|
|
3132
|
-
*
|
|
3133
|
-
*
|
|
3134
|
-
* @param type - 组件类型
|
|
3135
|
-
* @returns 如果有该组件则返回true
|
|
3203
|
+
* 获取系统列表(兼容性属性)
|
|
3136
3204
|
*/
|
|
3137
|
-
|
|
3205
|
+
get systems(): EntitySystem[];
|
|
3138
3206
|
/**
|
|
3139
|
-
*
|
|
3140
|
-
*
|
|
3141
|
-
* @param type - 组件类型
|
|
3142
|
-
* @param args - 组件构造函数参数(仅在创建时使用)
|
|
3143
|
-
* @returns 组件实例
|
|
3207
|
+
* 创建场景实例
|
|
3144
3208
|
*/
|
|
3145
|
-
|
|
3209
|
+
constructor(config?: ISceneConfig);
|
|
3146
3210
|
/**
|
|
3147
|
-
*
|
|
3211
|
+
* 初始化场景
|
|
3148
3212
|
*
|
|
3149
|
-
*
|
|
3213
|
+
* 在场景创建时调用,子类可以重写此方法来设置初始实体和组件。
|
|
3150
3214
|
*/
|
|
3151
|
-
|
|
3215
|
+
initialize(): void;
|
|
3152
3216
|
/**
|
|
3153
|
-
*
|
|
3217
|
+
* 场景开始运行时的回调
|
|
3154
3218
|
*
|
|
3155
|
-
*
|
|
3156
|
-
* @returns 被移除的组件实例或null
|
|
3157
|
-
*/
|
|
3158
|
-
removeComponentByType<T extends Component>(type: ComponentType<T>): T | null;
|
|
3159
|
-
/**
|
|
3160
|
-
* 移除所有组件
|
|
3219
|
+
* 在场景开始运行时调用,可以在此方法中执行场景启动逻辑。
|
|
3161
3220
|
*/
|
|
3162
|
-
|
|
3221
|
+
onStart(): void;
|
|
3163
3222
|
/**
|
|
3164
|
-
*
|
|
3223
|
+
* 场景卸载时的回调
|
|
3165
3224
|
*
|
|
3166
|
-
*
|
|
3167
|
-
* @returns 添加的组件数组
|
|
3225
|
+
* 在场景被销毁时调用,可以在此方法中执行清理工作。
|
|
3168
3226
|
*/
|
|
3169
|
-
|
|
3227
|
+
unload(): void;
|
|
3170
3228
|
/**
|
|
3171
|
-
*
|
|
3229
|
+
* 开始场景,启动实体处理器等
|
|
3172
3230
|
*
|
|
3173
|
-
*
|
|
3174
|
-
* @returns 被移除的组件数组
|
|
3231
|
+
* 这个方法会启动场景。它将启动实体处理器等,并调用onStart方法。
|
|
3175
3232
|
*/
|
|
3176
|
-
|
|
3233
|
+
begin(): void;
|
|
3177
3234
|
/**
|
|
3178
|
-
*
|
|
3235
|
+
* 结束场景,清除实体、实体处理器等
|
|
3179
3236
|
*
|
|
3180
|
-
*
|
|
3181
|
-
* @returns 组件实例数组
|
|
3237
|
+
* 这个方法会结束场景。它将移除所有实体,结束实体处理器等,并调用unload方法。
|
|
3182
3238
|
*/
|
|
3183
|
-
|
|
3239
|
+
end(): void;
|
|
3184
3240
|
/**
|
|
3185
|
-
*
|
|
3186
|
-
*
|
|
3187
|
-
* @param child - 要添加的子实体
|
|
3188
|
-
* @returns 添加的子实体
|
|
3241
|
+
* 更新场景,更新实体组件、实体处理器等
|
|
3189
3242
|
*/
|
|
3190
|
-
|
|
3243
|
+
update(): void;
|
|
3191
3244
|
/**
|
|
3192
|
-
*
|
|
3193
|
-
*
|
|
3194
|
-
* @param child - 要移除的子实体
|
|
3195
|
-
* @returns 是否成功移除
|
|
3245
|
+
* 将实体添加到此场景,并返回它
|
|
3246
|
+
* @param name 实体名称
|
|
3196
3247
|
*/
|
|
3197
|
-
|
|
3248
|
+
createEntity(name: string): Entity;
|
|
3198
3249
|
/**
|
|
3199
|
-
*
|
|
3250
|
+
* 在场景的实体列表中添加一个实体
|
|
3251
|
+
* @param entity 要添加的实体
|
|
3252
|
+
* @param deferCacheClear 是否延迟缓存清理(用于批量操作)
|
|
3200
3253
|
*/
|
|
3201
|
-
|
|
3254
|
+
addEntity(entity: Entity, deferCacheClear?: boolean): Entity;
|
|
3202
3255
|
/**
|
|
3203
|
-
*
|
|
3204
|
-
*
|
|
3205
|
-
* @param
|
|
3206
|
-
* @
|
|
3207
|
-
* @returns 找到的子实体或null
|
|
3256
|
+
* 批量创建实体(高性能版本)
|
|
3257
|
+
* @param count 要创建的实体数量
|
|
3258
|
+
* @param namePrefix 实体名称前缀
|
|
3259
|
+
* @returns 创建的实体列表
|
|
3208
3260
|
*/
|
|
3209
|
-
|
|
3261
|
+
createEntities(count: number, namePrefix?: string): Entity[];
|
|
3210
3262
|
/**
|
|
3211
|
-
*
|
|
3212
|
-
*
|
|
3213
|
-
* @param tag - 标签
|
|
3214
|
-
* @param recursive - 是否递归查找
|
|
3215
|
-
* @returns 找到的子实体数组
|
|
3263
|
+
* 从场景中删除所有实体
|
|
3216
3264
|
*/
|
|
3217
|
-
|
|
3265
|
+
destroyAllEntities(): void;
|
|
3218
3266
|
/**
|
|
3219
|
-
*
|
|
3220
|
-
*
|
|
3221
|
-
* @returns 层次结构的根实体
|
|
3267
|
+
* 搜索并返回第一个具有名称的实体
|
|
3268
|
+
* @param name 实体名称
|
|
3222
3269
|
*/
|
|
3223
|
-
|
|
3270
|
+
findEntity(name: string): Entity | null;
|
|
3224
3271
|
/**
|
|
3225
|
-
*
|
|
3226
|
-
*
|
|
3227
|
-
* @param entity - 要检查的实体
|
|
3228
|
-
* @returns 如果是祖先则返回true
|
|
3272
|
+
* 根据ID查找实体
|
|
3273
|
+
* @param id 实体ID
|
|
3229
3274
|
*/
|
|
3230
|
-
|
|
3275
|
+
findEntityById(id: number): Entity | null;
|
|
3231
3276
|
/**
|
|
3232
|
-
*
|
|
3233
|
-
*
|
|
3234
|
-
* @param entity - 要检查的实体
|
|
3235
|
-
* @returns 如果是后代则返回true
|
|
3277
|
+
* 根据标签查找实体
|
|
3278
|
+
* @param tag 实体标签
|
|
3236
3279
|
*/
|
|
3237
|
-
|
|
3280
|
+
findEntitiesByTag(tag: number): Entity[];
|
|
3238
3281
|
/**
|
|
3239
|
-
*
|
|
3240
|
-
*
|
|
3241
|
-
* @returns 在层次结构中的深度(根实体为0)
|
|
3282
|
+
* 根据名称查找实体(别名方法)
|
|
3283
|
+
* @param name 实体名称
|
|
3242
3284
|
*/
|
|
3243
|
-
|
|
3285
|
+
getEntityByName(name: string): Entity | null;
|
|
3244
3286
|
/**
|
|
3245
|
-
*
|
|
3246
|
-
*
|
|
3247
|
-
* @param callback - 对每个子实体执行的回调函数
|
|
3248
|
-
* @param recursive - 是否递归遍历
|
|
3287
|
+
* 根据标签查找实体(别名方法)
|
|
3288
|
+
* @param tag 实体标签
|
|
3249
3289
|
*/
|
|
3250
|
-
|
|
3290
|
+
getEntitiesByTag(tag: number): Entity[];
|
|
3251
3291
|
/**
|
|
3252
|
-
*
|
|
3292
|
+
* 在场景中添加一个EntitySystem处理器
|
|
3293
|
+
* @param processor 处理器
|
|
3253
3294
|
*/
|
|
3254
|
-
|
|
3295
|
+
addEntityProcessor(processor: EntitySystem): EntitySystem;
|
|
3255
3296
|
/**
|
|
3256
|
-
*
|
|
3257
|
-
*
|
|
3258
|
-
* 调用所有组件的更新方法,并更新子实体。
|
|
3297
|
+
* 添加系统到场景(addEntityProcessor的别名)
|
|
3298
|
+
* @param system 系统
|
|
3259
3299
|
*/
|
|
3260
|
-
|
|
3300
|
+
addSystem(system: EntitySystem): EntitySystem;
|
|
3261
3301
|
/**
|
|
3262
|
-
*
|
|
3263
|
-
*
|
|
3264
|
-
* 移除所有组件、子实体并标记为已销毁。
|
|
3302
|
+
* 从场景中删除EntitySystem处理器
|
|
3303
|
+
* @param processor 要删除的处理器
|
|
3265
3304
|
*/
|
|
3266
|
-
|
|
3305
|
+
removeEntityProcessor(processor: EntitySystem): void;
|
|
3267
3306
|
/**
|
|
3268
|
-
*
|
|
3269
|
-
*
|
|
3270
|
-
* @param other - 另一个实体
|
|
3271
|
-
* @returns 比较结果
|
|
3307
|
+
* 获取指定类型的EntitySystem处理器
|
|
3308
|
+
* @param type 处理器类型
|
|
3272
3309
|
*/
|
|
3273
|
-
|
|
3310
|
+
getEntityProcessor<T extends EntitySystem>(type: new (...args: unknown[]) => T): T | null;
|
|
3274
3311
|
/**
|
|
3275
|
-
*
|
|
3276
|
-
*
|
|
3277
|
-
* @returns 实体的字符串描述
|
|
3312
|
+
* 获取场景统计信息
|
|
3278
3313
|
*/
|
|
3279
|
-
|
|
3314
|
+
getStats(): {
|
|
3315
|
+
entityCount: number;
|
|
3316
|
+
processorCount: number;
|
|
3317
|
+
componentStorageStats: Map<string, any>;
|
|
3318
|
+
};
|
|
3280
3319
|
/**
|
|
3281
|
-
*
|
|
3282
|
-
*
|
|
3283
|
-
* @returns 包含实体详细信息的对象
|
|
3320
|
+
* 获取场景的调试信息
|
|
3284
3321
|
*/
|
|
3285
3322
|
getDebugInfo(): {
|
|
3286
3323
|
name: string;
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3324
|
+
entityCount: number;
|
|
3325
|
+
processorCount: number;
|
|
3326
|
+
isRunning: boolean;
|
|
3327
|
+
entities: Array<{
|
|
3328
|
+
name: string;
|
|
3329
|
+
id: number;
|
|
3330
|
+
componentCount: number;
|
|
3331
|
+
componentTypes: string[];
|
|
3332
|
+
}>;
|
|
3333
|
+
processors: Array<{
|
|
3334
|
+
name: string;
|
|
3335
|
+
updateOrder: number;
|
|
3336
|
+
entityCount: number;
|
|
3337
|
+
}>;
|
|
3338
|
+
componentStats: Map<string, any>;
|
|
3300
3339
|
};
|
|
3301
3340
|
}
|
|
3302
3341
|
|
|
3303
3342
|
/**
|
|
3304
|
-
*
|
|
3305
|
-
*/
|
|
3306
|
-
interface QueryCondition {
|
|
3307
|
-
all: ComponentType[];
|
|
3308
|
-
any: ComponentType[];
|
|
3309
|
-
none: ComponentType[];
|
|
3310
|
-
tag?: number;
|
|
3311
|
-
name?: string;
|
|
3312
|
-
component?: ComponentType;
|
|
3313
|
-
}
|
|
3314
|
-
/**
|
|
3315
|
-
* 实体匹配条件描述符
|
|
3343
|
+
* 实体系统的基类
|
|
3316
3344
|
*
|
|
3317
|
-
*
|
|
3345
|
+
* 用于处理一组符合特定条件的实体。系统是ECS架构中的逻辑处理单元,
|
|
3346
|
+
* 负责对拥有特定组件组合的实体执行业务逻辑。
|
|
3318
3347
|
*
|
|
3319
3348
|
* @example
|
|
3320
3349
|
* ```typescript
|
|
3321
|
-
*
|
|
3322
|
-
*
|
|
3323
|
-
*
|
|
3350
|
+
* class MovementSystem extends EntitySystem {
|
|
3351
|
+
* constructor() {
|
|
3352
|
+
* super(Transform, Velocity);
|
|
3353
|
+
* }
|
|
3324
3354
|
*
|
|
3325
|
-
*
|
|
3326
|
-
* const
|
|
3355
|
+
* protected process(entities: Entity[]): void {
|
|
3356
|
+
* for (const entity of entities) {
|
|
3357
|
+
* const transform = entity.getComponent(Transform);
|
|
3358
|
+
* const velocity = entity.getComponent(Velocity);
|
|
3359
|
+
* transform.position.add(velocity.value);
|
|
3360
|
+
* }
|
|
3361
|
+
* }
|
|
3362
|
+
* }
|
|
3327
3363
|
* ```
|
|
3328
3364
|
*/
|
|
3329
|
-
declare class
|
|
3330
|
-
private
|
|
3331
|
-
private
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
/**
|
|
3338
|
-
* 创建匹配器,要求至少一个指定的组件
|
|
3339
|
-
* @param types 组件类型
|
|
3340
|
-
*/
|
|
3341
|
-
static any(...types: ComponentType[]): Matcher;
|
|
3342
|
-
/**
|
|
3343
|
-
* 创建匹配器,排除指定的组件
|
|
3344
|
-
* @param types 组件类型
|
|
3345
|
-
*/
|
|
3346
|
-
static none(...types: ComponentType[]): Matcher;
|
|
3347
|
-
/**
|
|
3348
|
-
* 创建按标签查询的匙配器
|
|
3349
|
-
* @param tag 标签值
|
|
3350
|
-
*/
|
|
3351
|
-
static byTag(tag: number): Matcher;
|
|
3365
|
+
declare abstract class EntitySystem implements ISystemBase {
|
|
3366
|
+
private _updateOrder;
|
|
3367
|
+
private _enabled;
|
|
3368
|
+
private _performanceMonitor;
|
|
3369
|
+
private _systemName;
|
|
3370
|
+
private _initialized;
|
|
3371
|
+
private _matcher;
|
|
3372
|
+
private _trackedEntities;
|
|
3352
3373
|
/**
|
|
3353
|
-
*
|
|
3354
|
-
* @param name 实体名称
|
|
3374
|
+
* 获取系统处理的实体列表(动态查询)
|
|
3355
3375
|
*/
|
|
3356
|
-
|
|
3376
|
+
get entities(): readonly Entity[];
|
|
3357
3377
|
/**
|
|
3358
|
-
*
|
|
3359
|
-
* @param componentType 组件类型
|
|
3378
|
+
* 获取系统的更新时序
|
|
3360
3379
|
*/
|
|
3361
|
-
|
|
3380
|
+
get updateOrder(): number;
|
|
3381
|
+
set updateOrder(value: number);
|
|
3362
3382
|
/**
|
|
3363
|
-
*
|
|
3383
|
+
* 获取系统的启用状态
|
|
3364
3384
|
*/
|
|
3365
|
-
|
|
3385
|
+
get enabled(): boolean;
|
|
3366
3386
|
/**
|
|
3367
|
-
*
|
|
3387
|
+
* 设置系统的启用状态
|
|
3368
3388
|
*/
|
|
3369
|
-
|
|
3389
|
+
set enabled(value: boolean);
|
|
3370
3390
|
/**
|
|
3371
|
-
*
|
|
3372
|
-
* @param types 组件类型
|
|
3391
|
+
* 获取系统名称
|
|
3373
3392
|
*/
|
|
3374
|
-
|
|
3393
|
+
get systemName(): string;
|
|
3394
|
+
constructor(matcher?: Matcher);
|
|
3395
|
+
private _scene;
|
|
3375
3396
|
/**
|
|
3376
|
-
*
|
|
3377
|
-
* @param types 组件类型
|
|
3397
|
+
* 这个系统所属的场景
|
|
3378
3398
|
*/
|
|
3379
|
-
|
|
3399
|
+
get scene(): Scene | null;
|
|
3400
|
+
set scene(value: Scene | null);
|
|
3380
3401
|
/**
|
|
3381
|
-
*
|
|
3382
|
-
* @param types 组件类型
|
|
3402
|
+
* 获取实体匹配器
|
|
3383
3403
|
*/
|
|
3384
|
-
|
|
3404
|
+
get matcher(): Matcher;
|
|
3385
3405
|
/**
|
|
3386
|
-
*
|
|
3387
|
-
* @param
|
|
3406
|
+
* 设置更新时序
|
|
3407
|
+
* @param order 更新时序
|
|
3388
3408
|
*/
|
|
3389
|
-
|
|
3409
|
+
setUpdateOrder(order: number): void;
|
|
3390
3410
|
/**
|
|
3391
|
-
*
|
|
3392
|
-
*
|
|
3411
|
+
* 系统初始化(框架调用)
|
|
3412
|
+
*
|
|
3413
|
+
* 在系统创建时调用。框架内部使用,用户不应直接调用。
|
|
3393
3414
|
*/
|
|
3394
|
-
|
|
3415
|
+
initialize(): void;
|
|
3395
3416
|
/**
|
|
3396
|
-
*
|
|
3397
|
-
*
|
|
3417
|
+
* 系统初始化回调
|
|
3418
|
+
*
|
|
3419
|
+
* 子类可以重写此方法进行初始化操作。
|
|
3398
3420
|
*/
|
|
3399
|
-
|
|
3421
|
+
protected onInitialize(): void;
|
|
3400
3422
|
/**
|
|
3401
|
-
*
|
|
3402
|
-
*
|
|
3423
|
+
* 重置系统状态
|
|
3424
|
+
*
|
|
3425
|
+
* 当系统从场景中移除时调用,重置初始化状态以便重新添加时能正确初始化。
|
|
3403
3426
|
*/
|
|
3404
|
-
|
|
3427
|
+
reset(): void;
|
|
3405
3428
|
/**
|
|
3406
|
-
*
|
|
3407
|
-
* @param componentType 组件类型
|
|
3429
|
+
* 查询匹配的实体
|
|
3408
3430
|
*/
|
|
3409
|
-
|
|
3431
|
+
private queryEntities;
|
|
3410
3432
|
/**
|
|
3411
|
-
*
|
|
3433
|
+
* 检查是否为单一条件查询
|
|
3412
3434
|
*/
|
|
3413
|
-
|
|
3435
|
+
private isSingleCondition;
|
|
3414
3436
|
/**
|
|
3415
|
-
*
|
|
3437
|
+
* 执行单一条件查询
|
|
3416
3438
|
*/
|
|
3417
|
-
|
|
3439
|
+
private executeSingleConditionQuery;
|
|
3418
3440
|
/**
|
|
3419
|
-
*
|
|
3441
|
+
* 执行复合查询
|
|
3420
3442
|
*/
|
|
3421
|
-
|
|
3443
|
+
private executeComplexQueryWithIdSets;
|
|
3422
3444
|
/**
|
|
3423
|
-
*
|
|
3445
|
+
* 提取实体ID集合
|
|
3424
3446
|
*/
|
|
3425
|
-
|
|
3447
|
+
private extractEntityIds;
|
|
3426
3448
|
/**
|
|
3427
|
-
*
|
|
3449
|
+
* ID集合交集运算
|
|
3450
|
+
*
|
|
3451
|
+
* 使用单次扫描算法,选择较小集合进行迭代以提高效率
|
|
3428
3452
|
*/
|
|
3429
|
-
|
|
3453
|
+
private intersectIdSets;
|
|
3430
3454
|
/**
|
|
3431
|
-
*
|
|
3455
|
+
* ID集合差集运算
|
|
3456
|
+
*
|
|
3457
|
+
* 使用单次扫描算法计算setA - setB
|
|
3432
3458
|
*/
|
|
3433
|
-
|
|
3459
|
+
private differenceIdSets;
|
|
3434
3460
|
/**
|
|
3435
|
-
*
|
|
3461
|
+
* 从ID集合构建Entity数组
|
|
3462
|
+
*
|
|
3463
|
+
* 先构建ID到Entity的映射,然后根据ID集合构建结果数组
|
|
3436
3464
|
*/
|
|
3437
|
-
|
|
3465
|
+
private idSetToEntityArray;
|
|
3438
3466
|
/**
|
|
3439
|
-
*
|
|
3467
|
+
* 执行复合查询
|
|
3468
|
+
*
|
|
3469
|
+
* 使用基于ID集合的单次扫描算法进行复杂查询
|
|
3440
3470
|
*/
|
|
3441
|
-
|
|
3442
|
-
}
|
|
3443
|
-
|
|
3444
|
-
/**
|
|
3445
|
-
* 世代式ID池管理器
|
|
3446
|
-
*
|
|
3447
|
-
* 用于管理实体ID的分配和回收,支持世代版本控制以防止悬空引用问题。
|
|
3448
|
-
* 世代式ID由索引和版本组成,当ID被回收时版本会递增,确保旧引用失效。
|
|
3449
|
-
*
|
|
3450
|
-
* 支持动态扩展,理论上可以支持到65535个索引(16位),每个索引65535个版本(16位)。
|
|
3451
|
-
* 总计可以处理超过42亿个独特的ID组合,完全满足ECS大规模实体需求。
|
|
3452
|
-
*
|
|
3453
|
-
* @example
|
|
3454
|
-
* ```typescript
|
|
3455
|
-
* const pool = new IdentifierPool();
|
|
3456
|
-
*
|
|
3457
|
-
* // 分配ID
|
|
3458
|
-
* const id = pool.checkOut(); // 例如: 65536 (版本1,索引0)
|
|
3459
|
-
*
|
|
3460
|
-
* // 回收ID
|
|
3461
|
-
* pool.checkIn(id);
|
|
3462
|
-
*
|
|
3463
|
-
* // 验证ID是否有效
|
|
3464
|
-
* const isValid = pool.isValid(id); // false,因为版本已递增
|
|
3465
|
-
* ```
|
|
3466
|
-
*/
|
|
3467
|
-
declare class IdentifierPool {
|
|
3471
|
+
private executeComplexQuery;
|
|
3468
3472
|
/**
|
|
3469
|
-
*
|
|
3473
|
+
* 更新系统
|
|
3474
|
+
*
|
|
3475
|
+
* 在每帧调用,处理系统的主要逻辑。
|
|
3470
3476
|
*/
|
|
3471
|
-
|
|
3477
|
+
update(): void;
|
|
3472
3478
|
/**
|
|
3473
|
-
*
|
|
3479
|
+
* 后期更新系统
|
|
3480
|
+
*
|
|
3481
|
+
* 在所有系统的update方法执行完毕后调用。
|
|
3474
3482
|
*/
|
|
3475
|
-
|
|
3483
|
+
lateUpdate(): void;
|
|
3476
3484
|
/**
|
|
3477
|
-
*
|
|
3478
|
-
*
|
|
3485
|
+
* 在系统处理开始前调用
|
|
3486
|
+
*
|
|
3487
|
+
* 子类可以重写此方法进行预处理操作。
|
|
3479
3488
|
*/
|
|
3480
|
-
|
|
3489
|
+
protected onBegin(): void;
|
|
3481
3490
|
/**
|
|
3482
|
-
*
|
|
3483
|
-
*
|
|
3491
|
+
* 处理实体列表
|
|
3492
|
+
*
|
|
3493
|
+
* 系统的核心逻辑,子类必须实现此方法来定义具体的处理逻辑。
|
|
3494
|
+
*
|
|
3495
|
+
* @param entities 要处理的实体列表
|
|
3484
3496
|
*/
|
|
3485
|
-
|
|
3497
|
+
protected process(_entities: Entity[]): void;
|
|
3486
3498
|
/**
|
|
3487
|
-
*
|
|
3499
|
+
* 后期处理实体列表
|
|
3500
|
+
*
|
|
3501
|
+
* 在主要处理逻辑之后执行,子类可以重写此方法。
|
|
3502
|
+
*
|
|
3503
|
+
* @param entities 要处理的实体列表
|
|
3488
3504
|
*/
|
|
3489
|
-
|
|
3505
|
+
protected lateProcess(_entities: Entity[]): void;
|
|
3490
3506
|
/**
|
|
3491
|
-
*
|
|
3492
|
-
*
|
|
3493
|
-
*
|
|
3507
|
+
* 系统处理完毕后调用
|
|
3508
|
+
*
|
|
3509
|
+
* 子类可以重写此方法进行后处理操作。
|
|
3494
3510
|
*/
|
|
3495
|
-
|
|
3511
|
+
protected onEnd(): void;
|
|
3496
3512
|
/**
|
|
3497
|
-
*
|
|
3513
|
+
* 检查系统是否需要处理
|
|
3514
|
+
*
|
|
3515
|
+
* 在启用系统时有用,但仅偶尔需要处理。
|
|
3516
|
+
* 这只影响处理,不影响事件或订阅列表。
|
|
3517
|
+
*
|
|
3518
|
+
* @returns 如果系统应该处理,则为true,如果不处理则为false
|
|
3498
3519
|
*/
|
|
3499
|
-
|
|
3520
|
+
protected onCheckProcessing(): boolean;
|
|
3500
3521
|
/**
|
|
3501
|
-
*
|
|
3502
|
-
*
|
|
3522
|
+
* 获取系统的性能数据
|
|
3523
|
+
*
|
|
3524
|
+
* @returns 性能数据或undefined
|
|
3503
3525
|
*/
|
|
3504
|
-
|
|
3526
|
+
getPerformanceData(): PerformanceData | undefined;
|
|
3505
3527
|
/**
|
|
3506
|
-
*
|
|
3528
|
+
* 获取系统的性能统计
|
|
3529
|
+
*
|
|
3530
|
+
* @returns 性能统计或undefined
|
|
3507
3531
|
*/
|
|
3508
|
-
|
|
3532
|
+
getPerformanceStats(): PerformanceStats | undefined;
|
|
3509
3533
|
/**
|
|
3510
|
-
*
|
|
3511
|
-
*
|
|
3512
|
-
* @param recycleDelay 延迟回收时间(毫秒),默认为100ms
|
|
3513
|
-
* @param expansionBlockSize 内存扩展块大小,默认为1024
|
|
3534
|
+
* 重置系统的性能数据
|
|
3514
3535
|
*/
|
|
3515
|
-
|
|
3536
|
+
resetPerformanceData(): void;
|
|
3516
3537
|
/**
|
|
3517
|
-
*
|
|
3518
|
-
*
|
|
3519
|
-
* 返回一个32位ID,高16位为世代版本,低16位为索引。
|
|
3538
|
+
* 获取系统信息的字符串表示
|
|
3520
3539
|
*
|
|
3521
|
-
* @returns
|
|
3522
|
-
* @throws {Error} 当达到索引限制时抛出错误
|
|
3540
|
+
* @returns 系统信息字符串
|
|
3523
3541
|
*/
|
|
3524
|
-
|
|
3542
|
+
toString(): string;
|
|
3525
3543
|
/**
|
|
3526
|
-
*
|
|
3527
|
-
*
|
|
3528
|
-
* 验证ID的有效性后,将其加入延迟回收队列。
|
|
3529
|
-
* ID不会立即可重用,而是在延迟时间后才真正回收。
|
|
3530
|
-
*
|
|
3531
|
-
* @param id 要回收的实体ID
|
|
3532
|
-
* @returns 是否成功回收(ID是否有效且未被重复回收)
|
|
3544
|
+
* 更新实体跟踪,检查新增和移除的实体
|
|
3533
3545
|
*/
|
|
3534
|
-
|
|
3546
|
+
private updateEntityTracking;
|
|
3535
3547
|
/**
|
|
3536
|
-
*
|
|
3548
|
+
* 当实体被添加到系统时调用
|
|
3537
3549
|
*
|
|
3538
|
-
*
|
|
3550
|
+
* 子类可以重写此方法来处理实体添加事件。
|
|
3539
3551
|
*
|
|
3540
|
-
* @param
|
|
3541
|
-
* @returns ID是否有效
|
|
3552
|
+
* @param entity 被添加的实体
|
|
3542
3553
|
*/
|
|
3543
|
-
|
|
3554
|
+
protected onAdded(_entity: Entity): void;
|
|
3544
3555
|
/**
|
|
3545
|
-
*
|
|
3556
|
+
* 当实体从系统中移除时调用
|
|
3546
3557
|
*
|
|
3547
|
-
*
|
|
3558
|
+
* 子类可以重写此方法来处理实体移除事件。
|
|
3559
|
+
*
|
|
3560
|
+
* @param entity 被移除的实体
|
|
3548
3561
|
*/
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
/** 理论最大实体数(设计限制) */
|
|
3561
|
-
maxPossibleEntities: number;
|
|
3562
|
-
/** 当前使用的最大索引 */
|
|
3563
|
-
maxUsedIndex: number;
|
|
3564
|
-
/** 内存使用(字节) */
|
|
3565
|
-
memoryUsage: number;
|
|
3566
|
-
/** 内存扩展次数 */
|
|
3567
|
-
memoryExpansions: number;
|
|
3568
|
-
/** 平均世代版本 */
|
|
3569
|
-
averageGeneration: number;
|
|
3570
|
-
/** 世代存储大小 */
|
|
3571
|
-
generationStorageSize: number;
|
|
3572
|
-
};
|
|
3562
|
+
protected onRemoved(_entity: Entity): void;
|
|
3563
|
+
}
|
|
3564
|
+
|
|
3565
|
+
/**
|
|
3566
|
+
* 实体处理器列表管理器
|
|
3567
|
+
* 管理场景中的所有实体系统
|
|
3568
|
+
*/
|
|
3569
|
+
declare class EntityProcessorList {
|
|
3570
|
+
private static readonly _logger;
|
|
3571
|
+
private _processors;
|
|
3572
|
+
private _isDirty;
|
|
3573
3573
|
/**
|
|
3574
|
-
*
|
|
3575
|
-
*
|
|
3576
|
-
* 在某些情况下可能需要立即处理延迟回收队列,
|
|
3577
|
-
* 比如内存压力大或者需要精确的统计信息时。
|
|
3574
|
+
* 设置为脏状态,需要重新排序
|
|
3578
3575
|
*/
|
|
3579
|
-
|
|
3576
|
+
setDirty(): void;
|
|
3580
3577
|
/**
|
|
3581
|
-
*
|
|
3582
|
-
*
|
|
3583
|
-
* 将超过延迟时间的回收项真正回收到空闲列表中。
|
|
3584
|
-
*
|
|
3585
|
-
* @param forceAll 是否强制处理所有延迟回收项
|
|
3586
|
-
* @private
|
|
3578
|
+
* 添加实体处理器
|
|
3579
|
+
* @param processor 要添加的处理器
|
|
3587
3580
|
*/
|
|
3588
|
-
|
|
3581
|
+
add(processor: EntitySystem): void;
|
|
3589
3582
|
/**
|
|
3590
|
-
*
|
|
3591
|
-
*
|
|
3592
|
-
* @param startIndex 起始索引
|
|
3593
|
-
* @param count 分配数量
|
|
3594
|
-
* @private
|
|
3583
|
+
* 移除实体处理器
|
|
3584
|
+
* @param processor 要移除的处理器
|
|
3595
3585
|
*/
|
|
3596
|
-
|
|
3586
|
+
remove(processor: EntitySystem): void;
|
|
3597
3587
|
/**
|
|
3598
|
-
*
|
|
3599
|
-
*
|
|
3600
|
-
* @param index 索引
|
|
3601
|
-
* @private
|
|
3588
|
+
* 获取指定类型的处理器
|
|
3589
|
+
* @param type 处理器类型
|
|
3602
3590
|
*/
|
|
3603
|
-
|
|
3591
|
+
getProcessor<T extends EntitySystem>(type: new (...args: unknown[]) => T): T | null;
|
|
3604
3592
|
/**
|
|
3605
|
-
*
|
|
3593
|
+
* 开始处理
|
|
3606
3594
|
*
|
|
3607
|
-
*
|
|
3608
|
-
* @private
|
|
3595
|
+
* 对所有处理器进行排序以确保正确的执行顺序。
|
|
3609
3596
|
*/
|
|
3610
|
-
|
|
3597
|
+
begin(): void;
|
|
3611
3598
|
/**
|
|
3612
|
-
*
|
|
3613
|
-
*
|
|
3614
|
-
* @param index 索引(16位)
|
|
3615
|
-
* @param generation 世代版本(16位)
|
|
3616
|
-
* @returns 打包后的32位ID
|
|
3617
|
-
* @private
|
|
3599
|
+
* 结束处理
|
|
3618
3600
|
*/
|
|
3619
|
-
|
|
3601
|
+
end(): void;
|
|
3620
3602
|
/**
|
|
3621
|
-
*
|
|
3622
|
-
*
|
|
3623
|
-
* @param id 32位ID
|
|
3624
|
-
* @returns 索引部分(16位)
|
|
3625
|
-
* @private
|
|
3603
|
+
* 更新所有处理器
|
|
3626
3604
|
*/
|
|
3627
|
-
|
|
3605
|
+
update(): void;
|
|
3628
3606
|
/**
|
|
3629
|
-
*
|
|
3630
|
-
*
|
|
3631
|
-
* @param id 32位ID
|
|
3632
|
-
* @returns 世代版本部分(16位)
|
|
3633
|
-
* @private
|
|
3607
|
+
* 后期更新所有处理器
|
|
3634
3608
|
*/
|
|
3635
|
-
|
|
3609
|
+
lateUpdate(): void;
|
|
3636
3610
|
/**
|
|
3637
|
-
*
|
|
3638
|
-
*
|
|
3639
|
-
* @param index 索引
|
|
3640
|
-
* @param generation 世代版本
|
|
3641
|
-
* @returns 是否有效
|
|
3642
|
-
* @private
|
|
3611
|
+
* 排序处理器
|
|
3643
3612
|
*/
|
|
3644
|
-
private
|
|
3613
|
+
private sortProcessors;
|
|
3614
|
+
/** 获取处理器列表 */
|
|
3615
|
+
get processors(): EntitySystem[];
|
|
3616
|
+
/** 获取处理器数量 */
|
|
3617
|
+
get count(): number;
|
|
3645
3618
|
}
|
|
3646
3619
|
|
|
3647
3620
|
/**
|
|
3648
|
-
*
|
|
3621
|
+
* 场景接口定义
|
|
3649
3622
|
*
|
|
3650
|
-
*
|
|
3651
|
-
* 推荐使用组合而非继承的方式来构建自定义场景。
|
|
3623
|
+
* 定义场景应该实现的核心功能和属性,使用接口而非继承提供更灵活的实现方式。
|
|
3652
3624
|
*/
|
|
3653
|
-
|
|
3625
|
+
interface IScene {
|
|
3654
3626
|
/**
|
|
3655
3627
|
* 场景名称
|
|
3656
|
-
*
|
|
3657
|
-
* 用于标识和调试的友好名称。
|
|
3658
3628
|
*/
|
|
3659
3629
|
name: string;
|
|
3660
3630
|
/**
|
|
3661
3631
|
* 场景中的实体集合
|
|
3662
|
-
*
|
|
3663
|
-
* 管理场景内所有实体的生命周期。
|
|
3664
3632
|
*/
|
|
3665
3633
|
readonly entities: EntityList;
|
|
3666
3634
|
/**
|
|
3667
3635
|
* 实体系统处理器集合
|
|
3668
|
-
*
|
|
3669
|
-
* 管理场景内所有实体系统的执行。
|
|
3670
3636
|
*/
|
|
3671
3637
|
readonly entityProcessors: EntityProcessorList;
|
|
3672
3638
|
/**
|
|
3673
|
-
*
|
|
3674
|
-
*
|
|
3675
|
-
* 用于分配和回收实体的唯一标识符。
|
|
3639
|
+
* 标识符池
|
|
3676
3640
|
*/
|
|
3677
3641
|
readonly identifierPool: IdentifierPool;
|
|
3678
3642
|
/**
|
|
3679
3643
|
* 组件存储管理器
|
|
3680
|
-
*
|
|
3681
|
-
* 高性能的组件存储和查询系统。
|
|
3682
3644
|
*/
|
|
3683
3645
|
readonly componentStorageManager: ComponentStorageManager;
|
|
3684
3646
|
/**
|
|
3685
3647
|
* 查询系统
|
|
3686
|
-
*
|
|
3687
|
-
* 基于位掩码的高性能实体查询系统。
|
|
3688
3648
|
*/
|
|
3689
3649
|
readonly querySystem: QuerySystem;
|
|
3690
3650
|
/**
|
|
3691
3651
|
* 事件系统
|
|
3692
|
-
*
|
|
3693
|
-
* 类型安全的事件系统。
|
|
3694
3652
|
*/
|
|
3695
3653
|
readonly eventSystem: TypeSafeEventSystem;
|
|
3696
3654
|
/**
|
|
3697
|
-
*
|
|
3698
|
-
*/
|
|
3699
|
-
private _didSceneBegin;
|
|
3700
|
-
/**
|
|
3701
|
-
* 获取系统列表(兼容性属性)
|
|
3702
|
-
*/
|
|
3703
|
-
get systems(): EntitySystem[];
|
|
3704
|
-
/**
|
|
3705
|
-
* 创建场景实例
|
|
3655
|
+
* 获取系统列表
|
|
3706
3656
|
*/
|
|
3707
|
-
|
|
3657
|
+
readonly systems: EntitySystem[];
|
|
3708
3658
|
/**
|
|
3709
3659
|
* 初始化场景
|
|
3710
|
-
*
|
|
3711
|
-
* 在场景创建时调用,子类可以重写此方法来设置初始实体和组件。
|
|
3712
3660
|
*/
|
|
3713
3661
|
initialize(): void;
|
|
3714
3662
|
/**
|
|
3715
3663
|
* 场景开始运行时的回调
|
|
3716
|
-
*
|
|
3717
|
-
* 在场景开始运行时调用,可以在此方法中执行场景启动逻辑。
|
|
3718
3664
|
*/
|
|
3719
3665
|
onStart(): void;
|
|
3720
3666
|
/**
|
|
3721
3667
|
* 场景卸载时的回调
|
|
3722
|
-
*
|
|
3723
|
-
* 在场景被销毁时调用,可以在此方法中执行清理工作。
|
|
3724
3668
|
*/
|
|
3725
3669
|
unload(): void;
|
|
3726
3670
|
/**
|
|
3727
|
-
*
|
|
3728
|
-
*
|
|
3729
|
-
* 这个方法会启动场景。它将启动实体处理器等,并调用onStart方法。
|
|
3671
|
+
* 开始场景
|
|
3730
3672
|
*/
|
|
3731
3673
|
begin(): void;
|
|
3732
3674
|
/**
|
|
3733
|
-
*
|
|
3734
|
-
*
|
|
3735
|
-
* 这个方法会结束场景。它将移除所有实体,结束实体处理器等,并调用unload方法。
|
|
3675
|
+
* 结束场景
|
|
3736
3676
|
*/
|
|
3737
3677
|
end(): void;
|
|
3738
3678
|
/**
|
|
3739
|
-
*
|
|
3679
|
+
* 更新场景
|
|
3740
3680
|
*/
|
|
3741
3681
|
update(): void;
|
|
3742
3682
|
/**
|
|
3743
|
-
*
|
|
3744
|
-
* @param name 实体名称
|
|
3683
|
+
* 创建实体
|
|
3745
3684
|
*/
|
|
3746
3685
|
createEntity(name: string): Entity;
|
|
3747
3686
|
/**
|
|
3748
|
-
*
|
|
3749
|
-
* @param entity 要添加的实体
|
|
3750
|
-
* @param deferCacheClear 是否延迟缓存清理(用于批量操作)
|
|
3687
|
+
* 添加实体
|
|
3751
3688
|
*/
|
|
3752
3689
|
addEntity(entity: Entity, deferCacheClear?: boolean): Entity;
|
|
3753
3690
|
/**
|
|
3754
|
-
*
|
|
3755
|
-
* @param count 要创建的实体数量
|
|
3756
|
-
* @param namePrefix 实体名称前缀
|
|
3757
|
-
* @returns 创建的实体列表
|
|
3691
|
+
* 批量创建实体
|
|
3758
3692
|
*/
|
|
3759
3693
|
createEntities(count: number, namePrefix?: string): Entity[];
|
|
3760
3694
|
/**
|
|
3761
|
-
*
|
|
3695
|
+
* 销毁所有实体
|
|
3762
3696
|
*/
|
|
3763
3697
|
destroyAllEntities(): void;
|
|
3764
3698
|
/**
|
|
3765
|
-
*
|
|
3766
|
-
* @param name 实体名称
|
|
3699
|
+
* 查找实体
|
|
3767
3700
|
*/
|
|
3768
3701
|
findEntity(name: string): Entity | null;
|
|
3769
|
-
/**
|
|
3770
|
-
* 根据ID查找实体
|
|
3771
|
-
* @param id 实体ID
|
|
3772
|
-
*/
|
|
3773
|
-
findEntityById(id: number): Entity | null;
|
|
3774
3702
|
/**
|
|
3775
3703
|
* 根据标签查找实体
|
|
3776
|
-
* @param tag 实体标签
|
|
3777
3704
|
*/
|
|
3778
3705
|
findEntitiesByTag(tag: number): Entity[];
|
|
3779
3706
|
/**
|
|
3780
|
-
*
|
|
3781
|
-
* @param name 实体名称
|
|
3782
|
-
*/
|
|
3783
|
-
getEntityByName(name: string): Entity | null;
|
|
3784
|
-
/**
|
|
3785
|
-
* 根据标签查找实体(别名方法)
|
|
3786
|
-
* @param tag 实体标签
|
|
3787
|
-
*/
|
|
3788
|
-
getEntitiesByTag(tag: number): Entity[];
|
|
3789
|
-
/**
|
|
3790
|
-
* 在场景中添加一个EntitySystem处理器
|
|
3791
|
-
* @param processor 处理器
|
|
3707
|
+
* 添加实体处理器
|
|
3792
3708
|
*/
|
|
3793
3709
|
addEntityProcessor(processor: EntitySystem): EntitySystem;
|
|
3794
3710
|
/**
|
|
3795
|
-
*
|
|
3796
|
-
* @param system 系统
|
|
3711
|
+
* 移除实体处理器
|
|
3797
3712
|
*/
|
|
3798
|
-
|
|
3713
|
+
removeEntityProcessor(processor: EntitySystem): void;
|
|
3799
3714
|
/**
|
|
3800
|
-
*
|
|
3801
|
-
* @param processor 要删除的处理器
|
|
3715
|
+
* 获取实体处理器
|
|
3802
3716
|
*/
|
|
3803
|
-
|
|
3717
|
+
getEntityProcessor<T extends EntitySystem>(type: new (...args: any[]) => T): T | null;
|
|
3718
|
+
}
|
|
3719
|
+
/**
|
|
3720
|
+
* 场景工厂接口
|
|
3721
|
+
*/
|
|
3722
|
+
interface ISceneFactory<T extends IScene> {
|
|
3804
3723
|
/**
|
|
3805
|
-
*
|
|
3806
|
-
* @param type 处理器类型
|
|
3724
|
+
* 创建场景实例
|
|
3807
3725
|
*/
|
|
3808
|
-
|
|
3726
|
+
createScene(): T;
|
|
3727
|
+
}
|
|
3728
|
+
/**
|
|
3729
|
+
* 场景配置接口
|
|
3730
|
+
*/
|
|
3731
|
+
interface ISceneConfig {
|
|
3809
3732
|
/**
|
|
3810
|
-
*
|
|
3733
|
+
* 场景名称
|
|
3811
3734
|
*/
|
|
3812
|
-
|
|
3813
|
-
entityCount: number;
|
|
3814
|
-
processorCount: number;
|
|
3815
|
-
componentStorageStats: Map<string, any>;
|
|
3816
|
-
};
|
|
3735
|
+
name?: string;
|
|
3817
3736
|
/**
|
|
3818
|
-
*
|
|
3737
|
+
* 调试配置
|
|
3819
3738
|
*/
|
|
3820
|
-
|
|
3739
|
+
debug?: boolean;
|
|
3740
|
+
}
|
|
3741
|
+
|
|
3742
|
+
/**
|
|
3743
|
+
* 实体比较器
|
|
3744
|
+
*
|
|
3745
|
+
* 用于比较两个实体的优先级,首先按更新顺序比较,然后按ID比较。
|
|
3746
|
+
*/
|
|
3747
|
+
declare class EntityComparer {
|
|
3821
3748
|
/**
|
|
3822
|
-
*
|
|
3749
|
+
* 比较两个实体
|
|
3750
|
+
*
|
|
3751
|
+
* @param self - 第一个实体
|
|
3752
|
+
* @param other - 第二个实体
|
|
3753
|
+
* @returns 比较结果,负数表示self优先级更高,正数表示other优先级更高,0表示相等
|
|
3823
3754
|
*/
|
|
3824
|
-
|
|
3825
|
-
name: string;
|
|
3826
|
-
entityCount: number;
|
|
3827
|
-
processorCount: number;
|
|
3828
|
-
isRunning: boolean;
|
|
3829
|
-
entities: Array<{
|
|
3830
|
-
name: string;
|
|
3831
|
-
id: number;
|
|
3832
|
-
componentCount: number;
|
|
3833
|
-
componentTypes: string[];
|
|
3834
|
-
}>;
|
|
3835
|
-
processors: Array<{
|
|
3836
|
-
name: string;
|
|
3837
|
-
updateOrder: number;
|
|
3838
|
-
entityCount: number;
|
|
3839
|
-
}>;
|
|
3840
|
-
componentStats: Map<string, any>;
|
|
3841
|
-
};
|
|
3755
|
+
compare(self: Entity, other: Entity): number;
|
|
3842
3756
|
}
|
|
3843
|
-
|
|
3844
3757
|
/**
|
|
3845
|
-
*
|
|
3758
|
+
* 游戏实体类
|
|
3846
3759
|
*
|
|
3847
|
-
*
|
|
3848
|
-
*
|
|
3760
|
+
* ECS架构中的实体(Entity),作为组件的容器。
|
|
3761
|
+
* 实体本身不包含游戏逻辑,所有功能都通过组件来实现。
|
|
3762
|
+
* 支持父子关系,可以构建实体层次结构。
|
|
3849
3763
|
*
|
|
3850
3764
|
* @example
|
|
3851
3765
|
* ```typescript
|
|
3852
|
-
*
|
|
3853
|
-
*
|
|
3854
|
-
* super(Transform, Velocity);
|
|
3855
|
-
* }
|
|
3766
|
+
* // 创建实体
|
|
3767
|
+
* const entity = new Entity("Player", 1);
|
|
3856
3768
|
*
|
|
3857
|
-
*
|
|
3858
|
-
*
|
|
3859
|
-
*
|
|
3860
|
-
*
|
|
3861
|
-
*
|
|
3862
|
-
*
|
|
3863
|
-
*
|
|
3864
|
-
*
|
|
3769
|
+
* // 添加组件
|
|
3770
|
+
* const healthComponent = entity.addComponent(new HealthComponent(100));
|
|
3771
|
+
*
|
|
3772
|
+
* // 获取组件
|
|
3773
|
+
* const health = entity.getComponent(HealthComponent);
|
|
3774
|
+
*
|
|
3775
|
+
* // 添加位置组件
|
|
3776
|
+
* entity.addComponent(new PositionComponent(100, 200));
|
|
3777
|
+
*
|
|
3778
|
+
* // 添加子实体
|
|
3779
|
+
* const weapon = new Entity("Weapon", 2);
|
|
3780
|
+
* entity.addChild(weapon);
|
|
3865
3781
|
* ```
|
|
3866
3782
|
*/
|
|
3867
|
-
declare
|
|
3868
|
-
private _updateOrder;
|
|
3869
|
-
private _enabled;
|
|
3870
|
-
private _performanceMonitor;
|
|
3871
|
-
private _systemName;
|
|
3872
|
-
private _initialized;
|
|
3873
|
-
private _matcher;
|
|
3874
|
-
private _trackedEntities;
|
|
3875
|
-
/**
|
|
3876
|
-
* 获取系统处理的实体列表(动态查询)
|
|
3877
|
-
*/
|
|
3878
|
-
get entities(): readonly Entity[];
|
|
3783
|
+
declare class Entity {
|
|
3879
3784
|
/**
|
|
3880
|
-
*
|
|
3785
|
+
* Entity专用日志器
|
|
3881
3786
|
*/
|
|
3882
|
-
|
|
3883
|
-
set updateOrder(value: number);
|
|
3787
|
+
private static _logger;
|
|
3884
3788
|
/**
|
|
3885
|
-
*
|
|
3789
|
+
* 实体比较器实例
|
|
3886
3790
|
*/
|
|
3887
|
-
|
|
3791
|
+
static entityComparer: EntityComparer;
|
|
3888
3792
|
/**
|
|
3889
|
-
*
|
|
3793
|
+
* 全局事件总线实例
|
|
3794
|
+
* 用于发射组件相关事件
|
|
3890
3795
|
*/
|
|
3891
|
-
|
|
3796
|
+
static eventBus: EventBus | null;
|
|
3892
3797
|
/**
|
|
3893
|
-
*
|
|
3798
|
+
* 实体名称
|
|
3894
3799
|
*/
|
|
3895
|
-
|
|
3896
|
-
constructor(matcher?: Matcher);
|
|
3897
|
-
private _scene;
|
|
3800
|
+
name: string;
|
|
3898
3801
|
/**
|
|
3899
|
-
*
|
|
3802
|
+
* 实体唯一标识符
|
|
3900
3803
|
*/
|
|
3901
|
-
|
|
3902
|
-
set scene(value: Scene | null);
|
|
3804
|
+
readonly id: number;
|
|
3903
3805
|
/**
|
|
3904
|
-
*
|
|
3806
|
+
* 组件集合
|
|
3905
3807
|
*/
|
|
3906
|
-
|
|
3808
|
+
readonly components: Component[];
|
|
3907
3809
|
/**
|
|
3908
|
-
*
|
|
3909
|
-
* @param order 更新时序
|
|
3810
|
+
* 所属场景引用
|
|
3910
3811
|
*/
|
|
3911
|
-
|
|
3812
|
+
scene: IScene | null;
|
|
3912
3813
|
/**
|
|
3913
|
-
*
|
|
3914
|
-
*
|
|
3915
|
-
* 在系统创建时调用。框架内部使用,用户不应直接调用。
|
|
3814
|
+
* 更新间隔
|
|
3916
3815
|
*/
|
|
3917
|
-
|
|
3816
|
+
updateInterval: number;
|
|
3918
3817
|
/**
|
|
3919
|
-
*
|
|
3920
|
-
*
|
|
3921
|
-
* 子类可以重写此方法进行初始化操作。
|
|
3818
|
+
* 销毁状态标志
|
|
3922
3819
|
*/
|
|
3923
|
-
|
|
3820
|
+
_isDestroyed: boolean;
|
|
3924
3821
|
/**
|
|
3925
|
-
*
|
|
3926
|
-
*
|
|
3927
|
-
* 当系统从场景中移除时调用,重置初始化状态以便重新添加时能正确初始化。
|
|
3822
|
+
* 父实体引用
|
|
3928
3823
|
*/
|
|
3929
|
-
|
|
3824
|
+
private _parent;
|
|
3930
3825
|
/**
|
|
3931
|
-
*
|
|
3826
|
+
* 子实体集合
|
|
3932
3827
|
*/
|
|
3933
|
-
private
|
|
3828
|
+
private _children;
|
|
3934
3829
|
/**
|
|
3935
|
-
*
|
|
3830
|
+
* 激活状态
|
|
3936
3831
|
*/
|
|
3937
|
-
private
|
|
3832
|
+
private _active;
|
|
3938
3833
|
/**
|
|
3939
|
-
*
|
|
3834
|
+
* 实体标签
|
|
3940
3835
|
*/
|
|
3941
|
-
private
|
|
3836
|
+
private _tag;
|
|
3942
3837
|
/**
|
|
3943
|
-
*
|
|
3838
|
+
* 启用状态
|
|
3944
3839
|
*/
|
|
3945
|
-
private
|
|
3840
|
+
private _enabled;
|
|
3946
3841
|
/**
|
|
3947
|
-
*
|
|
3948
|
-
*
|
|
3949
|
-
* 在每帧调用,处理系统的主要逻辑。
|
|
3842
|
+
* 更新顺序
|
|
3950
3843
|
*/
|
|
3951
|
-
|
|
3844
|
+
private _updateOrder;
|
|
3952
3845
|
/**
|
|
3953
|
-
*
|
|
3954
|
-
*
|
|
3955
|
-
* 在所有系统的update方法执行完毕后调用。
|
|
3846
|
+
* 组件位掩码
|
|
3956
3847
|
*/
|
|
3957
|
-
|
|
3848
|
+
private _componentMask;
|
|
3958
3849
|
/**
|
|
3959
|
-
*
|
|
3960
|
-
*
|
|
3961
|
-
* 子类可以重写此方法进行预处理操作。
|
|
3850
|
+
* 按组件类型ID直址的稀疏数组
|
|
3962
3851
|
*/
|
|
3963
|
-
|
|
3852
|
+
private _componentsByTypeId;
|
|
3964
3853
|
/**
|
|
3965
|
-
*
|
|
3966
|
-
*
|
|
3967
|
-
* 系统的核心逻辑,子类必须实现此方法来定义具体的处理逻辑。
|
|
3968
|
-
*
|
|
3969
|
-
* @param entities 要处理的实体列表
|
|
3854
|
+
* typeId到components数组中密集索引的映射表
|
|
3970
3855
|
*/
|
|
3971
|
-
|
|
3856
|
+
private _componentDenseIndexByTypeId;
|
|
3972
3857
|
/**
|
|
3973
|
-
*
|
|
3974
|
-
*
|
|
3975
|
-
* 在主要处理逻辑之后执行,子类可以重写此方法。
|
|
3858
|
+
* 构造函数
|
|
3976
3859
|
*
|
|
3977
|
-
* @param
|
|
3860
|
+
* @param name - 实体名称
|
|
3861
|
+
* @param id - 实体唯一标识符
|
|
3978
3862
|
*/
|
|
3979
|
-
|
|
3863
|
+
constructor(name: string, id: number);
|
|
3980
3864
|
/**
|
|
3981
|
-
*
|
|
3982
|
-
*
|
|
3983
|
-
* 子类可以重写此方法进行后处理操作。
|
|
3865
|
+
* 获取销毁状态
|
|
3866
|
+
* @returns 如果实体已被销毁则返回true
|
|
3984
3867
|
*/
|
|
3985
|
-
|
|
3868
|
+
get isDestroyed(): boolean;
|
|
3986
3869
|
/**
|
|
3987
|
-
*
|
|
3988
|
-
*
|
|
3989
|
-
* 在启用系统时有用,但仅偶尔需要处理。
|
|
3990
|
-
* 这只影响处理,不影响事件或订阅列表。
|
|
3991
|
-
*
|
|
3992
|
-
* @returns 如果系统应该处理,则为true,如果不处理则为false
|
|
3870
|
+
* 获取父实体
|
|
3871
|
+
* @returns 父实体,如果没有父实体则返回null
|
|
3993
3872
|
*/
|
|
3994
|
-
|
|
3873
|
+
get parent(): Entity | null;
|
|
3995
3874
|
/**
|
|
3996
|
-
*
|
|
3875
|
+
* 获取子实体数组的只读副本
|
|
3997
3876
|
*
|
|
3998
|
-
* @returns
|
|
3877
|
+
* @returns 子实体数组的副本
|
|
3999
3878
|
*/
|
|
4000
|
-
|
|
3879
|
+
get children(): readonly Entity[];
|
|
4001
3880
|
/**
|
|
4002
|
-
*
|
|
3881
|
+
* 获取子实体数量
|
|
4003
3882
|
*
|
|
4004
|
-
* @returns
|
|
4005
|
-
*/
|
|
4006
|
-
getPerformanceStats(): PerformanceStats | undefined;
|
|
4007
|
-
/**
|
|
4008
|
-
* 重置系统的性能数据
|
|
3883
|
+
* @returns 子实体的数量
|
|
4009
3884
|
*/
|
|
4010
|
-
|
|
3885
|
+
get childCount(): number;
|
|
4011
3886
|
/**
|
|
4012
|
-
*
|
|
3887
|
+
* 获取活跃状态
|
|
4013
3888
|
*
|
|
4014
|
-
* @returns
|
|
4015
|
-
*/
|
|
4016
|
-
toString(): string;
|
|
4017
|
-
/**
|
|
4018
|
-
* 更新实体跟踪,检查新增和移除的实体
|
|
3889
|
+
* @returns 如果实体处于活跃状态则返回true
|
|
4019
3890
|
*/
|
|
4020
|
-
|
|
3891
|
+
get active(): boolean;
|
|
4021
3892
|
/**
|
|
4022
|
-
*
|
|
3893
|
+
* 设置活跃状态
|
|
4023
3894
|
*
|
|
4024
|
-
*
|
|
3895
|
+
* 设置实体的活跃状态,会影响子实体的有效活跃状态。
|
|
4025
3896
|
*
|
|
4026
|
-
* @param
|
|
3897
|
+
* @param value - 新的活跃状态
|
|
4027
3898
|
*/
|
|
4028
|
-
|
|
3899
|
+
set active(value: boolean);
|
|
4029
3900
|
/**
|
|
4030
|
-
*
|
|
3901
|
+
* 获取实体的有效活跃状态
|
|
4031
3902
|
*
|
|
4032
|
-
*
|
|
3903
|
+
* 考虑父实体的活跃状态,只有当实体本身和所有父实体都处于活跃状态时才返回true。
|
|
4033
3904
|
*
|
|
4034
|
-
* @
|
|
3905
|
+
* @returns 有效的活跃状态
|
|
4035
3906
|
*/
|
|
4036
|
-
|
|
4037
|
-
}
|
|
4038
|
-
|
|
4039
|
-
/**
|
|
4040
|
-
* 实体处理器列表管理器
|
|
4041
|
-
* 管理场景中的所有实体系统
|
|
4042
|
-
*/
|
|
4043
|
-
declare class EntityProcessorList {
|
|
4044
|
-
private static readonly _logger;
|
|
4045
|
-
private _processors;
|
|
4046
|
-
private _isDirty;
|
|
3907
|
+
get activeInHierarchy(): boolean;
|
|
4047
3908
|
/**
|
|
4048
|
-
*
|
|
3909
|
+
* 获取实体标签
|
|
3910
|
+
*
|
|
3911
|
+
* @returns 实体的数字标签
|
|
4049
3912
|
*/
|
|
4050
|
-
|
|
3913
|
+
get tag(): number;
|
|
4051
3914
|
/**
|
|
4052
|
-
*
|
|
4053
|
-
*
|
|
3915
|
+
* 设置实体标签
|
|
3916
|
+
*
|
|
3917
|
+
* @param value - 新的标签值
|
|
4054
3918
|
*/
|
|
4055
|
-
|
|
3919
|
+
set tag(value: number);
|
|
4056
3920
|
/**
|
|
4057
|
-
*
|
|
4058
|
-
*
|
|
3921
|
+
* 获取启用状态
|
|
3922
|
+
*
|
|
3923
|
+
* @returns 如果实体已启用则返回true
|
|
4059
3924
|
*/
|
|
4060
|
-
|
|
3925
|
+
get enabled(): boolean;
|
|
4061
3926
|
/**
|
|
4062
|
-
*
|
|
4063
|
-
*
|
|
3927
|
+
* 设置启用状态
|
|
3928
|
+
*
|
|
3929
|
+
* @param value - 新的启用状态
|
|
4064
3930
|
*/
|
|
4065
|
-
|
|
3931
|
+
set enabled(value: boolean);
|
|
4066
3932
|
/**
|
|
4067
|
-
*
|
|
3933
|
+
* 获取更新顺序
|
|
4068
3934
|
*
|
|
4069
|
-
*
|
|
3935
|
+
* @returns 实体的更新顺序值
|
|
4070
3936
|
*/
|
|
4071
|
-
|
|
3937
|
+
get updateOrder(): number;
|
|
4072
3938
|
/**
|
|
4073
|
-
*
|
|
3939
|
+
* 设置更新顺序
|
|
3940
|
+
*
|
|
3941
|
+
* @param value - 新的更新顺序值
|
|
4074
3942
|
*/
|
|
4075
|
-
|
|
3943
|
+
set updateOrder(value: number);
|
|
4076
3944
|
/**
|
|
4077
|
-
*
|
|
3945
|
+
* 获取组件位掩码
|
|
3946
|
+
*
|
|
3947
|
+
* @returns 实体的组件位掩码
|
|
4078
3948
|
*/
|
|
4079
|
-
|
|
3949
|
+
get componentMask(): BitMask64Data;
|
|
4080
3950
|
/**
|
|
4081
|
-
*
|
|
3951
|
+
* 创建并添加组件
|
|
3952
|
+
*
|
|
3953
|
+
* @param componentType - 组件类型
|
|
3954
|
+
* @param args - 组件构造函数参数
|
|
3955
|
+
* @returns 创建的组件实例
|
|
4082
3956
|
*/
|
|
4083
|
-
|
|
3957
|
+
createComponent<T extends Component>(componentType: ComponentType<T>, ...args: any[]): T;
|
|
4084
3958
|
/**
|
|
4085
|
-
*
|
|
3959
|
+
* 内部添加组件方法(不进行重复检查,用于初始化)
|
|
3960
|
+
*
|
|
3961
|
+
* @param component - 要添加的组件实例
|
|
3962
|
+
* @returns 添加的组件实例
|
|
4086
3963
|
*/
|
|
4087
|
-
private
|
|
4088
|
-
/** 获取处理器列表 */
|
|
4089
|
-
get processors(): EntitySystem[];
|
|
4090
|
-
/** 获取处理器数量 */
|
|
4091
|
-
get count(): number;
|
|
4092
|
-
}
|
|
4093
|
-
|
|
4094
|
-
/**
|
|
4095
|
-
* 场景接口定义
|
|
4096
|
-
*
|
|
4097
|
-
* 定义场景应该实现的核心功能和属性,使用接口而非继承提供更灵活的实现方式。
|
|
4098
|
-
*/
|
|
4099
|
-
interface IScene {
|
|
3964
|
+
private addComponentInternal;
|
|
4100
3965
|
/**
|
|
4101
|
-
*
|
|
3966
|
+
* 添加组件到实体
|
|
3967
|
+
*
|
|
3968
|
+
* @param component - 要添加的组件实例
|
|
3969
|
+
* @returns 添加的组件实例
|
|
3970
|
+
* @throws {Error} 如果组件类型已存在
|
|
4102
3971
|
*/
|
|
4103
|
-
|
|
3972
|
+
addComponent<T extends Component>(component: T): T;
|
|
4104
3973
|
/**
|
|
4105
|
-
*
|
|
3974
|
+
* 获取指定类型的组件
|
|
3975
|
+
*
|
|
3976
|
+
* @param type - 组件类型
|
|
3977
|
+
* @returns 组件实例或null
|
|
4106
3978
|
*/
|
|
4107
|
-
|
|
3979
|
+
getComponent<T extends Component>(type: ComponentType<T>): T | null;
|
|
4108
3980
|
/**
|
|
4109
|
-
*
|
|
3981
|
+
* 检查实体是否有指定类型的组件
|
|
3982
|
+
*
|
|
3983
|
+
* @param type - 组件类型
|
|
3984
|
+
* @returns 如果有该组件则返回true
|
|
4110
3985
|
*/
|
|
4111
|
-
|
|
3986
|
+
hasComponent<T extends Component>(type: ComponentType<T>): boolean;
|
|
4112
3987
|
/**
|
|
4113
|
-
*
|
|
3988
|
+
* 获取或创建指定类型的组件
|
|
3989
|
+
*
|
|
3990
|
+
* @param type - 组件类型
|
|
3991
|
+
* @param args - 组件构造函数参数(仅在创建时使用)
|
|
3992
|
+
* @returns 组件实例
|
|
4114
3993
|
*/
|
|
4115
|
-
|
|
3994
|
+
getOrCreateComponent<T extends Component>(type: ComponentType<T>, ...args: any[]): T;
|
|
4116
3995
|
/**
|
|
4117
|
-
*
|
|
3996
|
+
* 移除指定的组件
|
|
3997
|
+
*
|
|
3998
|
+
* @param component - 要移除的组件实例
|
|
4118
3999
|
*/
|
|
4119
|
-
|
|
4000
|
+
removeComponent(component: Component): void;
|
|
4120
4001
|
/**
|
|
4121
|
-
*
|
|
4002
|
+
* 移除指定类型的组件
|
|
4003
|
+
*
|
|
4004
|
+
* @param type - 组件类型
|
|
4005
|
+
* @returns 被移除的组件实例或null
|
|
4122
4006
|
*/
|
|
4123
|
-
|
|
4007
|
+
removeComponentByType<T extends Component>(type: ComponentType<T>): T | null;
|
|
4124
4008
|
/**
|
|
4125
|
-
*
|
|
4009
|
+
* 移除所有组件
|
|
4126
4010
|
*/
|
|
4127
|
-
|
|
4011
|
+
removeAllComponents(): void;
|
|
4128
4012
|
/**
|
|
4129
|
-
*
|
|
4013
|
+
* 批量添加组件
|
|
4014
|
+
*
|
|
4015
|
+
* @param components - 要添加的组件数组
|
|
4016
|
+
* @returns 添加的组件数组
|
|
4130
4017
|
*/
|
|
4131
|
-
|
|
4018
|
+
addComponents<T extends Component>(components: T[]): T[];
|
|
4132
4019
|
/**
|
|
4133
|
-
*
|
|
4020
|
+
* 批量移除组件类型
|
|
4021
|
+
*
|
|
4022
|
+
* @param componentTypes - 要移除的组件类型数组
|
|
4023
|
+
* @returns 被移除的组件数组
|
|
4134
4024
|
*/
|
|
4135
|
-
|
|
4025
|
+
removeComponentsByTypes<T extends Component>(componentTypes: ComponentType<T>[]): (T | null)[];
|
|
4136
4026
|
/**
|
|
4137
|
-
*
|
|
4027
|
+
* 获取所有指定类型的组件
|
|
4028
|
+
*
|
|
4029
|
+
* @param type - 组件类型
|
|
4030
|
+
* @returns 组件实例数组
|
|
4138
4031
|
*/
|
|
4139
|
-
|
|
4032
|
+
getComponents<T extends Component>(type: ComponentType<T>): T[];
|
|
4140
4033
|
/**
|
|
4141
|
-
*
|
|
4034
|
+
* 添加子实体
|
|
4035
|
+
*
|
|
4036
|
+
* @param child - 要添加的子实体
|
|
4037
|
+
* @returns 添加的子实体
|
|
4142
4038
|
*/
|
|
4143
|
-
|
|
4039
|
+
addChild(child: Entity): Entity;
|
|
4144
4040
|
/**
|
|
4145
|
-
*
|
|
4041
|
+
* 移除子实体
|
|
4042
|
+
*
|
|
4043
|
+
* @param child - 要移除的子实体
|
|
4044
|
+
* @returns 是否成功移除
|
|
4146
4045
|
*/
|
|
4147
|
-
|
|
4046
|
+
removeChild(child: Entity): boolean;
|
|
4148
4047
|
/**
|
|
4149
|
-
*
|
|
4048
|
+
* 移除所有子实体
|
|
4150
4049
|
*/
|
|
4151
|
-
|
|
4050
|
+
removeAllChildren(): void;
|
|
4152
4051
|
/**
|
|
4153
|
-
*
|
|
4052
|
+
* 根据名称查找子实体
|
|
4053
|
+
*
|
|
4054
|
+
* @param name - 子实体名称
|
|
4055
|
+
* @param recursive - 是否递归查找
|
|
4056
|
+
* @returns 找到的子实体或null
|
|
4154
4057
|
*/
|
|
4155
|
-
|
|
4058
|
+
findChild(name: string, recursive?: boolean): Entity | null;
|
|
4156
4059
|
/**
|
|
4157
|
-
*
|
|
4060
|
+
* 根据标签查找子实体
|
|
4061
|
+
*
|
|
4062
|
+
* @param tag - 标签
|
|
4063
|
+
* @param recursive - 是否递归查找
|
|
4064
|
+
* @returns 找到的子实体数组
|
|
4158
4065
|
*/
|
|
4159
|
-
|
|
4066
|
+
findChildrenByTag(tag: number, recursive?: boolean): Entity[];
|
|
4160
4067
|
/**
|
|
4161
|
-
*
|
|
4068
|
+
* 获取根实体
|
|
4069
|
+
*
|
|
4070
|
+
* @returns 层次结构的根实体
|
|
4162
4071
|
*/
|
|
4163
|
-
|
|
4072
|
+
getRoot(): Entity;
|
|
4164
4073
|
/**
|
|
4165
|
-
*
|
|
4074
|
+
* 检查是否是指定实体的祖先
|
|
4075
|
+
*
|
|
4076
|
+
* @param entity - 要检查的实体
|
|
4077
|
+
* @returns 如果是祖先则返回true
|
|
4166
4078
|
*/
|
|
4167
|
-
|
|
4079
|
+
isAncestorOf(entity: Entity): boolean;
|
|
4168
4080
|
/**
|
|
4169
|
-
*
|
|
4081
|
+
* 检查是否是指定实体的后代
|
|
4082
|
+
*
|
|
4083
|
+
* @param entity - 要检查的实体
|
|
4084
|
+
* @returns 如果是后代则返回true
|
|
4170
4085
|
*/
|
|
4171
|
-
|
|
4086
|
+
isDescendantOf(entity: Entity): boolean;
|
|
4172
4087
|
/**
|
|
4173
|
-
*
|
|
4088
|
+
* 获取层次深度
|
|
4089
|
+
*
|
|
4090
|
+
* @returns 在层次结构中的深度(根实体为0)
|
|
4174
4091
|
*/
|
|
4175
|
-
|
|
4092
|
+
getDepth(): number;
|
|
4176
4093
|
/**
|
|
4177
|
-
*
|
|
4094
|
+
* 遍历所有子实体(深度优先)
|
|
4095
|
+
*
|
|
4096
|
+
* @param callback - 对每个子实体执行的回调函数
|
|
4097
|
+
* @param recursive - 是否递归遍历
|
|
4178
4098
|
*/
|
|
4179
|
-
|
|
4099
|
+
forEachChild(callback: (child: Entity, index: number) => void, recursive?: boolean): void;
|
|
4180
4100
|
/**
|
|
4181
|
-
*
|
|
4101
|
+
* 活跃状态改变时的回调
|
|
4182
4102
|
*/
|
|
4183
|
-
|
|
4103
|
+
private onActiveChanged;
|
|
4184
4104
|
/**
|
|
4185
|
-
*
|
|
4105
|
+
* 更新实体
|
|
4106
|
+
*
|
|
4107
|
+
* 调用所有组件的更新方法,并更新子实体。
|
|
4186
4108
|
*/
|
|
4187
|
-
|
|
4109
|
+
update(): void;
|
|
4188
4110
|
/**
|
|
4189
|
-
*
|
|
4111
|
+
* 销毁实体
|
|
4112
|
+
*
|
|
4113
|
+
* 移除所有组件、子实体并标记为已销毁。
|
|
4190
4114
|
*/
|
|
4191
|
-
|
|
4192
|
-
}
|
|
4193
|
-
/**
|
|
4194
|
-
* 场景工厂接口
|
|
4195
|
-
*/
|
|
4196
|
-
interface ISceneFactory<T extends IScene> {
|
|
4115
|
+
destroy(): void;
|
|
4197
4116
|
/**
|
|
4198
|
-
*
|
|
4117
|
+
* 比较实体
|
|
4118
|
+
*
|
|
4119
|
+
* @param other - 另一个实体
|
|
4120
|
+
* @returns 比较结果
|
|
4199
4121
|
*/
|
|
4200
|
-
|
|
4201
|
-
}
|
|
4202
|
-
/**
|
|
4203
|
-
* 场景配置接口
|
|
4204
|
-
*/
|
|
4205
|
-
interface ISceneConfig {
|
|
4122
|
+
compareTo(other: Entity): number;
|
|
4206
4123
|
/**
|
|
4207
|
-
*
|
|
4124
|
+
* 获取实体的字符串表示
|
|
4125
|
+
*
|
|
4126
|
+
* @returns 实体的字符串描述
|
|
4208
4127
|
*/
|
|
4209
|
-
|
|
4128
|
+
toString(): string;
|
|
4210
4129
|
/**
|
|
4211
|
-
*
|
|
4130
|
+
* 获取实体的调试信息(包含组件缓存信息)
|
|
4131
|
+
*
|
|
4132
|
+
* @returns 包含实体详细信息的对象
|
|
4212
4133
|
*/
|
|
4213
|
-
|
|
4134
|
+
getDebugInfo(): {
|
|
4135
|
+
name: string;
|
|
4136
|
+
id: number;
|
|
4137
|
+
enabled: boolean;
|
|
4138
|
+
active: boolean;
|
|
4139
|
+
activeInHierarchy: boolean;
|
|
4140
|
+
destroyed: boolean;
|
|
4141
|
+
componentCount: number;
|
|
4142
|
+
componentTypes: string[];
|
|
4143
|
+
componentMask: string;
|
|
4144
|
+
parentId: number | null;
|
|
4145
|
+
childCount: number;
|
|
4146
|
+
childIds: number[];
|
|
4147
|
+
depth: number;
|
|
4148
|
+
indexMappingSize: number;
|
|
4149
|
+
denseIndexMappingSize: number;
|
|
4150
|
+
};
|
|
4214
4151
|
}
|
|
4215
4152
|
|
|
4216
4153
|
/**
|
|
@@ -4571,6 +4508,453 @@ declare class ECSFluentAPI {
|
|
|
4571
4508
|
*/
|
|
4572
4509
|
declare function createECSAPI(scene: IScene, querySystem: QuerySystem, eventSystem: TypeSafeEventSystem): ECSFluentAPI;
|
|
4573
4510
|
|
|
4511
|
+
/**
|
|
4512
|
+
* 全局系统接口
|
|
4513
|
+
* 全局系统是在World级别运行的系统,不依赖特定Scene
|
|
4514
|
+
*/
|
|
4515
|
+
interface IGlobalSystem {
|
|
4516
|
+
/**
|
|
4517
|
+
* 系统名称
|
|
4518
|
+
*/
|
|
4519
|
+
readonly name: string;
|
|
4520
|
+
/**
|
|
4521
|
+
* 初始化系统
|
|
4522
|
+
*/
|
|
4523
|
+
initialize?(): void;
|
|
4524
|
+
/**
|
|
4525
|
+
* 更新系统
|
|
4526
|
+
*/
|
|
4527
|
+
update(deltaTime?: number): void;
|
|
4528
|
+
/**
|
|
4529
|
+
* 重置系统
|
|
4530
|
+
*/
|
|
4531
|
+
reset?(): void;
|
|
4532
|
+
/**
|
|
4533
|
+
* 销毁系统
|
|
4534
|
+
*/
|
|
4535
|
+
destroy?(): void;
|
|
4536
|
+
}
|
|
4537
|
+
/**
|
|
4538
|
+
* World配置接口
|
|
4539
|
+
*/
|
|
4540
|
+
interface IWorldConfig {
|
|
4541
|
+
/**
|
|
4542
|
+
* World名称
|
|
4543
|
+
*/
|
|
4544
|
+
name?: string;
|
|
4545
|
+
/**
|
|
4546
|
+
* 是否启用调试模式
|
|
4547
|
+
*/
|
|
4548
|
+
debug?: boolean;
|
|
4549
|
+
/**
|
|
4550
|
+
* 最大Scene数量限制
|
|
4551
|
+
*/
|
|
4552
|
+
maxScenes?: number;
|
|
4553
|
+
/**
|
|
4554
|
+
* 是否自动清理空Scene
|
|
4555
|
+
*/
|
|
4556
|
+
autoCleanup?: boolean;
|
|
4557
|
+
}
|
|
4558
|
+
/**
|
|
4559
|
+
* World类 - ECS世界管理器
|
|
4560
|
+
*
|
|
4561
|
+
* World是Scene的容器,每个World可以管理多个Scene。
|
|
4562
|
+
* 这种设计允许创建独立的游戏世界,如:
|
|
4563
|
+
* - 游戏房间(每个房间一个World)
|
|
4564
|
+
* - 不同的游戏模式
|
|
4565
|
+
* - 独立的模拟环境
|
|
4566
|
+
*
|
|
4567
|
+
* @example
|
|
4568
|
+
* ```typescript
|
|
4569
|
+
* // 创建游戏房间的World
|
|
4570
|
+
* const roomWorld = new World({ name: 'Room_001' });
|
|
4571
|
+
*
|
|
4572
|
+
* // 在World中创建Scene
|
|
4573
|
+
* const gameScene = roomWorld.createScene('game', new Scene());
|
|
4574
|
+
* const uiScene = roomWorld.createScene('ui', new Scene());
|
|
4575
|
+
*
|
|
4576
|
+
* // 更新整个World
|
|
4577
|
+
* roomWorld.update(deltaTime);
|
|
4578
|
+
* ```
|
|
4579
|
+
*/
|
|
4580
|
+
declare class World {
|
|
4581
|
+
readonly name: string;
|
|
4582
|
+
private readonly _config;
|
|
4583
|
+
private readonly _scenes;
|
|
4584
|
+
private readonly _activeScenes;
|
|
4585
|
+
private readonly _globalSystems;
|
|
4586
|
+
private _isActive;
|
|
4587
|
+
private _createdAt;
|
|
4588
|
+
constructor(config?: IWorldConfig);
|
|
4589
|
+
/**
|
|
4590
|
+
* 创建并添加Scene到World
|
|
4591
|
+
*/
|
|
4592
|
+
createScene<T extends IScene>(sceneId: string, sceneInstance?: T): T;
|
|
4593
|
+
/**
|
|
4594
|
+
* 移除Scene
|
|
4595
|
+
*/
|
|
4596
|
+
removeScene(sceneId: string): boolean;
|
|
4597
|
+
/**
|
|
4598
|
+
* 获取Scene
|
|
4599
|
+
*/
|
|
4600
|
+
getScene<T extends IScene>(sceneId: string): T | null;
|
|
4601
|
+
/**
|
|
4602
|
+
* 获取所有Scene ID
|
|
4603
|
+
*/
|
|
4604
|
+
getSceneIds(): string[];
|
|
4605
|
+
/**
|
|
4606
|
+
* 获取所有Scene
|
|
4607
|
+
*/
|
|
4608
|
+
getAllScenes(): IScene[];
|
|
4609
|
+
/**
|
|
4610
|
+
* 设置Scene激活状态
|
|
4611
|
+
*/
|
|
4612
|
+
setSceneActive(sceneId: string, active: boolean): void;
|
|
4613
|
+
/**
|
|
4614
|
+
* 检查Scene是否激活
|
|
4615
|
+
*/
|
|
4616
|
+
isSceneActive(sceneId: string): boolean;
|
|
4617
|
+
/**
|
|
4618
|
+
* 获取活跃Scene数量
|
|
4619
|
+
*/
|
|
4620
|
+
getActiveSceneCount(): number;
|
|
4621
|
+
/**
|
|
4622
|
+
* 添加全局System
|
|
4623
|
+
* 全局System会在所有激活Scene之前更新
|
|
4624
|
+
*/
|
|
4625
|
+
addGlobalSystem<T extends IGlobalSystem>(system: T): T;
|
|
4626
|
+
/**
|
|
4627
|
+
* 移除全局System
|
|
4628
|
+
*/
|
|
4629
|
+
removeGlobalSystem(system: IGlobalSystem): boolean;
|
|
4630
|
+
/**
|
|
4631
|
+
* 获取全局System
|
|
4632
|
+
*/
|
|
4633
|
+
getGlobalSystem<T extends IGlobalSystem>(type: new (...args: any[]) => T): T | null;
|
|
4634
|
+
/**
|
|
4635
|
+
* 启动World
|
|
4636
|
+
*/
|
|
4637
|
+
start(): void;
|
|
4638
|
+
/**
|
|
4639
|
+
* 停止World
|
|
4640
|
+
*/
|
|
4641
|
+
stop(): void;
|
|
4642
|
+
/**
|
|
4643
|
+
* 更新World中的全局System
|
|
4644
|
+
* 注意:此方法由Core.update()调用,不应直接调用
|
|
4645
|
+
*/
|
|
4646
|
+
updateGlobalSystems(): void;
|
|
4647
|
+
/**
|
|
4648
|
+
* 更新World中的所有激活Scene
|
|
4649
|
+
* 注意:此方法由Core.update()调用,不应直接调用
|
|
4650
|
+
*/
|
|
4651
|
+
updateScenes(): void;
|
|
4652
|
+
/**
|
|
4653
|
+
* 销毁World
|
|
4654
|
+
*/
|
|
4655
|
+
destroy(): void;
|
|
4656
|
+
/**
|
|
4657
|
+
* 获取World状态
|
|
4658
|
+
*/
|
|
4659
|
+
getStatus(): {
|
|
4660
|
+
name: string;
|
|
4661
|
+
isActive: boolean;
|
|
4662
|
+
sceneCount: number;
|
|
4663
|
+
activeSceneCount: number;
|
|
4664
|
+
globalSystemCount: number;
|
|
4665
|
+
createdAt: number;
|
|
4666
|
+
config: {
|
|
4667
|
+
/**
|
|
4668
|
+
* World名称
|
|
4669
|
+
*/
|
|
4670
|
+
name?: string;
|
|
4671
|
+
/**
|
|
4672
|
+
* 是否启用调试模式
|
|
4673
|
+
*/
|
|
4674
|
+
debug?: boolean;
|
|
4675
|
+
/**
|
|
4676
|
+
* 最大Scene数量限制
|
|
4677
|
+
*/
|
|
4678
|
+
maxScenes?: number;
|
|
4679
|
+
/**
|
|
4680
|
+
* 是否自动清理空Scene
|
|
4681
|
+
*/
|
|
4682
|
+
autoCleanup?: boolean;
|
|
4683
|
+
};
|
|
4684
|
+
scenes: {
|
|
4685
|
+
id: string;
|
|
4686
|
+
isActive: boolean;
|
|
4687
|
+
name: string;
|
|
4688
|
+
}[];
|
|
4689
|
+
};
|
|
4690
|
+
/**
|
|
4691
|
+
* 获取World统计信息
|
|
4692
|
+
*/
|
|
4693
|
+
getStats(): {
|
|
4694
|
+
totalEntities: number;
|
|
4695
|
+
totalSystems: number;
|
|
4696
|
+
memoryUsage: number;
|
|
4697
|
+
performance: {
|
|
4698
|
+
averageUpdateTime: number;
|
|
4699
|
+
maxUpdateTime: number;
|
|
4700
|
+
};
|
|
4701
|
+
};
|
|
4702
|
+
/**
|
|
4703
|
+
* 检查是否应该执行自动清理
|
|
4704
|
+
*/
|
|
4705
|
+
private shouldAutoCleanup;
|
|
4706
|
+
/**
|
|
4707
|
+
* 执行清理操作
|
|
4708
|
+
*/
|
|
4709
|
+
private cleanup;
|
|
4710
|
+
/**
|
|
4711
|
+
* 检查World是否激活
|
|
4712
|
+
*/
|
|
4713
|
+
get isActive(): boolean;
|
|
4714
|
+
/**
|
|
4715
|
+
* 获取Scene数量
|
|
4716
|
+
*/
|
|
4717
|
+
get sceneCount(): number;
|
|
4718
|
+
/**
|
|
4719
|
+
* 获取创建时间
|
|
4720
|
+
*/
|
|
4721
|
+
get createdAt(): number;
|
|
4722
|
+
}
|
|
4723
|
+
|
|
4724
|
+
/**
|
|
4725
|
+
* WorldManager配置接口
|
|
4726
|
+
*/
|
|
4727
|
+
interface IWorldManagerConfig {
|
|
4728
|
+
/**
|
|
4729
|
+
* 最大World数量
|
|
4730
|
+
*/
|
|
4731
|
+
maxWorlds?: number;
|
|
4732
|
+
/**
|
|
4733
|
+
* 是否自动清理空World
|
|
4734
|
+
*/
|
|
4735
|
+
autoCleanup?: boolean;
|
|
4736
|
+
/**
|
|
4737
|
+
* 清理间隔(毫秒)
|
|
4738
|
+
*/
|
|
4739
|
+
cleanupInterval?: number;
|
|
4740
|
+
/**
|
|
4741
|
+
* 是否启用调试模式
|
|
4742
|
+
*/
|
|
4743
|
+
debug?: boolean;
|
|
4744
|
+
}
|
|
4745
|
+
/**
|
|
4746
|
+
* World管理器 - 管理所有World实例
|
|
4747
|
+
*
|
|
4748
|
+
* WorldManager是全局单例,负责管理所有World的生命周期。
|
|
4749
|
+
* 每个World都是独立的ECS环境,可以包含多个Scene。
|
|
4750
|
+
*
|
|
4751
|
+
* 设计理念:
|
|
4752
|
+
* - Core负责单Scene的传统ECS管理
|
|
4753
|
+
* - World负责多Scene的管理和协调
|
|
4754
|
+
* - WorldManager负责多World的全局管理
|
|
4755
|
+
*
|
|
4756
|
+
* @example
|
|
4757
|
+
* ```typescript
|
|
4758
|
+
* // 获取全局WorldManager
|
|
4759
|
+
* const worldManager = WorldManager.getInstance();
|
|
4760
|
+
*
|
|
4761
|
+
* // 创建游戏房间World
|
|
4762
|
+
* const roomWorld = worldManager.createWorld('room_001', {
|
|
4763
|
+
* name: 'GameRoom_001',
|
|
4764
|
+
* maxScenes: 5
|
|
4765
|
+
* });
|
|
4766
|
+
*
|
|
4767
|
+
* // 在游戏循环中更新所有World
|
|
4768
|
+
* worldManager.updateAll(deltaTime);
|
|
4769
|
+
* ```
|
|
4770
|
+
*/
|
|
4771
|
+
declare class WorldManager {
|
|
4772
|
+
private static _instance;
|
|
4773
|
+
private readonly _config;
|
|
4774
|
+
private readonly _worlds;
|
|
4775
|
+
private readonly _activeWorlds;
|
|
4776
|
+
private _cleanupTimer;
|
|
4777
|
+
private _isRunning;
|
|
4778
|
+
private constructor();
|
|
4779
|
+
/**
|
|
4780
|
+
* 获取WorldManager单例实例
|
|
4781
|
+
*/
|
|
4782
|
+
static getInstance(config?: IWorldManagerConfig): WorldManager;
|
|
4783
|
+
/**
|
|
4784
|
+
* 重置WorldManager实例(主要用于测试)
|
|
4785
|
+
*/
|
|
4786
|
+
static reset(): void;
|
|
4787
|
+
/**
|
|
4788
|
+
* 创建新World
|
|
4789
|
+
*/
|
|
4790
|
+
createWorld(worldId: string, config?: IWorldConfig): World;
|
|
4791
|
+
/**
|
|
4792
|
+
* 移除World
|
|
4793
|
+
*/
|
|
4794
|
+
removeWorld(worldId: string): boolean;
|
|
4795
|
+
/**
|
|
4796
|
+
* 获取World
|
|
4797
|
+
*/
|
|
4798
|
+
getWorld(worldId: string): World | null;
|
|
4799
|
+
/**
|
|
4800
|
+
* 获取所有World ID
|
|
4801
|
+
*/
|
|
4802
|
+
getWorldIds(): string[];
|
|
4803
|
+
/**
|
|
4804
|
+
* 获取所有World
|
|
4805
|
+
*/
|
|
4806
|
+
getAllWorlds(): World[];
|
|
4807
|
+
/**
|
|
4808
|
+
* 设置World激活状态
|
|
4809
|
+
*/
|
|
4810
|
+
setWorldActive(worldId: string, active: boolean): void;
|
|
4811
|
+
/**
|
|
4812
|
+
* 检查World是否激活
|
|
4813
|
+
*/
|
|
4814
|
+
isWorldActive(worldId: string): boolean;
|
|
4815
|
+
/**
|
|
4816
|
+
* 获取所有激活的World
|
|
4817
|
+
* 注意:此方法供Core.update()使用
|
|
4818
|
+
*/
|
|
4819
|
+
getActiveWorlds(): World[];
|
|
4820
|
+
/**
|
|
4821
|
+
* 启动所有World
|
|
4822
|
+
*/
|
|
4823
|
+
startAll(): void;
|
|
4824
|
+
/**
|
|
4825
|
+
* 停止所有World
|
|
4826
|
+
*/
|
|
4827
|
+
stopAll(): void;
|
|
4828
|
+
/**
|
|
4829
|
+
* 查找满足条件的World
|
|
4830
|
+
*/
|
|
4831
|
+
findWorlds(predicate: (world: World) => boolean): World[];
|
|
4832
|
+
/**
|
|
4833
|
+
* 根据名称查找World
|
|
4834
|
+
*/
|
|
4835
|
+
findWorldByName(name: string): World | null;
|
|
4836
|
+
/**
|
|
4837
|
+
* 获取WorldManager统计信息
|
|
4838
|
+
*/
|
|
4839
|
+
getStats(): {
|
|
4840
|
+
totalWorlds: number;
|
|
4841
|
+
activeWorlds: number;
|
|
4842
|
+
totalScenes: number;
|
|
4843
|
+
totalEntities: number;
|
|
4844
|
+
totalSystems: number;
|
|
4845
|
+
memoryUsage: number;
|
|
4846
|
+
isRunning: boolean;
|
|
4847
|
+
config: {
|
|
4848
|
+
/**
|
|
4849
|
+
* 最大World数量
|
|
4850
|
+
*/
|
|
4851
|
+
maxWorlds?: number;
|
|
4852
|
+
/**
|
|
4853
|
+
* 是否自动清理空World
|
|
4854
|
+
*/
|
|
4855
|
+
autoCleanup?: boolean;
|
|
4856
|
+
/**
|
|
4857
|
+
* 清理间隔(毫秒)
|
|
4858
|
+
*/
|
|
4859
|
+
cleanupInterval?: number;
|
|
4860
|
+
/**
|
|
4861
|
+
* 是否启用调试模式
|
|
4862
|
+
*/
|
|
4863
|
+
debug?: boolean;
|
|
4864
|
+
};
|
|
4865
|
+
worlds: any[];
|
|
4866
|
+
};
|
|
4867
|
+
/**
|
|
4868
|
+
* 获取详细状态信息
|
|
4869
|
+
*/
|
|
4870
|
+
getDetailedStatus(): {
|
|
4871
|
+
worlds: {
|
|
4872
|
+
id: string;
|
|
4873
|
+
isActive: boolean;
|
|
4874
|
+
status: {
|
|
4875
|
+
name: string;
|
|
4876
|
+
isActive: boolean;
|
|
4877
|
+
sceneCount: number;
|
|
4878
|
+
activeSceneCount: number;
|
|
4879
|
+
globalSystemCount: number;
|
|
4880
|
+
createdAt: number;
|
|
4881
|
+
config: {
|
|
4882
|
+
name?: string;
|
|
4883
|
+
debug?: boolean;
|
|
4884
|
+
maxScenes?: number;
|
|
4885
|
+
autoCleanup?: boolean;
|
|
4886
|
+
};
|
|
4887
|
+
scenes: {
|
|
4888
|
+
id: string;
|
|
4889
|
+
isActive: boolean;
|
|
4890
|
+
name: string;
|
|
4891
|
+
}[];
|
|
4892
|
+
};
|
|
4893
|
+
}[];
|
|
4894
|
+
totalWorlds: number;
|
|
4895
|
+
activeWorlds: number;
|
|
4896
|
+
totalScenes: number;
|
|
4897
|
+
totalEntities: number;
|
|
4898
|
+
totalSystems: number;
|
|
4899
|
+
memoryUsage: number;
|
|
4900
|
+
isRunning: boolean;
|
|
4901
|
+
config: {
|
|
4902
|
+
/**
|
|
4903
|
+
* 最大World数量
|
|
4904
|
+
*/
|
|
4905
|
+
maxWorlds?: number;
|
|
4906
|
+
/**
|
|
4907
|
+
* 是否自动清理空World
|
|
4908
|
+
*/
|
|
4909
|
+
autoCleanup?: boolean;
|
|
4910
|
+
/**
|
|
4911
|
+
* 清理间隔(毫秒)
|
|
4912
|
+
*/
|
|
4913
|
+
cleanupInterval?: number;
|
|
4914
|
+
/**
|
|
4915
|
+
* 是否启用调试模式
|
|
4916
|
+
*/
|
|
4917
|
+
debug?: boolean;
|
|
4918
|
+
};
|
|
4919
|
+
};
|
|
4920
|
+
/**
|
|
4921
|
+
* 清理空World
|
|
4922
|
+
*/
|
|
4923
|
+
cleanup(): number;
|
|
4924
|
+
/**
|
|
4925
|
+
* 销毁WorldManager
|
|
4926
|
+
*/
|
|
4927
|
+
destroy(): void;
|
|
4928
|
+
/**
|
|
4929
|
+
* 启动清理定时器
|
|
4930
|
+
*/
|
|
4931
|
+
private startCleanupTimer;
|
|
4932
|
+
/**
|
|
4933
|
+
* 停止清理定时器
|
|
4934
|
+
*/
|
|
4935
|
+
private stopCleanupTimer;
|
|
4936
|
+
/**
|
|
4937
|
+
* 判断World是否应该被清理
|
|
4938
|
+
*/
|
|
4939
|
+
private shouldCleanupWorld;
|
|
4940
|
+
/**
|
|
4941
|
+
* 获取World总数
|
|
4942
|
+
*/
|
|
4943
|
+
get worldCount(): number;
|
|
4944
|
+
/**
|
|
4945
|
+
* 获取激活World数量
|
|
4946
|
+
*/
|
|
4947
|
+
get activeWorldCount(): number;
|
|
4948
|
+
/**
|
|
4949
|
+
* 检查是否正在运行
|
|
4950
|
+
*/
|
|
4951
|
+
get isRunning(): boolean;
|
|
4952
|
+
/**
|
|
4953
|
+
* 获取配置
|
|
4954
|
+
*/
|
|
4955
|
+
get config(): IWorldManagerConfig;
|
|
4956
|
+
}
|
|
4957
|
+
|
|
4574
4958
|
/**
|
|
4575
4959
|
* 实体数据收集器
|
|
4576
4960
|
*/
|
|
@@ -4934,6 +5318,18 @@ declare class Core {
|
|
|
4934
5318
|
* 当设置为true时,游戏循环将暂停执行。
|
|
4935
5319
|
*/
|
|
4936
5320
|
static paused: boolean;
|
|
5321
|
+
/**
|
|
5322
|
+
* 默认World ID
|
|
5323
|
+
*
|
|
5324
|
+
* 用于单Scene模式的默认World标识
|
|
5325
|
+
*/
|
|
5326
|
+
private static readonly DEFAULT_WORLD_ID;
|
|
5327
|
+
/**
|
|
5328
|
+
* 默认Scene ID
|
|
5329
|
+
*
|
|
5330
|
+
* 用于单Scene模式的默认Scene标识
|
|
5331
|
+
*/
|
|
5332
|
+
private static readonly DEFAULT_SCENE_ID;
|
|
4937
5333
|
/**
|
|
4938
5334
|
* 全局核心实例
|
|
4939
5335
|
*/
|
|
@@ -4954,12 +5350,6 @@ declare class Core {
|
|
|
4954
5350
|
* 在调试模式下会启用额外的性能监控和错误检查。
|
|
4955
5351
|
*/
|
|
4956
5352
|
readonly debug: boolean;
|
|
4957
|
-
/**
|
|
4958
|
-
* 待切换的场景
|
|
4959
|
-
*
|
|
4960
|
-
* 存储下一帧要切换到的场景实例。
|
|
4961
|
-
*/
|
|
4962
|
-
_nextScene: IScene | null;
|
|
4963
5353
|
/**
|
|
4964
5354
|
* 全局管理器集合
|
|
4965
5355
|
*
|
|
@@ -4990,10 +5380,6 @@ declare class Core {
|
|
|
4990
5380
|
* 提供便捷的ECS操作接口。
|
|
4991
5381
|
*/
|
|
4992
5382
|
_ecsAPI?: ECSFluentAPI;
|
|
4993
|
-
/**
|
|
4994
|
-
* 当前活动场景
|
|
4995
|
-
*/
|
|
4996
|
-
_scene?: IScene;
|
|
4997
5383
|
/**
|
|
4998
5384
|
* 调试管理器
|
|
4999
5385
|
*
|
|
@@ -5001,13 +5387,15 @@ declare class Core {
|
|
|
5001
5387
|
*/
|
|
5002
5388
|
_debugManager?: DebugManager;
|
|
5003
5389
|
/**
|
|
5004
|
-
*
|
|
5390
|
+
* World管理器
|
|
5391
|
+
*
|
|
5392
|
+
* 管理多个World实例,支持多房间/多世界架构。
|
|
5005
5393
|
*/
|
|
5006
|
-
|
|
5394
|
+
_worldManager?: WorldManager;
|
|
5007
5395
|
/**
|
|
5008
|
-
*
|
|
5396
|
+
* Core配置
|
|
5009
5397
|
*/
|
|
5010
|
-
private
|
|
5398
|
+
private _config;
|
|
5011
5399
|
/**
|
|
5012
5400
|
* 创建核心实例
|
|
5013
5401
|
*
|
|
@@ -5021,58 +5409,24 @@ declare class Core {
|
|
|
5021
5409
|
*/
|
|
5022
5410
|
static get Instance(): Core;
|
|
5023
5411
|
/**
|
|
5024
|
-
*
|
|
5412
|
+
* 获取当前活动的场景(属性访问器)
|
|
5025
5413
|
*
|
|
5026
5414
|
* @returns 当前场景实例,如果没有则返回null
|
|
5027
5415
|
*/
|
|
5028
5416
|
static get scene(): IScene | null;
|
|
5029
5417
|
/**
|
|
5030
|
-
*
|
|
5031
|
-
*
|
|
5032
|
-
* @deprecated 请使用 Core.setScene() 方法代替。scene setter 可能导致场景延迟激活的时序问题,
|
|
5033
|
-
* 而 setScene() 提供更好的类型安全性和可预测的激活时序。
|
|
5034
|
-
*
|
|
5035
|
-
* 迁移示例:
|
|
5036
|
-
* ```typescript
|
|
5037
|
-
* // 旧方式(已废弃)
|
|
5038
|
-
* Core.scene = myScene;
|
|
5039
|
-
*
|
|
5040
|
-
* // 新方式(推荐)
|
|
5041
|
-
* Core.setScene(myScene);
|
|
5042
|
-
* ```
|
|
5418
|
+
* 获取当前活动的场景(方法调用)
|
|
5043
5419
|
*
|
|
5044
|
-
*
|
|
5045
|
-
*
|
|
5046
|
-
* @param value - 场景实例
|
|
5420
|
+
* @returns 当前场景实例,如果没有则返回null
|
|
5047
5421
|
*/
|
|
5048
|
-
static
|
|
5422
|
+
static getScene<T extends IScene>(): T | null;
|
|
5049
5423
|
/**
|
|
5050
|
-
*
|
|
5051
|
-
*
|
|
5052
|
-
* 这是设置场景的推荐方法,提供更好的类型安全性和可预测的激活时序。
|
|
5053
|
-
* 相比于 scene setter,此方法能确保场景正确初始化和激活。
|
|
5054
|
-
*
|
|
5055
|
-
* 如果当前没有场景,会立即切换;否则会在下一帧切换。
|
|
5424
|
+
* 设置当前场景
|
|
5056
5425
|
*
|
|
5057
5426
|
* @param scene - 要设置的场景实例
|
|
5058
5427
|
* @returns 设置的场景实例,便于链式调用
|
|
5059
|
-
*
|
|
5060
|
-
* @example
|
|
5061
|
-
* ```typescript
|
|
5062
|
-
* const myScene = new MyScene();
|
|
5063
|
-
* Core.setScene(myScene);
|
|
5064
|
-
*
|
|
5065
|
-
* // 链式调用
|
|
5066
|
-
* const scene = Core.setScene(new MyScene()).addSystem(new MySystem());
|
|
5067
|
-
* ```
|
|
5068
5428
|
*/
|
|
5069
5429
|
static setScene<T extends IScene>(scene: T): T;
|
|
5070
|
-
/**
|
|
5071
|
-
* 类型安全的场景获取方法
|
|
5072
|
-
*
|
|
5073
|
-
* @returns 当前场景实例
|
|
5074
|
-
*/
|
|
5075
|
-
static getScene<T extends IScene>(): T | null;
|
|
5076
5430
|
/**
|
|
5077
5431
|
* 创建Core实例
|
|
5078
5432
|
*
|
|
@@ -5170,23 +5524,23 @@ declare class Core {
|
|
|
5170
5524
|
*/
|
|
5171
5525
|
static get isDebugEnabled(): boolean;
|
|
5172
5526
|
/**
|
|
5173
|
-
*
|
|
5527
|
+
* 获取WorldManager实例
|
|
5174
5528
|
*
|
|
5175
|
-
* @returns
|
|
5529
|
+
* @returns WorldManager实例,如果未初始化则自动创建
|
|
5176
5530
|
*/
|
|
5177
|
-
static
|
|
5531
|
+
static getWorldManager(): WorldManager;
|
|
5178
5532
|
/**
|
|
5179
|
-
*
|
|
5533
|
+
* 启用World管理
|
|
5180
5534
|
*
|
|
5181
|
-
*
|
|
5535
|
+
* 显式启用World功能,用于多房间/多世界架构
|
|
5182
5536
|
*/
|
|
5183
|
-
static
|
|
5537
|
+
static enableWorldManager(): WorldManager;
|
|
5184
5538
|
/**
|
|
5185
|
-
*
|
|
5539
|
+
* 确保默认World存在
|
|
5186
5540
|
*
|
|
5187
|
-
*
|
|
5541
|
+
* 内部方法,用于懒初始化默认World
|
|
5188
5542
|
*/
|
|
5189
|
-
private
|
|
5543
|
+
private ensureDefaultWorld;
|
|
5190
5544
|
/**
|
|
5191
5545
|
* 场景切换回调
|
|
5192
5546
|
*
|
|
@@ -5199,12 +5553,6 @@ declare class Core {
|
|
|
5199
5553
|
* 执行核心系统的初始化逻辑。
|
|
5200
5554
|
*/
|
|
5201
5555
|
protected initialize(): void;
|
|
5202
|
-
/**
|
|
5203
|
-
* 记录兼容性信息
|
|
5204
|
-
*
|
|
5205
|
-
* 在控制台输出当前环境的兼容性信息和建议。
|
|
5206
|
-
*/
|
|
5207
|
-
private logCompatibilityInfo;
|
|
5208
5556
|
/**
|
|
5209
5557
|
* 内部更新方法
|
|
5210
5558
|
*
|
|
@@ -5469,163 +5817,153 @@ declare abstract class IntervalSystem extends EntitySystem {
|
|
|
5469
5817
|
}
|
|
5470
5818
|
|
|
5471
5819
|
/**
|
|
5472
|
-
*
|
|
5473
|
-
*
|
|
5474
|
-
* 基于BigInt实现,支持任意数量的位操作。
|
|
5475
|
-
* 自动适配运行环境,在不支持BigInt的环境中使用兼容实现。
|
|
5476
|
-
*
|
|
5477
|
-
* @example
|
|
5478
|
-
* ```typescript
|
|
5479
|
-
* const bits = new Bits();
|
|
5480
|
-
* bits.set(0);
|
|
5481
|
-
* bits.set(5);
|
|
5482
|
-
* console.log(bits.get(0)); // true
|
|
5483
|
-
* console.log(bits.get(1)); // false
|
|
5484
|
-
* ```
|
|
5820
|
+
* 64位位集合类,用于高效的位操作
|
|
5821
|
+
* 支持最多64个位的设置、清除、查询和逻辑运算
|
|
5485
5822
|
*/
|
|
5486
5823
|
declare class Bits {
|
|
5824
|
+
/** 存储位数据的64位掩码 */
|
|
5487
5825
|
private _value;
|
|
5488
5826
|
/**
|
|
5489
|
-
*
|
|
5490
|
-
* @param initialValue 初始值,可以是
|
|
5827
|
+
* 构造函数,创建位集合
|
|
5828
|
+
* @param initialValue 初始值,可以是BitMask64Data对象、数字或字符串
|
|
5491
5829
|
*/
|
|
5492
|
-
constructor(initialValue?:
|
|
5830
|
+
constructor(initialValue?: BitMask64Data | number | string);
|
|
5493
5831
|
/**
|
|
5494
|
-
*
|
|
5495
|
-
* @param index
|
|
5496
|
-
* @throws
|
|
5832
|
+
* 设置指定位为1
|
|
5833
|
+
* @param index 位索引,范围 [0, 63]
|
|
5834
|
+
* @throws 当位索引为负数或超过64位限制时抛出错误
|
|
5497
5835
|
*/
|
|
5498
5836
|
set(index: number): void;
|
|
5499
5837
|
/**
|
|
5500
|
-
*
|
|
5501
|
-
* @param index
|
|
5502
|
-
* @throws
|
|
5838
|
+
* 清除指定位为0
|
|
5839
|
+
* @param index 位索引,范围 [0, 63]
|
|
5840
|
+
* @throws 当位索引为负数时抛出错误
|
|
5503
5841
|
*/
|
|
5504
5842
|
clear(index: number): void;
|
|
5505
5843
|
/**
|
|
5506
|
-
*
|
|
5507
|
-
* @param index
|
|
5508
|
-
* @returns
|
|
5844
|
+
* 获取指定位的值
|
|
5845
|
+
* @param index 位索引
|
|
5846
|
+
* @returns 如果位被设置为1则返回true,否则返回false
|
|
5509
5847
|
*/
|
|
5510
5848
|
get(index: number): boolean;
|
|
5511
5849
|
/**
|
|
5512
|
-
*
|
|
5513
|
-
* @param other
|
|
5514
|
-
* @returns
|
|
5850
|
+
* 检查是否包含另一个位集合的所有位
|
|
5851
|
+
* @param other 另一个位集合
|
|
5852
|
+
* @returns 如果包含other的所有设置位则返回true
|
|
5515
5853
|
*/
|
|
5516
5854
|
containsAll(other: Bits): boolean;
|
|
5517
5855
|
/**
|
|
5518
|
-
*
|
|
5519
|
-
* @param other
|
|
5520
|
-
* @returns
|
|
5856
|
+
* 检查是否与另一个位集合有交集
|
|
5857
|
+
* @param other 另一个位集合
|
|
5858
|
+
* @returns 如果有共同的设置位则返回true
|
|
5521
5859
|
*/
|
|
5522
5860
|
intersects(other: Bits): boolean;
|
|
5523
5861
|
/**
|
|
5524
|
-
*
|
|
5525
|
-
* @param other
|
|
5526
|
-
* @returns
|
|
5862
|
+
* 检查是否与另一个位集合没有交集
|
|
5863
|
+
* @param other 另一个位集合
|
|
5864
|
+
* @returns 如果没有共同的设置位则返回true
|
|
5527
5865
|
*/
|
|
5528
5866
|
excludes(other: Bits): boolean;
|
|
5529
5867
|
/**
|
|
5530
|
-
*
|
|
5868
|
+
* 清除所有位为0
|
|
5531
5869
|
*/
|
|
5532
5870
|
clearAll(): void;
|
|
5533
5871
|
/**
|
|
5534
|
-
*
|
|
5535
|
-
* @returns
|
|
5872
|
+
* 检查位集合是否为空
|
|
5873
|
+
* @returns 如果所有位都为0则返回true
|
|
5536
5874
|
*/
|
|
5537
5875
|
isEmpty(): boolean;
|
|
5538
5876
|
/**
|
|
5539
|
-
*
|
|
5540
|
-
* @returns
|
|
5877
|
+
* 计算设置为1的位数
|
|
5878
|
+
* @returns 设置位的总数
|
|
5541
5879
|
*/
|
|
5542
5880
|
cardinality(): number;
|
|
5543
5881
|
/**
|
|
5544
|
-
*
|
|
5545
|
-
* @param other
|
|
5546
|
-
* @returns
|
|
5882
|
+
* 与另一个位集合执行按位与操作
|
|
5883
|
+
* @param other 另一个位集合
|
|
5884
|
+
* @returns 新的位集合,包含按位与的结果
|
|
5547
5885
|
*/
|
|
5548
5886
|
and(other: Bits): Bits;
|
|
5549
5887
|
/**
|
|
5550
|
-
*
|
|
5551
|
-
* @param other
|
|
5552
|
-
* @returns
|
|
5888
|
+
* 与另一个位集合执行按位或操作
|
|
5889
|
+
* @param other 另一个位集合
|
|
5890
|
+
* @returns 新的位集合,包含按位或的结果
|
|
5553
5891
|
*/
|
|
5554
5892
|
or(other: Bits): Bits;
|
|
5555
5893
|
/**
|
|
5556
|
-
*
|
|
5557
|
-
* @param other
|
|
5558
|
-
* @returns
|
|
5894
|
+
* 与另一个位集合执行按位异或操作
|
|
5895
|
+
* @param other 另一个位集合
|
|
5896
|
+
* @returns 新的位集合,包含按位异或的结果
|
|
5559
5897
|
*/
|
|
5560
5898
|
xor(other: Bits): Bits;
|
|
5561
5899
|
/**
|
|
5562
|
-
*
|
|
5563
|
-
* @param maxBits
|
|
5564
|
-
* @returns
|
|
5900
|
+
* 执行按位取反操作
|
|
5901
|
+
* @param maxBits 最大位数,默认为64
|
|
5902
|
+
* @returns 新的位集合,包含按位取反的结果
|
|
5565
5903
|
*/
|
|
5566
5904
|
not(maxBits?: number): Bits;
|
|
5567
5905
|
/**
|
|
5568
|
-
*
|
|
5569
|
-
* @param other
|
|
5906
|
+
* 从另一个位集合复制值
|
|
5907
|
+
* @param other 源位集合
|
|
5570
5908
|
*/
|
|
5571
5909
|
copyFrom(other: Bits): void;
|
|
5572
5910
|
/**
|
|
5573
|
-
*
|
|
5574
|
-
* @returns
|
|
5911
|
+
* 创建当前位集合的深拷贝
|
|
5912
|
+
* @returns 新的位集合,内容与当前位集合相同
|
|
5575
5913
|
*/
|
|
5576
5914
|
clone(): Bits;
|
|
5577
5915
|
/**
|
|
5578
|
-
*
|
|
5579
|
-
* @returns
|
|
5916
|
+
* 获取内部的64位掩码数据
|
|
5917
|
+
* @returns 内部存储的BitMask64Data对象
|
|
5580
5918
|
*/
|
|
5581
|
-
getValue():
|
|
5919
|
+
getValue(): BitMask64Data;
|
|
5582
5920
|
/**
|
|
5583
|
-
*
|
|
5584
|
-
* @param value
|
|
5921
|
+
* 设置位集合的值
|
|
5922
|
+
* @param value 新值,可以是BitMask64Data对象、数字或字符串
|
|
5585
5923
|
*/
|
|
5586
|
-
setValue(value:
|
|
5924
|
+
setValue(value: BitMask64Data | number | string): void;
|
|
5587
5925
|
/**
|
|
5588
|
-
*
|
|
5589
|
-
* @returns
|
|
5926
|
+
* 将位集合转换为可读字符串
|
|
5927
|
+
* @returns 格式为"Bits[index1, index2, ...]"的字符串
|
|
5590
5928
|
*/
|
|
5591
5929
|
toString(): string;
|
|
5592
5930
|
/**
|
|
5593
|
-
*
|
|
5594
|
-
* @param maxBits
|
|
5595
|
-
* @returns
|
|
5931
|
+
* 将位集合转换为二进制字符串
|
|
5932
|
+
* @param maxBits 最大位数,默认为64
|
|
5933
|
+
* @returns 二进制字符串表示,每8位用空格分隔
|
|
5596
5934
|
*/
|
|
5597
5935
|
toBinaryString(maxBits?: number): string;
|
|
5598
5936
|
/**
|
|
5599
|
-
*
|
|
5600
|
-
* @returns
|
|
5937
|
+
* 将位集合转换为十六进制字符串
|
|
5938
|
+
* @returns 十六进制字符串表示,带0x前缀
|
|
5601
5939
|
*/
|
|
5602
5940
|
toHexString(): string;
|
|
5603
5941
|
/**
|
|
5604
|
-
*
|
|
5605
|
-
* @param binaryString
|
|
5606
|
-
* @returns
|
|
5942
|
+
* 从二进制字符串创建位集合
|
|
5943
|
+
* @param binaryString 二进制字符串,可以包含空格
|
|
5944
|
+
* @returns 新的位集合对象
|
|
5607
5945
|
*/
|
|
5608
5946
|
static fromBinaryString(binaryString: string): Bits;
|
|
5609
5947
|
/**
|
|
5610
|
-
*
|
|
5611
|
-
* @param hexString
|
|
5612
|
-
* @returns
|
|
5948
|
+
* 从十六进制字符串创建位集合
|
|
5949
|
+
* @param hexString 十六进制字符串,可以带或不带0x前缀
|
|
5950
|
+
* @returns 新的位集合对象
|
|
5613
5951
|
*/
|
|
5614
5952
|
static fromHexString(hexString: string): Bits;
|
|
5615
5953
|
/**
|
|
5616
|
-
*
|
|
5617
|
-
* @param other
|
|
5618
|
-
* @returns
|
|
5954
|
+
* 检查是否与另一个位集合相等
|
|
5955
|
+
* @param other 另一个位集合
|
|
5956
|
+
* @returns 如果两个位集合完全相同则返回true
|
|
5619
5957
|
*/
|
|
5620
5958
|
equals(other: Bits): boolean;
|
|
5621
5959
|
/**
|
|
5622
|
-
*
|
|
5623
|
-
* @returns
|
|
5960
|
+
* 获取最高位设置位的索引
|
|
5961
|
+
* @returns 最高位设置位的索引,如果位集合为空则返回-1
|
|
5624
5962
|
*/
|
|
5625
5963
|
getHighestBitIndex(): number;
|
|
5626
5964
|
/**
|
|
5627
|
-
*
|
|
5628
|
-
* @returns
|
|
5965
|
+
* 获取最低位设置位的索引
|
|
5966
|
+
* @returns 最低位设置位的索引,如果位集合为空则返回-1
|
|
5629
5967
|
*/
|
|
5630
5968
|
getLowestBitIndex(): number;
|
|
5631
5969
|
}
|
|
@@ -5940,7 +6278,7 @@ declare class ComponentSparseSet {
|
|
|
5940
6278
|
* @param entity 实体
|
|
5941
6279
|
* @returns 组件位掩码,如果实体不存在则返回undefined
|
|
5942
6280
|
*/
|
|
5943
|
-
getEntityMask(entity: Entity):
|
|
6281
|
+
getEntityMask(entity: Entity): BitMask64Data | undefined;
|
|
5944
6282
|
/**
|
|
5945
6283
|
* 获取所有实体
|
|
5946
6284
|
*
|
|
@@ -5960,7 +6298,7 @@ declare class ComponentSparseSet {
|
|
|
5960
6298
|
*
|
|
5961
6299
|
* @param callback 遍历回调函数
|
|
5962
6300
|
*/
|
|
5963
|
-
forEach(callback: (entity: Entity, mask:
|
|
6301
|
+
forEach(callback: (entity: Entity, mask: BitMask64Data, index: number) => void): void;
|
|
5964
6302
|
/**
|
|
5965
6303
|
* 清空所有数据
|
|
5966
6304
|
*/
|
|
@@ -6879,5 +7217,5 @@ declare class Time {
|
|
|
6879
7217
|
static checkEvery(interval: number, lastTime: number): boolean;
|
|
6880
7218
|
}
|
|
6881
7219
|
|
|
6882
|
-
export { ArchetypeSystem, AsyncEventHandler,
|
|
6883
|
-
export type { Archetype, ArchetypeQueryResult, ComponentType$1 as ComponentType, DirtyData, DirtyListener, EventListenerConfig, EventStats, IComponent, IComponentDebugData, IComponentEventData, IComponentIndex, ICoreConfig, IECSDebugConfig, IECSDebugData, IEntityDebugData, IEntityEventData, IEntityHierarchyNode, IEventBus, IEventData, IEventListenerConfig, IEventStats, ILogger, IPerformanceDebugData, IPerformanceEventData, IPoolable, IScene, ISceneConfig, ISceneDebugData, ISceneEventData, ISceneFactory, ISystemBase, ISystemDebugData, ISystemEventData, ITimer, IndexStats, LoggerConfig, PerformanceData, PerformanceStats, PerformanceThresholds, PerformanceWarning, PoolStats };
|
|
7220
|
+
export { ArchetypeSystem, AsyncEventHandler$1 as AsyncEventHandler, BitMask64Utils, Bits, COMPONENT_TYPE_NAME, Component, ComponentDataCollector, ComponentIndex, ComponentIndexManager, ComponentPool, ComponentPoolManager, ComponentRegistry, ComponentSparseSet, ComponentStorage, ComponentTypeManager, ConsoleLogger, Core, DebugManager, DirtyFlag, DirtyTrackingSystem, ECSComponent, ECSEventType, ECSFluentAPI, ECSSystem, EVENT_TYPES, Emitter, EnableSoA, Entity, EntityDataCollector, EntityList, EntityManager, EntityProcessorList, EntityQueryBuilder, EntitySystem, EventBus, EventHandler$1 as EventHandler, EventPriority, EventTypeValidator, Float32, Float64, FuncPack, GlobalEventBus, GlobalManager, HighPrecision, IdentifierPool, Int32, IntervalSystem, LogLevel, Logger, LoggerManager, Matcher, NumberExtension, PassiveSystem, PerformanceDataCollector, PerformanceMonitor, PerformanceWarningType, Pool, PoolManager, ProcessingSystem, QuerySystem, SYSTEM_TYPE_NAME, Scene, SceneDataCollector, SerializeMap, SoAStorage, SparseSet, SystemDataCollector, Time, Timer, TimerManager, TypeSafeEventSystem, TypeUtils, WebSocketManager, World, WorldManager, createECSAPI, createLogger, getComponentInstanceTypeName, getComponentTypeName, getSystemInstanceTypeName, getSystemTypeName, setGlobalLogLevel };
|
|
7221
|
+
export type { Archetype, ArchetypeQueryResult, BitMask64Data, ComponentType$1 as ComponentType, DirtyData, DirtyListener, EventListenerConfig, EventStats, IComponent, IComponentDebugData, IComponentEventData, IComponentIndex, ICoreConfig, IECSDebugConfig, IECSDebugData, IEntityDebugData, IEntityEventData, IEntityHierarchyNode, IEventBus, IEventData, IEventListenerConfig, IEventStats, ILogger, IPerformanceDebugData, IPerformanceEventData, IPoolable, IScene, ISceneConfig, ISceneDebugData, ISceneEventData, ISceneFactory, ISystemBase, ISystemDebugData, ISystemEventData, ITimer, IWorldConfig, IWorldManagerConfig, IndexStats, LoggerConfig, PerformanceData, PerformanceStats, PerformanceThresholds, PerformanceWarning, PoolStats };
|