@esengine/ecs-framework 2.2.16 → 2.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @esengine/ecs-framework v2.2.16
2
+ * @esengine/ecs-framework v2.2.18
3
3
  * TypeScript definitions
4
4
  */
5
5
  /**
@@ -468,8 +468,6 @@ interface IECSDebugConfig {
468
468
  interface ICoreConfig {
469
469
  /** 是否启用调试模式 */
470
470
  debug?: boolean;
471
- /** 是否启用实体系统 */
472
- enableEntitySystems?: boolean;
473
471
  /** 调试配置 */
474
472
  debugConfig?: IECSDebugConfig;
475
473
  /** WorldManager配置 */
@@ -4349,6 +4347,147 @@ declare class ComponentSerializer {
4349
4347
  } | null;
4350
4348
  }
4351
4349
 
4350
+ /**
4351
+ * 层级关系系统 - 管理实体间的父子关系
4352
+ *
4353
+ * 提供层级操作的统一 API,维护层级缓存(depth、activeInHierarchy)。
4354
+ * 所有层级操作应通过此系统进行,而非直接修改 HierarchyComponent。
4355
+ *
4356
+ * @example
4357
+ * ```typescript
4358
+ * const hierarchySystem = scene.getSystem(HierarchySystem);
4359
+ *
4360
+ * // 设置父子关系
4361
+ * hierarchySystem.setParent(child, parent);
4362
+ *
4363
+ * // 查询层级
4364
+ * const parent = hierarchySystem.getParent(entity);
4365
+ * const children = hierarchySystem.getChildren(entity);
4366
+ * const depth = hierarchySystem.getDepth(entity);
4367
+ * ```
4368
+ */
4369
+ declare class HierarchySystem extends EntitySystem {
4370
+ private static readonly MAX_DEPTH;
4371
+ constructor();
4372
+ /**
4373
+ * 系统优先级,确保在其他系统之前更新层级缓存
4374
+ */
4375
+ get updateOrder(): number;
4376
+ protected process(): void;
4377
+ /**
4378
+ * 设置实体的父级
4379
+ *
4380
+ * @param child - 子实体
4381
+ * @param parent - 父实体,null 表示移动到根级
4382
+ */
4383
+ setParent(child: Entity, parent: Entity | null): void;
4384
+ /**
4385
+ * 在指定位置插入子实体
4386
+ *
4387
+ * @param parent - 父实体
4388
+ * @param child - 子实体
4389
+ * @param index - 插入位置索引,-1 表示追加到末尾
4390
+ */
4391
+ insertChildAt(parent: Entity, child: Entity, index: number): void;
4392
+ /**
4393
+ * 移除子实体(将其移动到根级)
4394
+ */
4395
+ removeChild(parent: Entity, child: Entity): boolean;
4396
+ /**
4397
+ * 移除所有子实体
4398
+ */
4399
+ removeAllChildren(parent: Entity): void;
4400
+ /**
4401
+ * 获取实体的父级
4402
+ */
4403
+ getParent(entity: Entity): Entity | null;
4404
+ /**
4405
+ * 获取实体的子级列表
4406
+ */
4407
+ getChildren(entity: Entity): Entity[];
4408
+ /**
4409
+ * 获取子级数量
4410
+ */
4411
+ getChildCount(entity: Entity): number;
4412
+ /**
4413
+ * 检查实体是否有子级
4414
+ */
4415
+ hasChildren(entity: Entity): boolean;
4416
+ /**
4417
+ * 检查 ancestor 是否是 entity 的祖先
4418
+ */
4419
+ isAncestorOf(ancestor: Entity, entity: Entity): boolean;
4420
+ /**
4421
+ * 检查 descendant 是否是 entity 的后代
4422
+ */
4423
+ isDescendantOf(descendant: Entity, entity: Entity): boolean;
4424
+ /**
4425
+ * 获取根实体
4426
+ */
4427
+ getRoot(entity: Entity): Entity;
4428
+ /**
4429
+ * 获取实体在层级中的深度
4430
+ */
4431
+ getDepth(entity: Entity): number;
4432
+ /**
4433
+ * 检查实体在层级中是否激活
4434
+ */
4435
+ isActiveInHierarchy(entity: Entity): boolean;
4436
+ /**
4437
+ * 获取所有根实体(没有父级的实体)
4438
+ */
4439
+ getRootEntities(): Entity[];
4440
+ /**
4441
+ * 根据名称查找子实体
4442
+ *
4443
+ * @param entity - 父实体
4444
+ * @param name - 子实体名称
4445
+ * @param bRecursive - 是否递归查找
4446
+ */
4447
+ findChild(entity: Entity, name: string, bRecursive?: boolean): Entity | null;
4448
+ /**
4449
+ * 根据标签查找子实体
4450
+ *
4451
+ * @param entity - 父实体
4452
+ * @param tag - 标签值
4453
+ * @param bRecursive - 是否递归查找
4454
+ */
4455
+ findChildrenByTag(entity: Entity, tag: number, bRecursive?: boolean): Entity[];
4456
+ /**
4457
+ * 遍历所有子级
4458
+ *
4459
+ * @param entity - 父实体
4460
+ * @param callback - 回调函数
4461
+ * @param bRecursive - 是否递归遍历
4462
+ */
4463
+ forEachChild(entity: Entity, callback: (child: Entity) => void, bRecursive?: boolean): void;
4464
+ /**
4465
+ * 扁平化层级树(用于虚拟化渲染)
4466
+ *
4467
+ * @param expandedIds - 展开的实体 ID 集合
4468
+ * @returns 扁平化的节点列表
4469
+ */
4470
+ flattenHierarchy(expandedIds: Set<number>): Array<{
4471
+ entity: Entity;
4472
+ depth: number;
4473
+ bHasChildren: boolean;
4474
+ bIsExpanded: boolean;
4475
+ }>;
4476
+ /**
4477
+ * 标记缓存为脏
4478
+ */
4479
+ private markCacheDirty;
4480
+ /**
4481
+ * 更新层级缓存
4482
+ */
4483
+ private updateHierarchyCache;
4484
+ /**
4485
+ * 当实体被移除时清理层级关系
4486
+ */
4487
+ protected onEntityRemoved(entity: Entity): void;
4488
+ dispose(): void;
4489
+ }
4490
+
4352
4491
  /**
4353
4492
  * 实体序列化器
4354
4493
  *
@@ -4405,9 +4544,10 @@ declare class EntitySerializer {
4405
4544
  *
4406
4545
  * @param entity 要序列化的实体
4407
4546
  * @param includeChildren 是否包含子实体(默认true)
4547
+ * @param hierarchySystem 层级系统(可选,用于获取层级信息)
4408
4548
  * @returns 序列化后的实体数据
4409
4549
  */
4410
- static serialize(entity: Entity, includeChildren?: boolean): SerializedEntity;
4550
+ static serialize(entity: Entity, includeChildren?: boolean, hierarchySystem?: HierarchySystem): SerializedEntity;
4411
4551
  /**
4412
4552
  * 反序列化实体
4413
4553
  *
@@ -4416,17 +4556,19 @@ declare class EntitySerializer {
4416
4556
  * @param idGenerator 实体ID生成器(用于生成新ID或保持原ID)
4417
4557
  * @param preserveIds 是否保持原始ID(默认false)
4418
4558
  * @param scene 目标场景(可选,用于设置entity.scene以支持添加组件)
4559
+ * @param hierarchySystem 层级系统(可选,用于建立层级关系)
4419
4560
  * @returns 反序列化后的实体
4420
4561
  */
4421
- static deserialize(serializedEntity: SerializedEntity, componentRegistry: Map<string, ComponentType>, idGenerator: () => number, preserveIds?: boolean, scene?: IScene): Entity;
4562
+ static deserialize(serializedEntity: SerializedEntity, componentRegistry: Map<string, ComponentType>, idGenerator: () => number, preserveIds?: boolean, scene?: IScene, hierarchySystem?: HierarchySystem | null, allEntities?: Map<number, Entity>): Entity;
4422
4563
  /**
4423
4564
  * 批量序列化实体
4424
4565
  *
4425
4566
  * @param entities 实体数组
4426
4567
  * @param includeChildren 是否包含子实体
4568
+ * @param hierarchySystem 层级系统(可选,用于获取层级信息)
4427
4569
  * @returns 序列化后的实体数据数组
4428
4570
  */
4429
- static serializeEntities(entities: Entity[], includeChildren?: boolean): SerializedEntity[];
4571
+ static serializeEntities(entities: Entity[], includeChildren?: boolean, hierarchySystem?: HierarchySystem): SerializedEntity[];
4430
4572
  /**
4431
4573
  * 批量反序列化实体
4432
4574
  *
@@ -4435,9 +4577,13 @@ declare class EntitySerializer {
4435
4577
  * @param idGenerator 实体ID生成器
4436
4578
  * @param preserveIds 是否保持原始ID
4437
4579
  * @param scene 目标场景(可选,用于设置entity.scene以支持添加组件)
4580
+ * @param hierarchySystem 层级系统(可选,用于建立层级关系)
4438
4581
  * @returns 反序列化后的实体数组
4439
4582
  */
4440
- static deserializeEntities(serializedEntities: SerializedEntity[], componentRegistry: Map<string, ComponentType>, idGenerator: () => number, preserveIds?: boolean, scene?: IScene): Entity[];
4583
+ static deserializeEntities(serializedEntities: SerializedEntity[], componentRegistry: Map<string, ComponentType>, idGenerator: () => number, preserveIds?: boolean, scene?: IScene, hierarchySystem?: HierarchySystem | null): {
4584
+ rootEntities: Entity[];
4585
+ allEntities: Map<number, Entity>;
4586
+ };
4441
4587
  /**
4442
4588
  * 创建实体的深拷贝
4443
4589
  *
@@ -4584,9 +4730,9 @@ declare class SceneSerializer {
4584
4730
  */
4585
4731
  static deserialize(scene: IScene, saveData: string | Uint8Array, options?: SceneDeserializationOptions): void;
4586
4732
  /**
4587
- * 递归调用实体及其子实体所有组件的 onDeserialized 方法
4733
+ * 调用实体所有组件的 onDeserialized 方法(不递归)
4588
4734
  */
4589
- private static callOnDeserializedRecursively;
4735
+ private static callOnDeserializedForEntity;
4590
4736
  /**
4591
4737
  * 递归添加实体的所有子实体到场景
4592
4738
  *
@@ -4597,6 +4743,7 @@ declare class SceneSerializer {
4597
4743
  *
4598
4744
  * @param entity 父实体
4599
4745
  * @param scene 目标场景
4746
+ * @param hierarchySystem 层级系统
4600
4747
  */
4601
4748
  private static addChildrenRecursively;
4602
4749
  /**
@@ -5672,6 +5819,12 @@ declare abstract class EntitySystem implements ISystemBase, IService {
5672
5819
  * 当Scene中的实体发生变化时调用
5673
5820
  */
5674
5821
  clearEntityCache(): void;
5822
+ /**
5823
+ * 完全重置实体跟踪状态
5824
+ * 清除所有缓存和跟踪的实体,强制下次 update 时重新扫描所有实体并触发 onAdded
5825
+ * 用于场景重载/预览重置等场景
5826
+ */
5827
+ resetEntityTracking(): void;
5675
5828
  /**
5676
5829
  * 重置系统状态
5677
5830
  *
@@ -6317,12 +6470,14 @@ declare class EntityComparer {
6317
6470
  *
6318
6471
  * ECS架构中的实体(Entity),作为组件的容器。
6319
6472
  * 实体本身不包含游戏逻辑,所有功能都通过组件来实现。
6320
- * 支持父子关系,可以构建实体层次结构。
6473
+ *
6474
+ * 层级关系通过 HierarchyComponent 和 HierarchySystem 管理,
6475
+ * 而非 Entity 内置属性,符合 ECS 组合原则。
6321
6476
  *
6322
6477
  * @example
6323
6478
  * ```typescript
6324
6479
  * // 创建实体
6325
- * const entity = new Entity("Player", 1);
6480
+ * const entity = scene.createEntity("Player");
6326
6481
  *
6327
6482
  * // 添加组件
6328
6483
  * const healthComponent = entity.addComponent(new HealthComponent(100));
@@ -6330,12 +6485,9 @@ declare class EntityComparer {
6330
6485
  * // 获取组件
6331
6486
  * const health = entity.getComponent(HealthComponent);
6332
6487
  *
6333
- * // 添加位置组件
6334
- * entity.addComponent(new PositionComponent(100, 200));
6335
- *
6336
- * // 添加子实体
6337
- * const weapon = new Entity("Weapon", 2);
6338
- * entity.addChild(weapon);
6488
+ * // 层级关系使用 HierarchySystem
6489
+ * const hierarchySystem = scene.getSystem(HierarchySystem);
6490
+ * hierarchySystem.setParent(childEntity, parentEntity);
6339
6491
  * ```
6340
6492
  */
6341
6493
  declare class Entity {
@@ -6363,14 +6515,6 @@ declare class Entity {
6363
6515
  * 销毁状态标志
6364
6516
  */
6365
6517
  private _isDestroyed;
6366
- /**
6367
- * 父实体引用
6368
- */
6369
- private _parent;
6370
- /**
6371
- * 子实体集合
6372
- */
6373
- private _children;
6374
6518
  /**
6375
6519
  * 激活状态
6376
6520
  */
@@ -6425,23 +6569,6 @@ declare class Entity {
6425
6569
  * 从存储重建组件缓存
6426
6570
  */
6427
6571
  private _rebuildComponentCache;
6428
- /**
6429
- * 获取父实体
6430
- * @returns 父实体,如果没有父实体则返回null
6431
- */
6432
- get parent(): Entity | null;
6433
- /**
6434
- * 获取子实体数组的只读副本
6435
- *
6436
- * @returns 子实体数组的副本
6437
- */
6438
- get children(): readonly Entity[];
6439
- /**
6440
- * 获取子实体数量
6441
- *
6442
- * @returns 子实体的数量
6443
- */
6444
- get childCount(): number;
6445
6572
  /**
6446
6573
  * 获取活跃状态
6447
6574
  *
@@ -6451,19 +6578,9 @@ declare class Entity {
6451
6578
  /**
6452
6579
  * 设置活跃状态
6453
6580
  *
6454
- * 设置实体的活跃状态,会影响子实体的有效活跃状态。
6455
- *
6456
6581
  * @param value - 新的活跃状态
6457
6582
  */
6458
6583
  set active(value: boolean);
6459
- /**
6460
- * 获取实体的有效活跃状态
6461
- *
6462
- * 考虑父实体的活跃状态,只有当实体本身和所有父实体都处于活跃状态时才返回true。
6463
- *
6464
- * @returns 有效的活跃状态
6465
- */
6466
- get activeInHierarchy(): boolean;
6467
6584
  /**
6468
6585
  * 获取实体标签
6469
6586
  *
@@ -6650,73 +6767,6 @@ declare class Entity {
6650
6767
  * ```
6651
6768
  */
6652
6769
  getComponentByType<T extends Component>(baseType: ComponentType<T>): T | null;
6653
- /**
6654
- * 添加子实体
6655
- *
6656
- * @param child - 要添加的子实体
6657
- * @returns 添加的子实体
6658
- */
6659
- addChild(child: Entity): Entity;
6660
- /**
6661
- * 移除子实体
6662
- *
6663
- * @param child - 要移除的子实体
6664
- * @returns 是否成功移除
6665
- */
6666
- removeChild(child: Entity): boolean;
6667
- /**
6668
- * 移除所有子实体
6669
- */
6670
- removeAllChildren(): void;
6671
- /**
6672
- * 根据名称查找子实体
6673
- *
6674
- * @param name - 子实体名称
6675
- * @param recursive - 是否递归查找
6676
- * @returns 找到的子实体或null
6677
- */
6678
- findChild(name: string, recursive?: boolean): Entity | null;
6679
- /**
6680
- * 根据标签查找子实体
6681
- *
6682
- * @param tag - 标签
6683
- * @param recursive - 是否递归查找
6684
- * @returns 找到的子实体数组
6685
- */
6686
- findChildrenByTag(tag: number, recursive?: boolean): Entity[];
6687
- /**
6688
- * 获取根实体
6689
- *
6690
- * @returns 层次结构的根实体
6691
- */
6692
- getRoot(): Entity;
6693
- /**
6694
- * 检查是否是指定实体的祖先
6695
- *
6696
- * @param entity - 要检查的实体
6697
- * @returns 如果是祖先则返回true
6698
- */
6699
- isAncestorOf(entity: Entity): boolean;
6700
- /**
6701
- * 检查是否是指定实体的后代
6702
- *
6703
- * @param entity - 要检查的实体
6704
- * @returns 如果是后代则返回true
6705
- */
6706
- isDescendantOf(entity: Entity): boolean;
6707
- /**
6708
- * 获取层次深度
6709
- *
6710
- * @returns 在层次结构中的深度(根实体为0)
6711
- */
6712
- getDepth(): number;
6713
- /**
6714
- * 遍历所有子实体(深度优先)
6715
- *
6716
- * @param callback - 对每个子实体执行的回调函数
6717
- * @param recursive - 是否递归遍历
6718
- */
6719
- forEachChild(callback: (child: Entity, index: number) => void, recursive?: boolean): void;
6720
6770
  /**
6721
6771
  * 活跃状态改变时的回调
6722
6772
  */
@@ -6724,13 +6774,10 @@ declare class Entity {
6724
6774
  /**
6725
6775
  * 销毁实体
6726
6776
  *
6727
- * 移除所有组件、子实体并标记为已销毁
6777
+ * 移除所有组件并标记为已销毁。
6778
+ * 层级关系的清理由 HierarchySystem 处理。
6728
6779
  */
6729
6780
  destroy(): void;
6730
- /**
6731
- * 批量销毁所有子实体
6732
- */
6733
- destroyAllChildren(): void;
6734
6781
  /**
6735
6782
  * 比较实体
6736
6783
  *
@@ -6754,15 +6801,10 @@ declare class Entity {
6754
6801
  id: number;
6755
6802
  enabled: boolean;
6756
6803
  active: boolean;
6757
- activeInHierarchy: boolean;
6758
6804
  destroyed: boolean;
6759
6805
  componentCount: number;
6760
6806
  componentTypes: string[];
6761
6807
  componentMask: string;
6762
- parentId: number | null;
6763
- childCount: number;
6764
- childIds: number[];
6765
- depth: number;
6766
6808
  cacheBuilt: boolean;
6767
6809
  };
6768
6810
  }
@@ -7929,7 +7971,7 @@ declare global {
7929
7971
  }
7930
7972
  }
7931
7973
 
7932
- type PropertyType = 'number' | 'integer' | 'string' | 'boolean' | 'color' | 'vector2' | 'vector3' | 'enum' | 'asset' | 'animationClips';
7974
+ type PropertyType = 'number' | 'integer' | 'string' | 'boolean' | 'color' | 'vector2' | 'vector3' | 'enum' | 'asset' | 'animationClips' | 'collisionLayer' | 'collisionMask';
7933
7975
  /**
7934
7976
  * 资源类型
7935
7977
  * Asset type for asset properties
@@ -8050,11 +8092,25 @@ interface AssetPropertyOptions extends PropertyOptionsBase {
8050
8092
  interface AnimationClipsPropertyOptions extends PropertyOptionsBase {
8051
8093
  type: 'animationClips';
8052
8094
  }
8095
+ /**
8096
+ * 碰撞层属性选项
8097
+ * Collision layer property options
8098
+ */
8099
+ interface CollisionLayerPropertyOptions extends PropertyOptionsBase {
8100
+ type: 'collisionLayer';
8101
+ }
8102
+ /**
8103
+ * 碰撞掩码属性选项
8104
+ * Collision mask property options
8105
+ */
8106
+ interface CollisionMaskPropertyOptions extends PropertyOptionsBase {
8107
+ type: 'collisionMask';
8108
+ }
8053
8109
  /**
8054
8110
  * 属性选项联合类型
8055
8111
  * Property options union type
8056
8112
  */
8057
- type PropertyOptions = NumberPropertyOptions | StringPropertyOptions | BooleanPropertyOptions | ColorPropertyOptions | VectorPropertyOptions | EnumPropertyOptions | AssetPropertyOptions | AnimationClipsPropertyOptions;
8113
+ type PropertyOptions = NumberPropertyOptions | StringPropertyOptions | BooleanPropertyOptions | ColorPropertyOptions | VectorPropertyOptions | EnumPropertyOptions | AssetPropertyOptions | AnimationClipsPropertyOptions | CollisionLayerPropertyOptions | CollisionMaskPropertyOptions;
8058
8114
  declare const PROPERTY_METADATA: unique symbol;
8059
8115
  /**
8060
8116
  * 属性装饰器 - 声明组件属性的编辑器元数据
@@ -8081,6 +8137,51 @@ declare function getPropertyMetadata(target: Function): Record<string, PropertyO
8081
8137
  */
8082
8138
  declare function hasPropertyMetadata(target: Function): boolean;
8083
8139
 
8140
+ /**
8141
+ * 层级关系组件 - 用于建立实体间的父子关系
8142
+ *
8143
+ * 只有需要层级关系的实体才添加此组件,遵循 ECS 组合原则。
8144
+ * 层级操作应通过 HierarchySystem 进行,而非直接修改此组件。
8145
+ *
8146
+ * @example
8147
+ * ```typescript
8148
+ * // 通过 HierarchySystem 设置父子关系
8149
+ * const hierarchySystem = scene.getSystem(HierarchySystem);
8150
+ * hierarchySystem.setParent(childEntity, parentEntity);
8151
+ *
8152
+ * // 查询层级信息
8153
+ * const parent = hierarchySystem.getParent(entity);
8154
+ * const children = hierarchySystem.getChildren(entity);
8155
+ * ```
8156
+ */
8157
+ declare class HierarchyComponent extends Component {
8158
+ /**
8159
+ * 父实体 ID
8160
+ * null 表示根实体(无父级)
8161
+ */
8162
+ parentId: number | null;
8163
+ /**
8164
+ * 子实体 ID 列表
8165
+ * 顺序即为子级的排列顺序
8166
+ */
8167
+ childIds: number[];
8168
+ /**
8169
+ * 在层级中的深度
8170
+ * 根实体深度为 0,由 HierarchySystem 维护
8171
+ */
8172
+ depth: number;
8173
+ /**
8174
+ * 层级中是否激活
8175
+ * 考虑所有祖先的激活状态,由 HierarchySystem 维护
8176
+ */
8177
+ bActiveInHierarchy: boolean;
8178
+ /**
8179
+ * 层级缓存是否脏
8180
+ * 用于优化缓存更新
8181
+ */
8182
+ bCacheDirty: boolean;
8183
+ }
8184
+
8084
8185
  /**
8085
8186
  * 实体构建器 - 提供流式API创建和配置实体
8086
8187
  */
@@ -9716,6 +9817,77 @@ declare class MigrationBuilder {
9716
9817
  migrate(migration: ComponentMigrationFunction | SceneMigrationFunction): void;
9717
9818
  }
9718
9819
 
9820
+ /**
9821
+ * 实体标签常量
9822
+ *
9823
+ * 用于标识特殊类型的实体,如文件夹、摄像机等。
9824
+ * 使用位掩码实现,支持多标签组合。
9825
+ *
9826
+ * @example
9827
+ * ```typescript
9828
+ * // 创建文件夹实体
9829
+ * entity.tag = EntityTags.FOLDER;
9830
+ *
9831
+ * // 检查是否是文件夹
9832
+ * if ((entity.tag & EntityTags.FOLDER) !== 0) {
9833
+ * // 是文件夹
9834
+ * }
9835
+ *
9836
+ * // 组合多个标签
9837
+ * entity.tag = EntityTags.FOLDER | EntityTags.HIDDEN;
9838
+ * ```
9839
+ */
9840
+ declare const EntityTags: {
9841
+ /** 无标签 */
9842
+ readonly NONE: 0;
9843
+ /** 文件夹实体 - 用于场景层级中的组织分类 */
9844
+ readonly FOLDER: 4096;
9845
+ /** 隐藏实体 - 在编辑器层级中不显示 */
9846
+ readonly HIDDEN: 8192;
9847
+ /** 锁定实体 - 在编辑器中不可选择/编辑 */
9848
+ readonly LOCKED: 16384;
9849
+ /** 编辑器专用实体 - 仅在编辑器中存在,不导出到运行时 */
9850
+ readonly EDITOR_ONLY: 32768;
9851
+ /** 预制件实例 */
9852
+ readonly PREFAB_INSTANCE: 256;
9853
+ /** 预制件根节点 */
9854
+ readonly PREFAB_ROOT: 512;
9855
+ };
9856
+ type EntityTagValue = (typeof EntityTags)[keyof typeof EntityTags];
9857
+ /**
9858
+ * 检查实体是否具有指定标签
9859
+ *
9860
+ * @param entityTag - 实体的 tag 值
9861
+ * @param tag - 要检查的标签
9862
+ */
9863
+ declare function hasEntityTag(entityTag: number, tag: EntityTagValue): boolean;
9864
+ /**
9865
+ * 添加标签到实体
9866
+ *
9867
+ * @param entityTag - 当前 tag 值
9868
+ * @param tag - 要添加的标签
9869
+ */
9870
+ declare function addEntityTag(entityTag: number, tag: EntityTagValue): number;
9871
+ /**
9872
+ * 从实体移除标签
9873
+ *
9874
+ * @param entityTag - 当前 tag 值
9875
+ * @param tag - 要移除的标签
9876
+ */
9877
+ declare function removeEntityTag(entityTag: number, tag: EntityTagValue): number;
9878
+ /**
9879
+ * 检查实体是否是文件夹
9880
+ */
9881
+ declare function isFolder(entityTag: number): boolean;
9882
+ /**
9883
+ * 检查实体是否隐藏
9884
+ */
9885
+ declare function isHidden(entityTag: number): boolean;
9886
+ /**
9887
+ * 检查实体是否锁定
9888
+ */
9889
+ declare function isLocked(entityTag: number): boolean;
9890
+
9719
9891
  interface ITimer<TContext = unknown> {
9720
9892
  context: TContext;
9721
9893
  /**
@@ -9737,11 +9909,11 @@ interface ITimer<TContext = unknown> {
9737
9909
  */
9738
9910
  declare class Timer<TContext = unknown> implements ITimer<TContext> {
9739
9911
  context: TContext;
9740
- _timeInSeconds: number;
9741
- _repeats: boolean;
9742
- _onTime: (timer: ITimer<TContext>) => void;
9743
- _isDone: boolean;
9744
- _elapsedTime: number;
9912
+ private _timeInSeconds;
9913
+ private _repeats;
9914
+ private _onTime;
9915
+ private _isDone;
9916
+ private _elapsedTime;
9745
9917
  getContext<T>(): T;
9746
9918
  /**
9747
9919
  * 定时器是否已完成
@@ -9762,1978 +9934,2668 @@ declare class Timer<TContext = unknown> implements ITimer<TContext> {
9762
9934
  }
9763
9935
 
9764
9936
  /**
9765
- * 定时器管理器
9766
- *
9767
- * 允许动作的延迟和重复执行
9937
+ * 插件状态
9768
9938
  */
9769
- declare class TimerManager implements IService, IUpdatable {
9770
- _timers: Array<Timer<unknown>>;
9771
- update(): void;
9939
+ declare enum PluginState {
9772
9940
  /**
9773
- * 调度一个一次性或重复的计时器,该计时器将调用已传递的动作
9774
- * @param timeInSeconds
9775
- * @param repeats
9776
- * @param context
9777
- * @param onTime
9941
+ * 未安装
9778
9942
  */
9779
- schedule<TContext = unknown>(timeInSeconds: number, repeats: boolean, context: TContext, onTime: (timer: ITimer<TContext>) => void): Timer<TContext>;
9943
+ NotInstalled = "not_installed",
9780
9944
  /**
9781
- * 释放资源
9945
+ * 已安装
9782
9946
  */
9783
- dispose(): void;
9784
- }
9785
-
9786
- /**
9787
- * 可池化对象接口
9788
- */
9789
- interface IPoolable {
9947
+ Installed = "installed",
9790
9948
  /**
9791
- * 重置对象状态,准备重用
9949
+ * 安装失败
9792
9950
  */
9793
- reset(): void;
9951
+ Failed = "failed"
9794
9952
  }
9795
9953
  /**
9796
- * 对象池统计信息
9954
+ * 插件接口
9955
+ *
9956
+ * 所有插件都必须实现此接口。
9957
+ * 插件提供了一种扩展框架功能的标准方式。
9958
+ *
9959
+ * @example
9960
+ * ```typescript
9961
+ * class MyPlugin implements IPlugin {
9962
+ * readonly name = 'my-plugin';
9963
+ * readonly version = '1.0.0';
9964
+ * readonly dependencies = ['other-plugin'];
9965
+ *
9966
+ * async install(core: Core, services: ServiceContainer) {
9967
+ * // 注册服务
9968
+ * services.registerSingleton(MyService);
9969
+ *
9970
+ * // 添加系统
9971
+ * const world = core.getWorld();
9972
+ * if (world) {
9973
+ * world.addSystem(new MySystem());
9974
+ * }
9975
+ * }
9976
+ *
9977
+ * async uninstall() {
9978
+ * // 清理资源
9979
+ * }
9980
+ * }
9981
+ * ```
9797
9982
  */
9798
- interface PoolStats {
9799
- /** 池中对象数量 */
9800
- size: number;
9801
- /** 池的最大大小 */
9802
- maxSize: number;
9803
- /** 总共创建的对象数量 */
9804
- totalCreated: number;
9805
- /** 总共获取的次数 */
9806
- totalObtained: number;
9807
- /** 总共释放的次数 */
9808
- totalReleased: number;
9809
- /** 命中率(从池中获取的比例) */
9810
- hitRate: number;
9811
- /** 内存使用估算(字节) */
9812
- estimatedMemoryUsage: number;
9813
- }
9814
-
9815
- /**
9816
- * 高性能通用对象池
9817
- * 支持任意类型的对象池化,包含详细的统计信息
9818
- */
9819
- declare class Pool<T extends IPoolable> {
9820
- private static _pools;
9821
- private _objects;
9822
- private _createFn;
9823
- private _maxSize;
9824
- private _stats;
9825
- private _objectSize;
9826
- /**
9827
- * 构造函数
9828
- * @param createFn 创建对象的函数
9829
- * @param maxSize 池的最大大小,默认100
9830
- * @param estimatedObjectSize 估算的单个对象大小(字节),默认1024
9831
- */
9832
- constructor(createFn: () => T, maxSize?: number, estimatedObjectSize?: number);
9833
- /**
9834
- * 获取指定类型的对象池
9835
- * @param type 对象类型
9836
- * @param maxSize 池的最大大小
9837
- * @param estimatedObjectSize 估算的单个对象大小
9838
- * @returns 对象池实例
9839
- */
9840
- static getPool<T extends IPoolable>(type: new (...args: unknown[]) => T, maxSize?: number, estimatedObjectSize?: number): Pool<T>;
9841
- /**
9842
- * 从池中获取对象
9843
- * @returns 对象实例
9844
- */
9845
- obtain(): T;
9846
- /**
9847
- * 释放对象回池中
9848
- * @param obj 要释放的对象
9849
- */
9850
- release(obj: T): void;
9851
- /**
9852
- * 获取池统计信息
9853
- * @returns 统计信息对象
9854
- */
9855
- getStats(): Readonly<PoolStats>;
9856
- /**
9857
- * 清空池
9858
- */
9859
- clear(): void;
9860
- /**
9861
- * 压缩池(移除多余的对象)
9862
- * @param targetSize 目标大小,默认为当前大小的一半
9863
- */
9864
- compact(targetSize?: number): void;
9865
- /**
9866
- * 预填充池
9867
- * @param count 预填充的对象数量
9868
- */
9869
- prewarm(count: number): void;
9870
- /**
9871
- * 设置最大池大小
9872
- * @param maxSize 新的最大大小
9873
- */
9874
- setMaxSize(maxSize: number): void;
9983
+ interface IPlugin {
9875
9984
  /**
9876
- * 获取池中可用对象数量
9877
- * @returns 可用对象数量
9985
+ * 插件唯一名称
9986
+ *
9987
+ * 用于依赖解析和插件管理。
9878
9988
  */
9879
- getAvailableCount(): number;
9989
+ readonly name: string;
9880
9990
  /**
9881
- * 检查池是否为空
9882
- * @returns 如果池为空返回true
9991
+ * 插件版本
9992
+ *
9993
+ * 遵循语义化版本规范 (semver)。
9883
9994
  */
9884
- isEmpty(): boolean;
9995
+ readonly version: string;
9885
9996
  /**
9886
- * 检查池是否已满
9887
- * @returns 如果池已满返回true
9997
+ * 依赖的其他插件名称列表
9998
+ *
9999
+ * 这些插件必须在当前插件之前安装。
9888
10000
  */
9889
- isFull(): boolean;
10001
+ readonly dependencies?: readonly string[];
9890
10002
  /**
9891
- * 获取所有已注册的池类型
9892
- * @returns 所有池类型的数组
10003
+ * 安装插件
10004
+ *
10005
+ * 在此方法中初始化插件,注册服务、系统等。
10006
+ * 可以是同步或异步的。
10007
+ *
10008
+ * @param core - Core实例,用于访问World等
10009
+ * @param services - 服务容器,用于注册服务
9893
10010
  */
9894
- static getAllPoolTypes(): Function[];
10011
+ install(core: Core, services: ServiceContainer): void | Promise<void>;
9895
10012
  /**
9896
- * 获取所有池的统计信息
9897
- * @returns 包含所有池统计信息的对象
10013
+ * 卸载插件
10014
+ *
10015
+ * 清理插件占用的资源。
10016
+ * 可以是同步或异步的。
9898
10017
  */
9899
- static getAllPoolStats(): Record<string, PoolStats>;
10018
+ uninstall(): void | Promise<void>;
10019
+ }
10020
+ /**
10021
+ * 插件元数据
10022
+ */
10023
+ interface IPluginMetadata {
9900
10024
  /**
9901
- * 压缩所有池
10025
+ * 插件名称
9902
10026
  */
9903
- static compactAllPools(): void;
10027
+ name: string;
9904
10028
  /**
9905
- * 清空所有池
10029
+ * 插件版本
9906
10030
  */
9907
- static clearAllPools(): void;
10031
+ version: string;
9908
10032
  /**
9909
- * 获取全局池统计信息的格式化字符串
9910
- * @returns 格式化的统计信息字符串
10033
+ * 插件状态
9911
10034
  */
9912
- static getGlobalStatsString(): string;
10035
+ state: PluginState;
9913
10036
  /**
9914
- * 更新命中率
10037
+ * 安装时间戳
9915
10038
  */
9916
- private _updateHitRate;
10039
+ installedAt?: number;
9917
10040
  /**
9918
- * 更新内存使用估算
10041
+ * 错误信息(如果安装失败)
9919
10042
  */
9920
- private _updateMemoryUsage;
10043
+ error?: string;
9921
10044
  }
9922
10045
 
9923
10046
  /**
9924
- * 池管理器
9925
- * 统一管理所有对象池
10047
+ * 游戏引擎核心类
10048
+ *
10049
+ * 职责:
10050
+ * - 提供全局服务(Timer、Performance、Pool等)
10051
+ * - 管理场景生命周期(内置SceneManager)
10052
+ * - 管理全局管理器的生命周期
10053
+ * - 提供统一的游戏循环更新入口
10054
+ *
10055
+ * @example
10056
+ * ```typescript
10057
+ * // 初始化并设置场景
10058
+ * Core.create({ debug: true });
10059
+ * Core.setScene(new GameScene());
10060
+ *
10061
+ * // 游戏循环(自动更新全局服务和场景)
10062
+ * function gameLoop(deltaTime: number) {
10063
+ * Core.update(deltaTime);
10064
+ * }
10065
+ *
10066
+ * // 使用定时器
10067
+ * Core.schedule(1.0, false, null, (timer) => {
10068
+ * console.log("1秒后执行");
10069
+ * });
10070
+ *
10071
+ * // 切换场景
10072
+ * Core.loadScene(new MenuScene()); // 延迟切换
10073
+ * Core.setScene(new GameScene()); // 立即切换
10074
+ *
10075
+ * // 获取当前场景
10076
+ * const currentScene = Core.scene;
10077
+ * ```
9926
10078
  */
9927
- declare class PoolManager implements IService {
9928
- private pools;
9929
- private autoCompactInterval;
9930
- private lastCompactTime;
9931
- constructor();
10079
+ declare class Core {
9932
10080
  /**
9933
- * 注册池
9934
- * @param name 池名称
9935
- * @param pool 池实例
10081
+ * 游戏暂停状态
10082
+ *
10083
+ * 当设置为true时,游戏循环将暂停执行。
9936
10084
  */
9937
- registerPool<T extends IPoolable>(name: string, pool: Pool<T>): void;
10085
+ static paused: boolean;
9938
10086
  /**
9939
- * 获取池
9940
- * @param name 池名称
9941
- * @returns 池实例
10087
+ * 全局核心实例
10088
+ *
10089
+ * 可能为null表示Core尚未初始化或已被销毁
9942
10090
  */
9943
- getPool<T extends IPoolable>(name: string): Pool<T> | null;
10091
+ private static _instance;
9944
10092
  /**
9945
- * 更新池管理器(应在游戏循环中调用)
10093
+ * Core专用日志器
9946
10094
  */
9947
- update(): void;
10095
+ private static _logger;
9948
10096
  /**
9949
- * 创建或获取标准池
9950
- * @param name 池名称
9951
- * @param createFn 创建函数
9952
- * @param maxSize 最大大小
9953
- * @param estimatedObjectSize 估算对象大小
9954
- * @returns 池实例
10097
+ * 调试模式标志
10098
+ *
10099
+ * 在调试模式下会启用额外的性能监控和错误检查。
9955
10100
  */
9956
- createPool<T extends IPoolable>(name: string, createFn: () => T, maxSize?: number, estimatedObjectSize?: number): Pool<T>;
10101
+ readonly debug: boolean;
9957
10102
  /**
9958
- * 移除池
9959
- * @param name 池名称
9960
- * @returns 是否成功移除
10103
+ * 服务容器
10104
+ *
10105
+ * 管理所有服务的注册、解析和生命周期。
9961
10106
  */
9962
- removePool(name: string): boolean;
10107
+ private _serviceContainer;
10108
+ private _timerManager;
10109
+ private _performanceMonitor;
10110
+ private _poolManager;
10111
+ private _debugManager?;
9963
10112
  /**
9964
- * 获取所有池名称
9965
- * @returns 池名称数组
10113
+ * 场景管理器
10114
+ *
10115
+ * 管理当前场景的生命周期。
9966
10116
  */
9967
- getPoolNames(): string[];
10117
+ private _sceneManager;
9968
10118
  /**
9969
- * 获取池数量
9970
- * @returns 池数量
10119
+ * World管理器
10120
+ *
10121
+ * 管理多个独立的World实例(可选)。
9971
10122
  */
9972
- getPoolCount(): number;
10123
+ private _worldManager;
9973
10124
  /**
9974
- * 压缩所有池
10125
+ * 插件管理器
10126
+ *
10127
+ * 管理所有插件的生命周期。
9975
10128
  */
9976
- compactAllPools(): void;
10129
+ private _pluginManager;
9977
10130
  /**
9978
- * 清空所有池
10131
+ * Core配置
9979
10132
  */
9980
- clearAllPools(): void;
10133
+ private _config;
9981
10134
  /**
9982
- * 获取所有池的统计信息
9983
- * @returns 统计信息映射
10135
+ * 创建核心实例
10136
+ *
10137
+ * @param config - Core配置对象
9984
10138
  */
9985
- getAllStats(): Map<string, PoolStats>;
10139
+ private constructor();
9986
10140
  /**
9987
- * 获取总体统计信息
9988
- * @returns 总体统计信息
10141
+ * 获取核心实例
10142
+ *
10143
+ * @returns 全局核心实例
9989
10144
  */
9990
- getGlobalStats(): PoolStats;
10145
+ static get Instance(): Core | null;
9991
10146
  /**
9992
- * 获取格式化的统计信息字符串
9993
- * @returns 格式化字符串
9994
- */
9995
- getStatsString(): string;
9996
- /**
9997
- * 设置自动压缩间隔
9998
- * @param intervalMs 间隔毫秒数
10147
+ * 获取服务容器
10148
+ *
10149
+ * 用于注册和解析自定义服务。
10150
+ *
10151
+ * @returns 服务容器实例
10152
+ * @throws 如果Core实例未创建
10153
+ *
10154
+ * @example
10155
+ * ```typescript
10156
+ * // 注册自定义服务
10157
+ * Core.services.registerSingleton(MyService);
10158
+ *
10159
+ * // 解析服务
10160
+ * const myService = Core.services.resolve(MyService);
10161
+ * ```
9999
10162
  */
10000
- setAutoCompactInterval(intervalMs: number): void;
10163
+ static get services(): ServiceContainer;
10001
10164
  /**
10002
- * 预填充所有池
10165
+ * 获取World管理器
10166
+ *
10167
+ * 用于管理多个独立的World实例(高级用户)。
10168
+ *
10169
+ * @returns WorldManager实例
10170
+ * @throws 如果Core实例未创建
10171
+ *
10172
+ * @example
10173
+ * ```typescript
10174
+ * // 创建多个游戏房间
10175
+ * const wm = Core.worldManager;
10176
+ * const room1 = wm.createWorld('room_001');
10177
+ * room1.createScene('game', new GameScene());
10178
+ * room1.start();
10179
+ * ```
10003
10180
  */
10004
- prewarmAllPools(): void;
10181
+ static get worldManager(): WorldManager;
10005
10182
  /**
10006
- * 重置池管理器
10183
+ * 创建Core实例
10184
+ *
10185
+ * 如果实例已存在,则返回现有实例。
10186
+ *
10187
+ * @param config - Core配置,也可以直接传入boolean表示debug模式(向后兼容)
10188
+ * @returns Core实例
10189
+ *
10190
+ * @example
10191
+ * ```typescript
10192
+ * // 方式1:使用配置对象
10193
+ * Core.create({
10194
+ * debug: true,
10195
+ * debugConfig: {
10196
+ * enabled: true,
10197
+ * websocketUrl: 'ws://localhost:9229'
10198
+ * }
10199
+ * });
10200
+ *
10201
+ * // 方式2:简单模式(向后兼容)
10202
+ * Core.create(true); // debug = true
10203
+ * ```
10007
10204
  */
10008
- reset(): void;
10205
+ static create(config?: ICoreConfig | boolean): Core;
10009
10206
  /**
10010
- * 释放资源
10011
- * 实现 IService 接口
10207
+ * 设置当前场景
10208
+ *
10209
+ * @param scene - 要设置的场景
10210
+ * @returns 设置的场景实例
10211
+ *
10212
+ * @example
10213
+ * ```typescript
10214
+ * Core.create({ debug: true });
10215
+ *
10216
+ * // 创建并设置场景
10217
+ * const gameScene = new GameScene();
10218
+ * Core.setScene(gameScene);
10219
+ * ```
10012
10220
  */
10013
- dispose(): void;
10014
- }
10015
-
10016
- /**
10017
- * 实体数据收集器
10018
- */
10019
- declare class EntityDataCollector {
10221
+ static setScene<T extends IScene>(scene: T): T;
10020
10222
  /**
10021
- * 收集实体数据
10022
- * @param scene 场景实例
10223
+ * 获取当前场景
10224
+ *
10225
+ * @returns 当前场景,如果没有场景则返回null
10023
10226
  */
10024
- collectEntityData(scene?: IScene | null): IEntityDebugData;
10227
+ static get scene(): IScene | null;
10025
10228
  /**
10026
- * 获取原始实体列表
10027
- * @param scene 场景实例
10229
+ * 获取ECS流式API
10230
+ *
10231
+ * @returns ECS API实例,如果当前没有场景则返回null
10232
+ *
10233
+ * @example
10234
+ * ```typescript
10235
+ * // 使用流式API创建实体
10236
+ * const player = Core.ecsAPI?.createEntity('Player')
10237
+ * .addComponent(Position, 100, 100)
10238
+ * .addComponent(Velocity, 50, 0);
10239
+ *
10240
+ * // 查询实体
10241
+ * const enemies = Core.ecsAPI?.query(Enemy, Transform);
10242
+ *
10243
+ * // 发射事件
10244
+ * Core.ecsAPI?.emit('game:start', { level: 1 });
10245
+ * ```
10028
10246
  */
10029
- getRawEntityList(scene?: IScene | null): Array<{
10030
- id: number;
10031
- name: string;
10032
- active: boolean;
10033
- enabled: boolean;
10034
- activeInHierarchy: boolean;
10035
- componentCount: number;
10036
- componentTypes: string[];
10037
- parentId: number | null;
10038
- childIds: number[];
10039
- depth: number;
10040
- tag: number;
10041
- updateOrder: number;
10042
- }>;
10247
+ static get ecsAPI(): ECSFluentAPI | null;
10043
10248
  /**
10044
- * 获取实体详细信息
10045
- * @param entityId 实体ID
10046
- * @param scene 场景实例
10249
+ * 延迟加载场景(下一帧切换)
10250
+ *
10251
+ * @param scene - 要加载的场景
10252
+ *
10253
+ * @example
10254
+ * ```typescript
10255
+ * // 延迟切换场景(在下一帧生效)
10256
+ * Core.loadScene(new MenuScene());
10257
+ * ```
10047
10258
  */
10048
- getEntityDetails(entityId: number, scene?: IScene | null): any;
10049
- private getSceneInfo;
10259
+ static loadScene<T extends IScene>(scene: T): void;
10050
10260
  /**
10051
- * 收集实体数据(包含内存信息)
10052
- * @param scene 场景实例
10261
+ * 更新游戏逻辑
10262
+ *
10263
+ * 此方法应该在游戏引擎的更新循环中调用。
10264
+ * 会自动更新全局服务和当前场景。
10265
+ *
10266
+ * @param deltaTime - 外部引擎提供的帧时间间隔(秒)
10267
+ *
10268
+ * @example
10269
+ * ```typescript
10270
+ * // 初始化
10271
+ * Core.create({ debug: true });
10272
+ * Core.setScene(new GameScene());
10273
+ *
10274
+ * // Laya引擎集成
10275
+ * Laya.timer.frameLoop(1, this, () => {
10276
+ * const deltaTime = Laya.timer.delta / 1000;
10277
+ * Core.update(deltaTime); // 自动更新全局服务和场景
10278
+ * });
10279
+ *
10280
+ * // Cocos Creator集成
10281
+ * update(deltaTime: number) {
10282
+ * Core.update(deltaTime); // 自动更新全局服务和场景
10283
+ * }
10284
+ * ```
10053
10285
  */
10054
- collectEntityDataWithMemory(scene?: IScene | null): IEntityDebugData;
10055
- private collectArchetypeData;
10056
- private getArchetypeDistributionFast;
10057
- private getTopEntitiesByComponentsFast;
10058
- private collectArchetypeDataWithMemory;
10059
- private extractArchetypeStatistics;
10060
- private extractArchetypeStatisticsWithMemory;
10061
- private getArchetypeDistributionWithMemory;
10062
- private getTopEntitiesByComponentsWithMemory;
10063
- private getEmptyEntityDebugData;
10064
- private calculateFallbackEntityStats;
10065
- estimateEntityMemoryUsage(entity: any): number;
10066
- calculateObjectSize(obj: any, excludeKeys?: string[]): number;
10067
- private buildEntityHierarchyTree;
10286
+ static update(deltaTime: number): void;
10068
10287
  /**
10069
- * 构建实体层次结构节点
10288
+ * 调度定时器
10289
+ *
10290
+ * 创建一个定时器,在指定时间后执行回调函数。
10291
+ *
10292
+ * @param timeInSeconds - 延迟时间(秒)
10293
+ * @param repeats - 是否重复执行,默认为false
10294
+ * @param context - 回调函数的上下文,默认为null
10295
+ * @param onTime - 定时器触发时的回调函数
10296
+ * @returns 创建的定时器实例
10297
+ * @throws 如果Core实例未创建或onTime回调未提供
10298
+ *
10299
+ * @example
10300
+ * ```typescript
10301
+ * // 一次性定时器
10302
+ * Core.schedule(1.0, false, null, (timer) => {
10303
+ * console.log("1秒后执行一次");
10304
+ * });
10305
+ *
10306
+ * // 重复定时器
10307
+ * Core.schedule(0.5, true, null, (timer) => {
10308
+ * console.log("每0.5秒执行一次");
10309
+ * });
10310
+ * ```
10070
10311
  */
10071
- private buildEntityHierarchyNode;
10312
+ static schedule<TContext = unknown>(timeInSeconds: number, repeats?: boolean, context?: TContext, onTime?: (timer: ITimer<TContext>) => void): Timer<TContext>;
10072
10313
  /**
10073
- * 构建实体详情映射
10314
+ * 启用调试功能
10315
+ *
10316
+ * @param config 调试配置
10074
10317
  */
10075
- private buildEntityDetailsMap;
10318
+ static enableDebug(config: IECSDebugConfig): void;
10076
10319
  /**
10077
- * 构建实体基础信息
10320
+ * 禁用调试功能
10078
10321
  */
10079
- private buildFallbackEntityInfo;
10322
+ static disableDebug(): void;
10080
10323
  /**
10081
- * 提取组件详细信息
10324
+ * 获取调试数据
10325
+ *
10326
+ * @returns 当前调试数据,如果调试未启用则返回null
10082
10327
  */
10083
- extractComponentDetails(components: readonly Component[]): Array<{
10084
- typeName: string;
10085
- properties: Record<string, any>;
10086
- }>;
10328
+ static getDebugData(): unknown;
10087
10329
  /**
10088
- * 获取组件的完整属性信息(仅在需要时调用)
10089
- * @param entityId 实体ID
10090
- * @param componentIndex 组件索引
10091
- * @param scene 场景实例
10330
+ * 检查调试是否启用
10331
+ *
10332
+ * @returns 调试状态
10092
10333
  */
10093
- getComponentProperties(entityId: number, componentIndex: number, scene?: IScene | null): Record<string, any>;
10334
+ static get isDebugEnabled(): boolean;
10094
10335
  /**
10095
- * 格式化属性值
10336
+ * 获取性能监视器实例
10337
+ *
10338
+ * @returns 性能监视器,如果Core未初始化则返回null
10096
10339
  */
10097
- private formatPropertyValue;
10340
+ static get performanceMonitor(): PerformanceMonitor | null;
10098
10341
  /**
10099
- * 格式化对象第一层
10342
+ * 安装插件
10343
+ *
10344
+ * @param plugin - 插件实例
10345
+ * @throws 如果Core实例未创建或插件安装失败
10346
+ *
10347
+ * @example
10348
+ * ```typescript
10349
+ * Core.create({ debug: true });
10350
+ *
10351
+ * // 安装插件
10352
+ * await Core.installPlugin(new MyPlugin());
10353
+ * ```
10100
10354
  */
10101
- private formatObjectFirstLevel;
10355
+ static installPlugin(plugin: IPlugin): Promise<void>;
10102
10356
  /**
10103
- * 创建懒加载占位符
10357
+ * 卸载插件
10358
+ *
10359
+ * @param name - 插件名称
10360
+ * @throws 如果Core实例未创建或插件卸载失败
10361
+ *
10362
+ * @example
10363
+ * ```typescript
10364
+ * await Core.uninstallPlugin('my-plugin');
10365
+ * ```
10104
10366
  */
10105
- private createLazyLoadPlaceholder;
10367
+ static uninstallPlugin(name: string): Promise<void>;
10106
10368
  /**
10107
- * 获取对象摘要信息
10369
+ * 获取插件实例
10370
+ *
10371
+ * @param name - 插件名称
10372
+ * @returns 插件实例,如果未安装则返回undefined
10373
+ *
10374
+ * @example
10375
+ * ```typescript
10376
+ * const myPlugin = Core.getPlugin('my-plugin');
10377
+ * if (myPlugin) {
10378
+ * console.log(myPlugin.version);
10379
+ * }
10380
+ * ```
10108
10381
  */
10109
- private getObjectSummary;
10382
+ static getPlugin(name: string): IPlugin | undefined;
10110
10383
  /**
10111
- * 生成对象ID
10384
+ * 检查插件是否已安装
10385
+ *
10386
+ * @param name - 插件名称
10387
+ * @returns 是否已安装
10388
+ *
10389
+ * @example
10390
+ * ```typescript
10391
+ * if (Core.isPluginInstalled('my-plugin')) {
10392
+ * console.log('Plugin is installed');
10393
+ * }
10394
+ * ```
10112
10395
  */
10113
- private generateObjectId;
10396
+ static isPluginInstalled(name: string): boolean;
10114
10397
  /**
10115
- * 展开懒加载对象(供调试面板调用)
10116
- * @param entityId 实体ID
10117
- * @param componentIndex 组件索引
10118
- * @param propertyPath 属性路径
10119
- * @param scene 场景实例
10398
+ * 初始化核心系统
10399
+ *
10400
+ * 执行核心系统的初始化逻辑。
10120
10401
  */
10121
- expandLazyObject(entityId: number, componentIndex: number, propertyPath: string, scene?: IScene | null): any;
10402
+ protected initialize(): void;
10122
10403
  /**
10123
- * 根据路径获取对象
10404
+ * 内部更新方法
10405
+ *
10406
+ * @param deltaTime - 帧时间间隔(秒)
10124
10407
  */
10125
- private getObjectByPath;
10126
- }
10127
-
10128
- /**
10129
- * 系统数据收集器
10130
- */
10131
- declare class SystemDataCollector {
10408
+ private updateInternal;
10132
10409
  /**
10133
- * 收集系统数据
10134
- * @param performanceMonitor 性能监视器实例
10135
- * @param scene 场景实例
10410
+ * 销毁Core实例
10411
+ *
10412
+ * 清理所有资源,通常在应用程序关闭时调用。
10136
10413
  */
10137
- collectSystemData(performanceMonitor: any, scene?: IScene | null): ISystemDebugData;
10414
+ static destroy(): void;
10138
10415
  }
10139
10416
 
10140
10417
  /**
10141
- * 性能数据收集器
10418
+ * 插件管理器
10419
+ *
10420
+ * 负责插件的注册、安装、卸载和生命周期管理。
10421
+ * 支持依赖检查和异步加载。
10422
+ *
10423
+ * @example
10424
+ * ```typescript
10425
+ * const core = Core.create();
10426
+ * const pluginManager = core.getService(PluginManager);
10427
+ *
10428
+ * // 注册插件
10429
+ * await pluginManager.install(new MyPlugin());
10430
+ *
10431
+ * // 查询插件
10432
+ * const plugin = pluginManager.getPlugin('my-plugin');
10433
+ *
10434
+ * // 卸载插件
10435
+ * await pluginManager.uninstall('my-plugin');
10436
+ * ```
10142
10437
  */
10143
- declare class PerformanceDataCollector {
10144
- private frameTimeHistory;
10145
- private maxHistoryLength;
10146
- private gcCollections;
10147
- private lastMemoryCheck;
10148
- /**
10149
- * 收集性能数据
10150
- */
10151
- collectPerformanceData(performanceMonitor: any): IPerformanceDebugData;
10152
- /**
10153
- * 获取ECS框架整体性能数据
10154
- */
10155
- private getECSPerformanceData;
10156
- /**
10157
- * 获取系统性能数据
10158
- */
10159
- private getSystemPerformance;
10160
- /**
10161
- * 获取内存详情
10162
- */
10163
- private getMemoryDetails;
10438
+ declare class PluginManager implements IService {
10164
10439
  /**
10165
- * 更新GC计数
10440
+ * 已安装的插件
10166
10441
  */
10167
- private updateGCCount;
10168
- }
10169
-
10170
- /**
10171
- * 组件数据收集器
10172
- */
10173
- declare class ComponentDataCollector {
10174
- private static componentSizeCache;
10442
+ private _plugins;
10175
10443
  /**
10176
- * 收集组件数据(轻量版,不计算实际内存大小)
10177
- * @param scene 场景实例
10444
+ * 插件元数据
10178
10445
  */
10179
- collectComponentData(scene?: IScene | null): IComponentDebugData;
10446
+ private _metadata;
10180
10447
  /**
10181
- * 获取组件类型的估算内存大小(基于预设值,不进行实际计算)
10448
+ * Core实例引用
10182
10449
  */
10183
- private getEstimatedComponentSize;
10184
- private calculateQuickObjectSize;
10450
+ private _core;
10185
10451
  /**
10186
- * 为内存快照功能提供的详细内存计算
10187
- * 只在用户主动请求内存快照时调用
10188
- * @param typeName 组件类型名称
10189
- * @param scene 场景实例
10452
+ * 服务容器引用
10190
10453
  */
10191
- calculateDetailedComponentMemory(typeName: string, scene?: IScene | null): number;
10454
+ private _services;
10192
10455
  /**
10193
- * 估算对象内存大小(仅用于内存快照)
10194
- * 优化版本:减少递归深度,提高性能
10456
+ * 初始化插件管理器
10457
+ *
10458
+ * @param core - Core实例
10459
+ * @param services - 服务容器
10195
10460
  */
10196
- private estimateObjectSize;
10197
- static clearCache(): void;
10198
- }
10199
-
10200
- /**
10201
- * 场景数据收集器
10202
- */
10203
- declare class SceneDataCollector {
10204
- private sceneStartTime;
10461
+ initialize(core: Core, services: ServiceContainer): void;
10205
10462
  /**
10206
- * 收集场景数据
10207
- * @param scene 场景实例
10463
+ * 安装插件
10464
+ *
10465
+ * 会自动检查依赖并按正确顺序安装。
10466
+ *
10467
+ * @param plugin - 插件实例
10468
+ * @throws 如果依赖检查失败或安装失败
10208
10469
  */
10209
- collectSceneData(scene?: IScene | null): ISceneDebugData;
10470
+ install(plugin: IPlugin): Promise<void>;
10210
10471
  /**
10211
- * 设置场景开始时间
10472
+ * 卸载插件
10473
+ *
10474
+ * @param name - 插件名称
10475
+ * @throws 如果插件未安装或卸载失败
10212
10476
  */
10213
- setSceneStartTime(time: number): void;
10214
- }
10215
-
10216
- /**
10217
- * WebSocket连接管理器
10218
- */
10219
- declare class WebSocketManager {
10220
- private ws?;
10221
- private isConnected;
10222
- private reconnectAttempts;
10223
- private maxReconnectAttempts;
10224
- private url;
10225
- private autoReconnect;
10226
- private reconnectTimer?;
10227
- private onOpen?;
10228
- private onClose?;
10229
- private onError?;
10230
- private messageHandler?;
10231
- constructor(url: string, autoReconnect?: boolean);
10477
+ uninstall(name: string): Promise<void>;
10232
10478
  /**
10233
- * 设置消息处理回调
10479
+ * 获取插件实例
10480
+ *
10481
+ * @param name - 插件名称
10482
+ * @returns 插件实例,如果未安装则返回undefined
10234
10483
  */
10235
- setMessageHandler(handler: (message: any) => void): void;
10484
+ getPlugin(name: string): IPlugin | undefined;
10236
10485
  /**
10237
- * 连接WebSocket
10486
+ * 获取插件元数据
10487
+ *
10488
+ * @param name - 插件名称
10489
+ * @returns 插件元数据,如果未安装则返回undefined
10238
10490
  */
10239
- connect(): Promise<void>;
10491
+ getMetadata(name: string): IPluginMetadata | undefined;
10240
10492
  /**
10241
- * 断开连接
10493
+ * 获取所有已安装的插件
10494
+ *
10495
+ * @returns 插件列表
10242
10496
  */
10243
- disconnect(): void;
10497
+ getAllPlugins(): IPlugin[];
10244
10498
  /**
10245
- * 发送数据
10499
+ * 获取所有插件元数据
10500
+ *
10501
+ * @returns 元数据列表
10246
10502
  */
10247
- send(data: any): void;
10503
+ getAllMetadata(): IPluginMetadata[];
10248
10504
  /**
10249
- * 获取连接状态
10505
+ * 检查插件是否已安装
10506
+ *
10507
+ * @param name - 插件名称
10508
+ * @returns 是否已安装
10250
10509
  */
10251
- getConnectionStatus(): boolean;
10510
+ isInstalled(name: string): boolean;
10252
10511
  /**
10253
- * 设置最大重连次数
10512
+ * 检查插件依赖
10513
+ *
10514
+ * @param plugin - 插件实例
10515
+ * @throws 如果依赖未满足
10254
10516
  */
10255
- setMaxReconnectAttempts(attempts: number): void;
10517
+ private _checkDependencies;
10256
10518
  /**
10257
- * 计划重连
10519
+ * 检查是否有其他插件依赖指定插件
10520
+ *
10521
+ * @param name - 插件名称
10522
+ * @throws 如果有其他插件依赖此插件
10258
10523
  */
10259
- private scheduleReconnect;
10524
+ private _checkDependents;
10260
10525
  /**
10261
- * 处理接收到的消息
10526
+ * 释放资源
10262
10527
  */
10263
- private handleMessage;
10264
- private handleOpen;
10265
- private handleClose;
10266
- private handleError;
10267
- private handleConnectionFailure;
10528
+ dispose(): void;
10268
10529
  }
10269
10530
 
10270
10531
  /**
10271
- * 调试管理器
10272
- *
10273
- * 整合所有调试数据收集器,负责收集和发送调试数据
10532
+ * ECS 调试插件统计信息
10274
10533
  */
10275
- declare class DebugManager implements IService, IUpdatable {
10276
- private config;
10277
- private webSocketManager;
10278
- private entityCollector;
10279
- private systemCollector;
10280
- private performanceCollector;
10281
- private componentCollector;
10282
- private sceneCollector;
10283
- private sceneManager;
10284
- private performanceMonitor;
10285
- private configService;
10286
- private frameCounter;
10287
- private lastSendTime;
10288
- private sendInterval;
10289
- private isRunning;
10290
- private originalConsole;
10291
- onInitialize(): void;
10292
- /**
10293
- * 启动调试管理器
10294
- */
10295
- start(): void;
10296
- /**
10297
- * 停止调试管理器
10298
- */
10299
- stop(): void;
10300
- /**
10301
- * 拦截 console 日志并转发到编辑器
10302
- */
10303
- private interceptConsole;
10304
- /**
10305
- * 格式化日志消息
10306
- */
10307
- private formatLogMessage;
10308
- /**
10309
- * 安全的 JSON 序列化,支持循环引用和深度限制
10310
- */
10311
- private safeStringify;
10312
- /**
10313
- * 发送日志到编辑器
10314
- */
10315
- private sendLog;
10316
- /**
10317
- * 更新配置
10318
- */
10319
- updateConfig(config: IECSDebugConfig): void;
10320
- update(_deltaTime?: number): void;
10321
- /**
10322
- * 场景变更回调
10323
- */
10324
- onSceneChanged(): void;
10325
- /**
10326
- * 处理来自调试面板的消息
10327
- */
10328
- private handleMessage;
10534
+ interface ECSDebugStats {
10535
+ scenes: SceneDebugInfo[];
10536
+ totalEntities: number;
10537
+ totalSystems: number;
10538
+ timestamp: number;
10539
+ }
10540
+ /**
10541
+ * 场景调试信息
10542
+ */
10543
+ interface SceneDebugInfo {
10544
+ name: string;
10545
+ entityCount: number;
10546
+ systems: SystemDebugInfo[];
10547
+ entities: EntityDebugInfo[];
10548
+ }
10549
+ /**
10550
+ * 系统调试信息
10551
+ */
10552
+ interface SystemDebugInfo {
10553
+ name: string;
10554
+ enabled: boolean;
10555
+ updateOrder: number;
10556
+ entityCount: number;
10557
+ performance?: {
10558
+ avgExecutionTime: number;
10559
+ maxExecutionTime: number;
10560
+ totalCalls: number;
10561
+ };
10562
+ }
10563
+ /**
10564
+ * 实体调试信息
10565
+ */
10566
+ interface EntityDebugInfo {
10567
+ id: number;
10568
+ name: string;
10569
+ enabled: boolean;
10570
+ tag: number;
10571
+ componentCount: number;
10572
+ components: ComponentDebugInfo[];
10573
+ }
10574
+ /**
10575
+ * 组件调试信息
10576
+ */
10577
+ interface ComponentDebugInfo {
10578
+ type: string;
10579
+ data: any;
10580
+ }
10581
+ /**
10582
+ * ECS 调试插件
10583
+ *
10584
+ * 提供运行时调试功能:
10585
+ * - 实时查看实体和组件信息
10586
+ * - System 执行统计
10587
+ * - 性能监控
10588
+ * - 实体查询
10589
+ *
10590
+ * @example
10591
+ * ```typescript
10592
+ * const core = Core.create();
10593
+ * const debugPlugin = new DebugPlugin({ autoStart: true, updateInterval: 1000 });
10594
+ * await core.pluginManager.install(debugPlugin);
10595
+ *
10596
+ * // 获取调试信息
10597
+ * const stats = debugPlugin.getStats();
10598
+ * console.log('Total entities:', stats.totalEntities);
10599
+ *
10600
+ * // 查询实体
10601
+ * const entities = debugPlugin.queryEntities({ tag: 1 });
10602
+ * ```
10603
+ */
10604
+ declare class DebugPlugin implements IPlugin, IService {
10605
+ readonly name = "@esengine/debug-plugin";
10606
+ readonly version = "1.0.0";
10607
+ private worldManager;
10608
+ private updateInterval;
10609
+ private updateTimer;
10610
+ private autoStart;
10329
10611
  /**
10330
- * 处理展开懒加载对象请求
10612
+ * 创建调试插件实例
10613
+ *
10614
+ * @param options - 配置选项
10331
10615
  */
10332
- private handleExpandLazyObjectRequest;
10616
+ constructor(options?: {
10617
+ autoStart?: boolean;
10618
+ updateInterval?: number;
10619
+ });
10333
10620
  /**
10334
- * 处理获取组件属性请求
10621
+ * 安装插件
10335
10622
  */
10336
- private handleGetComponentPropertiesRequest;
10623
+ install(_core: Core, services: ServiceContainer): Promise<void>;
10337
10624
  /**
10338
- * 处理获取原始实体列表请求
10625
+ * 卸载插件
10339
10626
  */
10340
- private handleGetRawEntityListRequest;
10627
+ uninstall(): Promise<void>;
10341
10628
  /**
10342
- * 处理获取实体详情请求
10629
+ * 实现 IService 接口
10343
10630
  */
10344
- private handleGetEntityDetailsRequest;
10631
+ dispose(): void;
10345
10632
  /**
10346
- * 处理内存快照请求
10633
+ * 启动调试监控
10347
10634
  */
10348
- private handleMemorySnapshotRequest;
10635
+ start(): void;
10349
10636
  /**
10350
- * 捕获内存快照
10637
+ * 停止调试监控
10351
10638
  */
10352
- private captureMemorySnapshot;
10639
+ stop(): void;
10353
10640
  /**
10354
- * 收集基础内存信息
10641
+ * 获取当前 ECS 统计信息
10355
10642
  */
10356
- private collectBaseMemoryInfo;
10643
+ getStats(): ECSDebugStats;
10357
10644
  /**
10358
- * 收集组件内存统计(仅用于内存快照)
10645
+ * 获取场景调试信息
10359
10646
  */
10360
- private collectComponentMemoryStats;
10361
- private collectSystemMemoryStats;
10362
- private calculateQuickSystemSize;
10647
+ getSceneInfo(scene: IScene): SceneDebugInfo;
10363
10648
  /**
10364
- * 收集对象池内存统计
10649
+ * 获取系统调试信息
10365
10650
  */
10366
- private collectPoolMemoryStats;
10651
+ private getSystemInfo;
10367
10652
  /**
10368
- * 收集性能统计信息
10653
+ * 获取实体调试信息
10369
10654
  */
10370
- private collectPerformanceStats;
10655
+ getEntityInfo(entity: Entity): EntityDebugInfo;
10371
10656
  /**
10372
- * 获取调试数据
10657
+ * 获取组件调试信息
10373
10658
  */
10374
- getDebugData(): IECSDebugData;
10659
+ private getComponentInfo;
10375
10660
  /**
10376
- * 连接WebSocket
10661
+ * 查询实体
10662
+ *
10663
+ * @param filter - 查询过滤器
10377
10664
  */
10378
- private connectWebSocket;
10665
+ queryEntities(filter: {
10666
+ sceneName?: string;
10667
+ tag?: number;
10668
+ name?: string;
10669
+ hasComponent?: string;
10670
+ }): EntityDebugInfo[];
10379
10671
  /**
10380
- * 发送调试数据
10672
+ * 打印统计信息到日志
10381
10673
  */
10382
- private sendDebugData;
10674
+ private logStats;
10383
10675
  /**
10384
- * 释放资源
10676
+ * 导出调试数据为 JSON
10385
10677
  */
10386
- dispose(): void;
10678
+ exportJSON(): string;
10387
10679
  }
10388
10680
 
10389
10681
  /**
10390
- * 调试配置服务
10682
+ * 依赖注入装饰器
10391
10683
  *
10392
- * 管理调试系统的配置信息
10684
+ * 提供 @Injectable、@InjectProperty 和 @Updatable 装饰器,用于标记可注入的类和依赖注入点
10393
10685
  */
10394
- declare class DebugConfigService implements IService {
10395
- private _config;
10396
- constructor();
10397
- setConfig(config: IECSDebugConfig): void;
10398
- getConfig(): IECSDebugConfig;
10399
- isEnabled(): boolean;
10400
- dispose(): void;
10401
- }
10402
10686
 
10403
10687
  /**
10404
- * 插件状态
10688
+ * 依赖注入元数据存储
10405
10689
  */
10406
- declare enum PluginState {
10690
+ type Constructor = abstract new (...args: unknown[]) => unknown;
10691
+ /**
10692
+ * 可注入元数据接口
10693
+ */
10694
+ interface InjectableMetadata {
10407
10695
  /**
10408
- * 未安装
10696
+ * 是否可注入
10409
10697
  */
10410
- NotInstalled = "not_installed",
10698
+ injectable: boolean;
10411
10699
  /**
10412
- * 已安装
10700
+ * 依赖列表
10413
10701
  */
10414
- Installed = "installed",
10702
+ dependencies: Array<ServiceType<IService> | string | symbol>;
10415
10703
  /**
10416
- * 安装失败
10704
+ * 属性注入映射
10705
+ * key: 属性名, value: 服务类型
10417
10706
  */
10418
- Failed = "failed"
10707
+ properties?: Map<string | symbol, ServiceType<IService>>;
10419
10708
  }
10420
10709
  /**
10421
- * 插件接口
10710
+ * 可更新元数据接口
10711
+ */
10712
+ interface UpdatableMetadata {
10713
+ /**
10714
+ * 是否可更新
10715
+ */
10716
+ updatable: boolean;
10717
+ /**
10718
+ * 更新优先级(数值越小越先执行,默认0)
10719
+ */
10720
+ priority: number;
10721
+ }
10722
+ /**
10723
+ * @Injectable() 装饰器
10422
10724
  *
10423
- * 所有插件都必须实现此接口。
10424
- * 插件提供了一种扩展框架功能的标准方式。
10725
+ * 标记类为可注入的服务,使其可以通过ServiceContainer进行依赖注入
10425
10726
  *
10426
10727
  * @example
10427
10728
  * ```typescript
10428
- * class MyPlugin implements IPlugin {
10429
- * readonly name = 'my-plugin';
10430
- * readonly version = '1.0.0';
10431
- * readonly dependencies = ['other-plugin'];
10729
+ * @Injectable()
10730
+ * class TimeService implements IService {
10731
+ * constructor() {}
10732
+ * dispose() {}
10733
+ * }
10432
10734
  *
10433
- * async install(core: Core, services: ServiceContainer) {
10434
- * // 注册服务
10435
- * services.registerSingleton(MyService);
10735
+ * @Injectable()
10736
+ * class PhysicsSystem extends EntitySystem {
10737
+ * @InjectProperty(TimeService)
10738
+ * private timeService!: TimeService;
10436
10739
  *
10437
- * // 添加系统
10438
- * const world = core.getWorld();
10439
- * if (world) {
10440
- * world.addSystem(new MySystem());
10441
- * }
10740
+ * constructor() {
10741
+ * super(Matcher.empty());
10442
10742
  * }
10743
+ * }
10744
+ * ```
10745
+ */
10746
+ declare function Injectable(): ClassDecorator;
10747
+ /**
10748
+ * @Updatable() 装饰器
10443
10749
  *
10444
- * async uninstall() {
10445
- * // 清理资源
10750
+ * 标记服务类为可更新的,使其在每帧自动被ServiceContainer调用update方法。
10751
+ * 使用此装饰器的类必须实现IUpdatable接口(包含update方法)。
10752
+ *
10753
+ * @param priority - 更新优先级(数值越小越先执行,默认0)
10754
+ * @throws 如果类没有实现update方法,将在运行时抛出错误
10755
+ *
10756
+ * @example
10757
+ * ```typescript
10758
+ * @Injectable()
10759
+ * @Updatable()
10760
+ * class TimerManager implements IService, IUpdatable {
10761
+ * update(deltaTime?: number) {
10762
+ * // 每帧更新逻辑
10446
10763
  * }
10764
+ * dispose() {}
10765
+ * }
10766
+ *
10767
+ * // 指定优先级
10768
+ * @Injectable()
10769
+ * @Updatable(10)
10770
+ * class PhysicsManager implements IService, IUpdatable {
10771
+ * update() { }
10772
+ * dispose() {}
10447
10773
  * }
10448
10774
  * ```
10449
10775
  */
10450
- interface IPlugin {
10776
+ declare function Updatable(priority?: number): ClassDecorator;
10777
+ /**
10778
+ * @InjectProperty() 装饰器
10779
+ *
10780
+ * 通过属性装饰器注入依赖
10781
+ *
10782
+ * 注入时机:在构造函数执行后、onInitialize() 调用前完成
10783
+ *
10784
+ * @param serviceType 服务类型
10785
+ *
10786
+ * @example
10787
+ * ```typescript
10788
+ * @Injectable()
10789
+ * class PhysicsSystem extends EntitySystem {
10790
+ * @InjectProperty(TimeService)
10791
+ * private timeService!: TimeService;
10792
+ *
10793
+ * @InjectProperty(CollisionService)
10794
+ * private collision!: CollisionService;
10795
+ *
10796
+ * constructor() {
10797
+ * super(Matcher.empty());
10798
+ * }
10799
+ *
10800
+ * public onInitialize(): void {
10801
+ * // 此时属性已注入完成,可以安全使用
10802
+ * console.log(this.timeService.getDeltaTime());
10803
+ * }
10804
+ * }
10805
+ * ```
10806
+ */
10807
+ declare function InjectProperty(serviceType: ServiceType<IService>): PropertyDecorator;
10808
+ /**
10809
+ * 获取属性注入元数据
10810
+ *
10811
+ * @param target 目标类
10812
+ * @returns 属性名到服务类型的映射
10813
+ */
10814
+ declare function getPropertyInjectMetadata(target: Constructor): Map<string | symbol, ServiceType<IService>>;
10815
+ /**
10816
+ * 创建实例并自动注入依赖
10817
+ *
10818
+ * @param constructor 构造函数
10819
+ * @param container 服务容器
10820
+ * @returns 创建的实例
10821
+ *
10822
+ * @example
10823
+ * ```typescript
10824
+ * const instance = createInstance(MySystem, container);
10825
+ * ```
10826
+ */
10827
+ declare function createInstance<T>(constructor: new (...args: any[]) => T, container: ServiceContainer): T;
10828
+ /**
10829
+ * 为实例注入属性依赖
10830
+ *
10831
+ * @param instance 目标实例
10832
+ * @param container 服务容器
10833
+ */
10834
+ declare function injectProperties<T extends object>(instance: T, container: ServiceContainer): void;
10835
+ /**
10836
+ * 检查类是否标记为可更新
10837
+ *
10838
+ * @param target 目标类
10839
+ * @returns 是否可更新
10840
+ */
10841
+ declare function isUpdatable(target: Constructor): boolean;
10842
+ /**
10843
+ * 获取类的可更新元数据
10844
+ *
10845
+ * @param target 目标类
10846
+ * @returns 可更新元数据
10847
+ */
10848
+ declare function getUpdatableMetadata(target: Constructor): UpdatableMetadata | undefined;
10849
+ /**
10850
+ * 注册可注入的服务到容器
10851
+ *
10852
+ * 自动检测@Injectable装饰器并注册服务
10853
+ *
10854
+ * @param container 服务容器
10855
+ * @param serviceType 服务类型
10856
+ * @param singleton 是否注册为单例(默认true)
10857
+ *
10858
+ * @example
10859
+ * ```typescript
10860
+ * @Injectable()
10861
+ * class MyService implements IService {
10862
+ * dispose() {}
10863
+ * }
10864
+ *
10865
+ * // 自动注册
10866
+ * registerInjectable(Core.services, MyService);
10867
+ * ```
10868
+ */
10869
+ declare function registerInjectable<T extends IService>(container: ServiceContainer, serviceType: ServiceType<T>, singleton?: boolean): void;
10870
+
10871
+ /**
10872
+ * 用于包装事件的一个小类
10873
+ */
10874
+ declare class FuncPack<TContext = unknown> {
10875
+ /** 函数 */
10876
+ func: Function;
10877
+ /** 上下文 */
10878
+ context: TContext;
10879
+ constructor(func: Function, context: TContext);
10880
+ }
10881
+ /**
10882
+ * 用于事件管理
10883
+ */
10884
+ declare class Emitter<T, TContext = unknown> {
10885
+ private _messageTable;
10886
+ constructor();
10451
10887
  /**
10452
- * 插件唯一名称
10453
- *
10454
- * 用于依赖解析和插件管理。
10888
+ * 开始监听项
10889
+ * @param eventType 监听类型
10890
+ * @param handler 监听函数
10891
+ * @param context 监听上下文
10455
10892
  */
10456
- readonly name: string;
10893
+ addObserver(eventType: T, handler: Function, context: TContext): void;
10457
10894
  /**
10458
- * 插件版本
10459
- *
10460
- * 遵循语义化版本规范 (semver)。
10895
+ * 移除监听项
10896
+ * @param eventType 事件类型
10897
+ * @param handler 事件函数
10461
10898
  */
10462
- readonly version: string;
10899
+ removeObserver(eventType: T, handler: Function): void;
10463
10900
  /**
10464
- * 依赖的其他插件名称列表
10465
- *
10466
- * 这些插件必须在当前插件之前安装。
10901
+ * 触发该事件
10902
+ * @param eventType 事件类型
10903
+ * @param data 事件数据
10467
10904
  */
10468
- readonly dependencies?: readonly string[];
10905
+ emit<TData = unknown>(eventType: T, ...data: TData[]): void;
10469
10906
  /**
10470
- * 安装插件
10471
- *
10472
- * 在此方法中初始化插件,注册服务、系统等。
10473
- * 可以是同步或异步的。
10474
- *
10475
- * @param core - Core实例,用于访问World等
10476
- * @param services - 服务容器,用于注册服务
10907
+ * 判断是否存在该类型的观察者
10908
+ * @param eventType 事件类型
10909
+ * @param handler 事件函数
10477
10910
  */
10478
- install(core: Core, services: ServiceContainer): void | Promise<void>;
10911
+ hasObserver(eventType: T, handler: Function): boolean;
10479
10912
  /**
10480
- * 卸载插件
10481
- *
10482
- * 清理插件占用的资源。
10483
- * 可以是同步或异步的。
10913
+ * 移除指定事件类型的所有监听器
10914
+ * @param eventType 事件类型
10484
10915
  */
10485
- uninstall(): void | Promise<void>;
10916
+ removeAllObservers(eventType?: T): void;
10917
+ /**
10918
+ * 释放所有资源,清理所有监听器
10919
+ */
10920
+ dispose(): void;
10921
+ /**
10922
+ * 获取事件类型数量
10923
+ */
10924
+ getEventTypeCount(): number;
10925
+ /**
10926
+ * 获取指定事件类型的监听器数量
10927
+ * @param eventType 事件类型
10928
+ */
10929
+ getObserverCount(eventType: T): number;
10486
10930
  }
10931
+
10487
10932
  /**
10488
- * 插件元数据
10933
+ * 全局管理器的基类。所有全局管理器都应该从此类继承。
10489
10934
  */
10490
- interface IPluginMetadata {
10935
+ declare class GlobalManager {
10936
+ private _enabled;
10491
10937
  /**
10492
- * 插件名称
10938
+ * 获取或设置管理器是否启用
10493
10939
  */
10494
- name: string;
10940
+ get enabled(): boolean;
10941
+ set enabled(value: boolean);
10495
10942
  /**
10496
- * 插件版本
10943
+ * 设置管理器是否启用
10944
+ * @param isEnabled 如果为true,则启用管理器;否则禁用管理器
10497
10945
  */
10498
- version: string;
10946
+ setEnabled(isEnabled: boolean): void;
10499
10947
  /**
10500
- * 插件状态
10948
+ * 在启用管理器时调用的回调方法
10501
10949
  */
10502
- state: PluginState;
10950
+ protected onEnabled(): void;
10503
10951
  /**
10504
- * 安装时间戳
10952
+ * 在禁用管理器时调用的回调方法
10505
10953
  */
10506
- installedAt?: number;
10954
+ protected onDisabled(): void;
10507
10955
  /**
10508
- * 错误信息(如果安装失败)
10956
+ * 更新管理器状态的方法
10509
10957
  */
10510
- error?: string;
10958
+ update(): void;
10511
10959
  }
10512
10960
 
10513
10961
  /**
10514
- * 游戏引擎核心类
10515
- *
10516
- * 职责:
10517
- * - 提供全局服务(Timer、Performance、Pool等)
10518
- * - 管理场景生命周期(内置SceneManager)
10519
- * - 管理全局管理器的生命周期
10520
- * - 提供统一的游戏循环更新入口
10521
- *
10522
- * @example
10523
- * ```typescript
10524
- * // 初始化并设置场景
10525
- * Core.create({ debug: true });
10526
- * Core.setScene(new GameScene());
10962
+ * 定时器管理器
10527
10963
  *
10528
- * // 游戏循环(自动更新全局服务和场景)
10529
- * function gameLoop(deltaTime: number) {
10530
- * Core.update(deltaTime);
10964
+ * 允许动作的延迟和重复执行
10965
+ */
10966
+ declare class TimerManager implements IService, IUpdatable {
10967
+ private _timers;
10968
+ update(): void;
10969
+ /**
10970
+ * 调度一个一次性或重复的计时器,该计时器将调用已传递的动作
10971
+ * @param timeInSeconds
10972
+ * @param repeats
10973
+ * @param context
10974
+ * @param onTime
10975
+ */
10976
+ schedule<TContext = unknown>(timeInSeconds: number, repeats: boolean, context: TContext, onTime: (timer: ITimer<TContext>) => void): Timer<TContext>;
10977
+ /**
10978
+ * 释放资源
10979
+ */
10980
+ dispose(): void;
10981
+ }
10982
+
10983
+ /**
10984
+ * Entity类型安全工具函数
10985
+ *
10986
+ * 提供类型安全的组件操作工具函数,无需修改Entity类
10987
+ */
10988
+
10989
+ /**
10990
+ * 获取组件,如果不存在则抛出错误
10991
+ *
10992
+ * @param entity - 实体实例
10993
+ * @param componentType - 组件类型构造函数
10994
+ * @returns 组件实例(保证非空)
10995
+ * @throws {Error} 如果组件不存在
10996
+ *
10997
+ * @example
10998
+ * ```typescript
10999
+ * const position = requireComponent(entity, Position);
11000
+ * position.x += 10;
11001
+ * ```
11002
+ */
11003
+ declare function requireComponent<T extends ComponentConstructor>(entity: Entity, componentType: T): ComponentInstance<T>;
11004
+ /**
11005
+ * 尝试获取组件
11006
+ *
11007
+ * @param entity - 实体实例
11008
+ * @param componentType - 组件类型构造函数
11009
+ * @returns 组件实例或undefined
11010
+ *
11011
+ * @example
11012
+ * ```typescript
11013
+ * const health = tryGetComponent(entity, Health);
11014
+ * if (health) {
11015
+ * health.value -= 10;
10531
11016
  * }
11017
+ * ```
11018
+ */
11019
+ declare function tryGetComponent<T extends ComponentConstructor>(entity: Entity, componentType: T): ComponentInstance<T> | undefined;
11020
+ /**
11021
+ * 批量获取组件
10532
11022
  *
10533
- * // 使用定时器
10534
- * Core.schedule(1.0, false, null, (timer) => {
10535
- * console.log("1秒后执行");
11023
+ * @param entity - 实体实例
11024
+ * @param types - 组件类型构造函数数组
11025
+ * @returns 组件实例元组,每个元素可能为null
11026
+ *
11027
+ * @example
11028
+ * ```typescript
11029
+ * const [pos, vel, health] = getComponents(entity, Position, Velocity, Health);
11030
+ * if (pos && vel && health) {
11031
+ * pos.x += vel.dx;
11032
+ * }
11033
+ * ```
11034
+ */
11035
+ declare function getComponents<T extends readonly ComponentConstructor[]>(entity: Entity, ...types: T): {
11036
+ [K in keyof T]: ComponentInstance<T[K]> | null;
11037
+ };
11038
+ /**
11039
+ * 检查实体是否拥有所有指定的组件
11040
+ *
11041
+ * @param entity - 实体实例
11042
+ * @param types - 组件类型构造函数数组
11043
+ * @returns 如果拥有所有组件返回true,否则返回false
11044
+ *
11045
+ * @example
11046
+ * ```typescript
11047
+ * if (hasComponents(entity, Position, Velocity)) {
11048
+ * const pos = entity.getComponent(Position)!;
11049
+ * const vel = entity.getComponent(Velocity)!;
11050
+ * }
11051
+ * ```
11052
+ */
11053
+ declare function hasComponents(entity: Entity, ...types: ComponentConstructor[]): boolean;
11054
+ /**
11055
+ * 检查实体是否拥有至少一个指定的组件
11056
+ *
11057
+ * @param entity - 实体实例
11058
+ * @param types - 组件类型构造函数数组
11059
+ * @returns 如果拥有任意一个组件返回true,否则返回false
11060
+ */
11061
+ declare function hasAnyComponent(entity: Entity, ...types: ComponentConstructor[]): boolean;
11062
+ /**
11063
+ * 添加组件并立即配置
11064
+ *
11065
+ * @param entity - 实体实例
11066
+ * @param component - 组件实例
11067
+ * @param configure - 配置回调函数
11068
+ * @returns 实体实例(支持链式调用)
11069
+ *
11070
+ * @example
11071
+ * ```typescript
11072
+ * addAndConfigure(entity, new Health(), health => {
11073
+ * health.maxValue = 100;
11074
+ * health.value = 50;
10536
11075
  * });
11076
+ * ```
11077
+ */
11078
+ declare function addAndConfigure<T extends Component>(entity: Entity, component: T, configure: (component: T) => void): Entity;
11079
+ /**
11080
+ * 获取或添加组件
10537
11081
  *
10538
- * // 切换场景
10539
- * Core.loadScene(new MenuScene()); // 延迟切换
10540
- * Core.setScene(new GameScene()); // 立即切换
11082
+ * 如果组件已存在则返回现有组件,否则通过工厂函数创建并添加
10541
11083
  *
10542
- * // 获取当前场景
10543
- * const currentScene = Core.scene;
11084
+ * @param entity - 实体实例
11085
+ * @param componentType - 组件类型构造函数
11086
+ * @param factory - 组件工厂函数(仅在组件不存在时调用)
11087
+ * @returns 组件实例
11088
+ *
11089
+ * @example
11090
+ * ```typescript
11091
+ * const health = getOrAddComponent(entity, Health, () => new Health(100));
10544
11092
  * ```
10545
11093
  */
10546
- declare class Core {
11094
+ declare function getOrAddComponent<T extends ComponentConstructor>(entity: Entity, componentType: T, factory: () => ComponentInstance<T>): ComponentInstance<T>;
11095
+ /**
11096
+ * 更新组件的部分字段
11097
+ *
11098
+ * @param entity - 实体实例
11099
+ * @param componentType - 组件类型构造函数
11100
+ * @param data - 要更新的部分数据
11101
+ * @returns 如果更新成功返回true,组件不存在返回false
11102
+ *
11103
+ * @example
11104
+ * ```typescript
11105
+ * updateComponent(entity, Position, { x: 100 });
11106
+ * ```
11107
+ */
11108
+ declare function updateComponent<T extends ComponentConstructor>(entity: Entity, componentType: T, data: Partial<ComponentInstance<T>>): boolean;
11109
+ /**
11110
+ * 类型安全的实体构建器
11111
+ *
11112
+ * @example
11113
+ * ```typescript
11114
+ * const player = buildEntity(scene.createEntity("Player"))
11115
+ * .with(new Position(100, 100))
11116
+ * .with(new Velocity(0, 0))
11117
+ * .withTag(1)
11118
+ * .build();
11119
+ * ```
11120
+ */
11121
+ declare class TypedEntityBuilder {
11122
+ private _entity;
11123
+ constructor(entity: Entity);
10547
11124
  /**
10548
- * 游戏暂停状态
10549
- *
10550
- * 当设置为true时,游戏循环将暂停执行。
11125
+ * 添加组件
10551
11126
  */
10552
- static paused: boolean;
11127
+ with<T extends Component>(component: T): this;
10553
11128
  /**
10554
- * 全局核心实例
10555
- *
10556
- * 可能为null表示Core尚未初始化或已被销毁
11129
+ * 添加并配置组件
10557
11130
  */
10558
- private static _instance;
11131
+ withConfigured<T extends Component>(component: T, configure: (component: T) => void): this;
10559
11132
  /**
10560
- * Core专用日志器
11133
+ * 设置标签
10561
11134
  */
10562
- private static _logger;
11135
+ withTag(tag: number): this;
10563
11136
  /**
10564
- * 实体系统启用状态
10565
- *
10566
- * 控制是否启用ECS实体系统功能。
11137
+ * 设置名称
10567
11138
  */
10568
- static entitySystemsEnabled: boolean;
11139
+ withName(name: string): this;
10569
11140
  /**
10570
- * 调试模式标志
10571
- *
10572
- * 在调试模式下会启用额外的性能监控和错误检查。
11141
+ * 设置激活状态
10573
11142
  */
10574
- readonly debug: boolean;
11143
+ withActive(active: boolean): this;
10575
11144
  /**
10576
- * 服务容器
10577
- *
10578
- * 管理所有服务的注册、解析和生命周期。
11145
+ * 设置启用状态
10579
11146
  */
10580
- private _serviceContainer;
11147
+ withEnabled(enabled: boolean): this;
10581
11148
  /**
10582
- * 定时器管理器
10583
- *
10584
- * 负责管理所有的游戏定时器。
11149
+ * 设置更新顺序
10585
11150
  */
10586
- _timerManager: TimerManager;
11151
+ withUpdateOrder(order: number): this;
10587
11152
  /**
10588
- * 性能监控器
10589
- *
10590
- * 监控游戏性能并提供优化建议。
11153
+ * 添加子实体
10591
11154
  */
10592
- _performanceMonitor: PerformanceMonitor;
11155
+ withChild(child: Entity): this;
10593
11156
  /**
10594
- * 对象池管理器
10595
- *
10596
- * 管理所有对象池的生命周期。
11157
+ * 完成构建
10597
11158
  */
10598
- _poolManager: PoolManager;
11159
+ build(): Entity;
10599
11160
  /**
10600
- * 调试管理器
10601
- *
10602
- * 负责收集和发送调试数据。
11161
+ * 获取正在构建的实体
10603
11162
  */
10604
- _debugManager?: DebugManager;
11163
+ get entity(): Entity;
11164
+ }
11165
+ /**
11166
+ * 创建类型安全的实体构建器
11167
+ *
11168
+ * @param entity - 要包装的实体
11169
+ * @returns 实体构建器
11170
+ */
11171
+ declare function buildEntity(entity: Entity): TypedEntityBuilder;
11172
+
11173
+ /**
11174
+ * 类型工具类
11175
+ * 提供类型相关的实用方法
11176
+ */
11177
+ declare class TypeUtils {
10605
11178
  /**
10606
- * 场景管理器
10607
- *
10608
- * 管理当前场景的生命周期。
11179
+ * 获取对象的类型
11180
+ * @param obj 对象
11181
+ * @returns 对象的构造函数
10609
11182
  */
10610
- private _sceneManager;
11183
+ static getType(obj: any): any;
11184
+ }
11185
+
11186
+ /**
11187
+ * 数字扩展工具类
11188
+ * 提供数字转换的实用方法
11189
+ */
11190
+ declare class NumberExtension {
10611
11191
  /**
10612
- * World管理器
10613
- *
10614
- * 管理多个独立的World实例(可选)。
11192
+ * 将值转换为数字
11193
+ * @param value 要转换的值
11194
+ * @returns 转换后的数字,如果值为undefined则返回0
10615
11195
  */
10616
- private _worldManager;
11196
+ static toNumber(value: unknown): number;
11197
+ }
11198
+
11199
+ /**
11200
+ * 可池化对象接口
11201
+ */
11202
+ interface IPoolable {
10617
11203
  /**
10618
- * 插件管理器
10619
- *
10620
- * 管理所有插件的生命周期。
11204
+ * 重置对象状态,准备重用
10621
11205
  */
10622
- private _pluginManager;
10623
- /**
10624
- * Core配置
10625
- */
10626
- private _config;
11206
+ reset(): void;
11207
+ }
11208
+ /**
11209
+ * 对象池统计信息
11210
+ */
11211
+ interface PoolStats {
11212
+ /** 池中对象数量 */
11213
+ size: number;
11214
+ /** 池的最大大小 */
11215
+ maxSize: number;
11216
+ /** 总共创建的对象数量 */
11217
+ totalCreated: number;
11218
+ /** 总共获取的次数 */
11219
+ totalObtained: number;
11220
+ /** 总共释放的次数 */
11221
+ totalReleased: number;
11222
+ /** 命中率(从池中获取的比例) */
11223
+ hitRate: number;
11224
+ /** 内存使用估算(字节) */
11225
+ estimatedMemoryUsage: number;
11226
+ }
11227
+
11228
+ /**
11229
+ * 高性能通用对象池
11230
+ * 支持任意类型的对象池化,包含详细的统计信息
11231
+ */
11232
+ declare class Pool<T extends IPoolable> {
11233
+ private static _pools;
11234
+ private _objects;
11235
+ private _createFn;
11236
+ private _maxSize;
11237
+ private _stats;
11238
+ private _objectSize;
10627
11239
  /**
10628
- * 创建核心实例
10629
- *
10630
- * @param config - Core配置对象
11240
+ * 构造函数
11241
+ * @param createFn 创建对象的函数
11242
+ * @param maxSize 池的最大大小,默认100
11243
+ * @param estimatedObjectSize 估算的单个对象大小(字节),默认1024
10631
11244
  */
10632
- private constructor();
11245
+ constructor(createFn: () => T, maxSize?: number, estimatedObjectSize?: number);
10633
11246
  /**
10634
- * 获取核心实例
10635
- *
10636
- * @returns 全局核心实例
11247
+ * 获取指定类型的对象池
11248
+ * @param type 对象类型
11249
+ * @param maxSize 池的最大大小
11250
+ * @param estimatedObjectSize 估算的单个对象大小
11251
+ * @returns 对象池实例
10637
11252
  */
10638
- static get Instance(): Core | null;
11253
+ static getPool<T extends IPoolable>(type: new (...args: unknown[]) => T, maxSize?: number, estimatedObjectSize?: number): Pool<T>;
10639
11254
  /**
10640
- * 获取服务容器
10641
- *
10642
- * 用于注册和解析自定义服务。
10643
- *
10644
- * @returns 服务容器实例
10645
- * @throws 如果Core实例未创建
10646
- *
10647
- * @example
10648
- * ```typescript
10649
- * // 注册自定义服务
10650
- * Core.services.registerSingleton(MyService);
10651
- *
10652
- * // 解析服务
10653
- * const myService = Core.services.resolve(MyService);
10654
- * ```
11255
+ * 从池中获取对象
11256
+ * @returns 对象实例
10655
11257
  */
10656
- static get services(): ServiceContainer;
11258
+ obtain(): T;
10657
11259
  /**
10658
- * 获取World管理器
10659
- *
10660
- * 用于管理多个独立的World实例(高级用户)。
10661
- *
10662
- * @returns WorldManager实例
10663
- * @throws 如果Core实例未创建
10664
- *
10665
- * @example
10666
- * ```typescript
10667
- * // 创建多个游戏房间
10668
- * const wm = Core.worldManager;
10669
- * const room1 = wm.createWorld('room_001');
10670
- * room1.createScene('game', new GameScene());
10671
- * room1.start();
10672
- * ```
11260
+ * 释放对象回池中
11261
+ * @param obj 要释放的对象
10673
11262
  */
10674
- static get worldManager(): WorldManager;
11263
+ release(obj: T): void;
10675
11264
  /**
10676
- * 创建Core实例
10677
- *
10678
- * 如果实例已存在,则返回现有实例。
10679
- *
10680
- * @param config - Core配置,也可以直接传入boolean表示debug模式(向后兼容)
10681
- * @returns Core实例
10682
- *
10683
- * @example
10684
- * ```typescript
10685
- * // 方式1:使用配置对象
10686
- * Core.create({
10687
- * debug: true,
10688
- * enableEntitySystems: true,
10689
- * debugConfig: {
10690
- * enabled: true,
10691
- * websocketUrl: 'ws://localhost:9229'
10692
- * }
10693
- * });
10694
- *
10695
- * // 方式2:简单模式(向后兼容)
10696
- * Core.create(true); // debug = true
10697
- * ```
11265
+ * 获取池统计信息
11266
+ * @returns 统计信息对象
10698
11267
  */
10699
- static create(config?: ICoreConfig | boolean): Core;
11268
+ getStats(): Readonly<PoolStats>;
10700
11269
  /**
10701
- * 设置当前场景
10702
- *
10703
- * @param scene - 要设置的场景
10704
- * @returns 设置的场景实例
10705
- *
10706
- * @example
10707
- * ```typescript
10708
- * Core.create({ debug: true });
10709
- *
10710
- * // 创建并设置场景
10711
- * const gameScene = new GameScene();
10712
- * Core.setScene(gameScene);
10713
- * ```
11270
+ * 清空池
10714
11271
  */
10715
- static setScene<T extends IScene>(scene: T): T;
11272
+ clear(): void;
10716
11273
  /**
10717
- * 获取当前场景
10718
- *
10719
- * @returns 当前场景,如果没有场景则返回null
11274
+ * 压缩池(移除多余的对象)
11275
+ * @param targetSize 目标大小,默认为当前大小的一半
10720
11276
  */
10721
- static get scene(): IScene | null;
11277
+ compact(targetSize?: number): void;
10722
11278
  /**
10723
- * 获取ECS流式API
10724
- *
10725
- * @returns ECS API实例,如果当前没有场景则返回null
10726
- *
10727
- * @example
10728
- * ```typescript
10729
- * // 使用流式API创建实体
10730
- * const player = Core.ecsAPI?.createEntity('Player')
10731
- * .addComponent(Position, 100, 100)
10732
- * .addComponent(Velocity, 50, 0);
10733
- *
10734
- * // 查询实体
10735
- * const enemies = Core.ecsAPI?.query(Enemy, Transform);
10736
- *
10737
- * // 发射事件
10738
- * Core.ecsAPI?.emit('game:start', { level: 1 });
10739
- * ```
11279
+ * 预填充池
11280
+ * @param count 预填充的对象数量
10740
11281
  */
10741
- static get ecsAPI(): ECSFluentAPI | null;
11282
+ prewarm(count: number): void;
10742
11283
  /**
10743
- * 延迟加载场景(下一帧切换)
10744
- *
10745
- * @param scene - 要加载的场景
10746
- *
10747
- * @example
10748
- * ```typescript
10749
- * // 延迟切换场景(在下一帧生效)
10750
- * Core.loadScene(new MenuScene());
10751
- * ```
11284
+ * 设置最大池大小
11285
+ * @param maxSize 新的最大大小
10752
11286
  */
10753
- static loadScene<T extends IScene>(scene: T): void;
11287
+ setMaxSize(maxSize: number): void;
10754
11288
  /**
10755
- * 更新游戏逻辑
10756
- *
10757
- * 此方法应该在游戏引擎的更新循环中调用。
10758
- * 会自动更新全局服务和当前场景。
10759
- *
10760
- * @param deltaTime - 外部引擎提供的帧时间间隔(秒)
10761
- *
10762
- * @example
10763
- * ```typescript
10764
- * // 初始化
10765
- * Core.create({ debug: true });
10766
- * Core.setScene(new GameScene());
10767
- *
10768
- * // Laya引擎集成
10769
- * Laya.timer.frameLoop(1, this, () => {
10770
- * const deltaTime = Laya.timer.delta / 1000;
10771
- * Core.update(deltaTime); // 自动更新全局服务和场景
10772
- * });
10773
- *
10774
- * // Cocos Creator集成
10775
- * update(deltaTime: number) {
10776
- * Core.update(deltaTime); // 自动更新全局服务和场景
10777
- * }
10778
- * ```
11289
+ * 获取池中可用对象数量
11290
+ * @returns 可用对象数量
10779
11291
  */
10780
- static update(deltaTime: number): void;
11292
+ getAvailableCount(): number;
10781
11293
  /**
10782
- * 调度定时器
10783
- *
10784
- * 创建一个定时器,在指定时间后执行回调函数。
10785
- *
10786
- * @param timeInSeconds - 延迟时间(秒)
10787
- * @param repeats - 是否重复执行,默认为false
10788
- * @param context - 回调函数的上下文,默认为null
10789
- * @param onTime - 定时器触发时的回调函数
10790
- * @returns 创建的定时器实例
10791
- * @throws 如果Core实例未创建或onTime回调未提供
10792
- *
10793
- * @example
10794
- * ```typescript
10795
- * // 一次性定时器
10796
- * Core.schedule(1.0, false, null, (timer) => {
10797
- * console.log("1秒后执行一次");
10798
- * });
10799
- *
10800
- * // 重复定时器
10801
- * Core.schedule(0.5, true, null, (timer) => {
10802
- * console.log("每0.5秒执行一次");
10803
- * });
10804
- * ```
11294
+ * 检查池是否为空
11295
+ * @returns 如果池为空返回true
10805
11296
  */
10806
- static schedule<TContext = unknown>(timeInSeconds: number, repeats?: boolean, context?: TContext, onTime?: (timer: ITimer<TContext>) => void): Timer<TContext>;
11297
+ isEmpty(): boolean;
10807
11298
  /**
10808
- * 启用调试功能
10809
- *
10810
- * @param config 调试配置
11299
+ * 检查池是否已满
11300
+ * @returns 如果池已满返回true
10811
11301
  */
10812
- static enableDebug(config: IECSDebugConfig): void;
11302
+ isFull(): boolean;
10813
11303
  /**
10814
- * 禁用调试功能
11304
+ * 获取所有已注册的池类型
11305
+ * @returns 所有池类型的数组
10815
11306
  */
10816
- static disableDebug(): void;
11307
+ static getAllPoolTypes(): Function[];
10817
11308
  /**
10818
- * 获取调试数据
10819
- *
10820
- * @returns 当前调试数据,如果调试未启用则返回null
11309
+ * 获取所有池的统计信息
11310
+ * @returns 包含所有池统计信息的对象
10821
11311
  */
10822
- static getDebugData(): unknown;
11312
+ static getAllPoolStats(): Record<string, PoolStats>;
10823
11313
  /**
10824
- * 检查调试是否启用
10825
- *
10826
- * @returns 调试状态
11314
+ * 压缩所有池
10827
11315
  */
10828
- static get isDebugEnabled(): boolean;
11316
+ static compactAllPools(): void;
10829
11317
  /**
10830
- * 安装插件
10831
- *
10832
- * @param plugin - 插件实例
10833
- * @throws 如果Core实例未创建或插件安装失败
10834
- *
10835
- * @example
10836
- * ```typescript
10837
- * Core.create({ debug: true });
10838
- *
10839
- * // 安装插件
10840
- * await Core.installPlugin(new MyPlugin());
10841
- * ```
10842
- */
10843
- static installPlugin(plugin: IPlugin): Promise<void>;
10844
- /**
10845
- * 卸载插件
10846
- *
10847
- * @param name - 插件名称
10848
- * @throws 如果Core实例未创建或插件卸载失败
10849
- *
10850
- * @example
10851
- * ```typescript
10852
- * await Core.uninstallPlugin('my-plugin');
10853
- * ```
10854
- */
10855
- static uninstallPlugin(name: string): Promise<void>;
10856
- /**
10857
- * 获取插件实例
10858
- *
10859
- * @param name - 插件名称
10860
- * @returns 插件实例,如果未安装则返回undefined
10861
- *
10862
- * @example
10863
- * ```typescript
10864
- * const myPlugin = Core.getPlugin('my-plugin');
10865
- * if (myPlugin) {
10866
- * console.log(myPlugin.version);
10867
- * }
10868
- * ```
10869
- */
10870
- static getPlugin(name: string): IPlugin | undefined;
10871
- /**
10872
- * 检查插件是否已安装
10873
- *
10874
- * @param name - 插件名称
10875
- * @returns 是否已安装
10876
- *
10877
- * @example
10878
- * ```typescript
10879
- * if (Core.isPluginInstalled('my-plugin')) {
10880
- * console.log('Plugin is installed');
10881
- * }
10882
- * ```
11318
+ * 清空所有池
10883
11319
  */
10884
- static isPluginInstalled(name: string): boolean;
11320
+ static clearAllPools(): void;
10885
11321
  /**
10886
- * 初始化核心系统
10887
- *
10888
- * 执行核心系统的初始化逻辑。
11322
+ * 获取全局池统计信息的格式化字符串
11323
+ * @returns 格式化的统计信息字符串
10889
11324
  */
10890
- protected initialize(): void;
11325
+ static getGlobalStatsString(): string;
10891
11326
  /**
10892
- * 内部更新方法
10893
- *
10894
- * @param deltaTime - 帧时间间隔(秒)
11327
+ * 更新命中率
10895
11328
  */
10896
- private updateInternal;
11329
+ private _updateHitRate;
10897
11330
  /**
10898
- * 销毁Core实例
10899
- *
10900
- * 清理所有资源,通常在应用程序关闭时调用。
11331
+ * 更新内存使用估算
10901
11332
  */
10902
- static destroy(): void;
11333
+ private _updateMemoryUsage;
10903
11334
  }
10904
11335
 
10905
11336
  /**
10906
- * 插件管理器
10907
- *
10908
- * 负责插件的注册、安装、卸载和生命周期管理。
10909
- * 支持依赖检查和异步加载。
10910
- *
10911
- * @example
10912
- * ```typescript
10913
- * const core = Core.create();
10914
- * const pluginManager = core.getService(PluginManager);
10915
- *
10916
- * // 注册插件
10917
- * await pluginManager.install(new MyPlugin());
10918
- *
10919
- * // 查询插件
10920
- * const plugin = pluginManager.getPlugin('my-plugin');
10921
- *
10922
- * // 卸载插件
10923
- * await pluginManager.uninstall('my-plugin');
10924
- * ```
11337
+ * 池管理器
11338
+ * 统一管理所有对象池
10925
11339
  */
10926
- declare class PluginManager implements IService {
11340
+ declare class PoolManager implements IService {
11341
+ private pools;
11342
+ private autoCompactInterval;
11343
+ private lastCompactTime;
11344
+ constructor();
10927
11345
  /**
10928
- * 已安装的插件
11346
+ * 注册池
11347
+ * @param name 池名称
11348
+ * @param pool 池实例
10929
11349
  */
10930
- private _plugins;
11350
+ registerPool<T extends IPoolable>(name: string, pool: Pool<T>): void;
10931
11351
  /**
10932
- * 插件元数据
11352
+ * 获取池
11353
+ * @param name 池名称
11354
+ * @returns 池实例
10933
11355
  */
10934
- private _metadata;
11356
+ getPool<T extends IPoolable>(name: string): Pool<T> | null;
10935
11357
  /**
10936
- * Core实例引用
11358
+ * 更新池管理器(应在游戏循环中调用)
10937
11359
  */
10938
- private _core;
11360
+ update(): void;
10939
11361
  /**
10940
- * 服务容器引用
11362
+ * 创建或获取标准池
11363
+ * @param name 池名称
11364
+ * @param createFn 创建函数
11365
+ * @param maxSize 最大大小
11366
+ * @param estimatedObjectSize 估算对象大小
11367
+ * @returns 池实例
10941
11368
  */
10942
- private _services;
11369
+ createPool<T extends IPoolable>(name: string, createFn: () => T, maxSize?: number, estimatedObjectSize?: number): Pool<T>;
10943
11370
  /**
10944
- * 初始化插件管理器
10945
- *
10946
- * @param core - Core实例
10947
- * @param services - 服务容器
11371
+ * 移除池
11372
+ * @param name 池名称
11373
+ * @returns 是否成功移除
10948
11374
  */
10949
- initialize(core: Core, services: ServiceContainer): void;
11375
+ removePool(name: string): boolean;
10950
11376
  /**
10951
- * 安装插件
10952
- *
10953
- * 会自动检查依赖并按正确顺序安装。
10954
- *
10955
- * @param plugin - 插件实例
10956
- * @throws 如果依赖检查失败或安装失败
11377
+ * 获取所有池名称
11378
+ * @returns 池名称数组
10957
11379
  */
10958
- install(plugin: IPlugin): Promise<void>;
11380
+ getPoolNames(): string[];
10959
11381
  /**
10960
- * 卸载插件
10961
- *
10962
- * @param name - 插件名称
10963
- * @throws 如果插件未安装或卸载失败
11382
+ * 获取池数量
11383
+ * @returns 池数量
10964
11384
  */
10965
- uninstall(name: string): Promise<void>;
11385
+ getPoolCount(): number;
10966
11386
  /**
10967
- * 获取插件实例
10968
- *
10969
- * @param name - 插件名称
10970
- * @returns 插件实例,如果未安装则返回undefined
11387
+ * 压缩所有池
10971
11388
  */
10972
- getPlugin(name: string): IPlugin | undefined;
11389
+ compactAllPools(): void;
10973
11390
  /**
10974
- * 获取插件元数据
10975
- *
10976
- * @param name - 插件名称
10977
- * @returns 插件元数据,如果未安装则返回undefined
11391
+ * 清空所有池
10978
11392
  */
10979
- getMetadata(name: string): IPluginMetadata | undefined;
11393
+ clearAllPools(): void;
10980
11394
  /**
10981
- * 获取所有已安装的插件
10982
- *
10983
- * @returns 插件列表
11395
+ * 获取所有池的统计信息
11396
+ * @returns 统计信息映射
10984
11397
  */
10985
- getAllPlugins(): IPlugin[];
11398
+ getAllStats(): Map<string, PoolStats>;
10986
11399
  /**
10987
- * 获取所有插件元数据
10988
- *
10989
- * @returns 元数据列表
11400
+ * 获取总体统计信息
11401
+ * @returns 总体统计信息
10990
11402
  */
10991
- getAllMetadata(): IPluginMetadata[];
11403
+ getGlobalStats(): PoolStats;
10992
11404
  /**
10993
- * 检查插件是否已安装
10994
- *
10995
- * @param name - 插件名称
10996
- * @returns 是否已安装
11405
+ * 获取格式化的统计信息字符串
11406
+ * @returns 格式化字符串
10997
11407
  */
10998
- isInstalled(name: string): boolean;
11408
+ getStatsString(): string;
10999
11409
  /**
11000
- * 检查插件依赖
11001
- *
11002
- * @param plugin - 插件实例
11003
- * @throws 如果依赖未满足
11410
+ * 设置自动压缩间隔
11411
+ * @param intervalMs 间隔毫秒数
11004
11412
  */
11005
- private _checkDependencies;
11413
+ setAutoCompactInterval(intervalMs: number): void;
11006
11414
  /**
11007
- * 检查是否有其他插件依赖指定插件
11008
- *
11009
- * @param name - 插件名称
11010
- * @throws 如果有其他插件依赖此插件
11415
+ * 预填充所有池
11011
11416
  */
11012
- private _checkDependents;
11417
+ prewarmAllPools(): void;
11418
+ /**
11419
+ * 重置池管理器
11420
+ */
11421
+ reset(): void;
11013
11422
  /**
11014
11423
  * 释放资源
11424
+ * 实现 IService 接口
11015
11425
  */
11016
11426
  dispose(): void;
11017
11427
  }
11018
11428
 
11019
11429
  /**
11020
- * ECS 调试插件统计信息
11021
- */
11022
- interface ECSDebugStats {
11023
- scenes: SceneDebugInfo[];
11024
- totalEntities: number;
11025
- totalSystems: number;
11026
- timestamp: number;
11027
- }
11028
- /**
11029
- * 场景调试信息
11030
- */
11031
- interface SceneDebugInfo {
11032
- name: string;
11033
- entityCount: number;
11034
- systems: SystemDebugInfo[];
11035
- entities: EntityDebugInfo[];
11036
- }
11037
- /**
11038
- * 系统调试信息
11039
- */
11040
- interface SystemDebugInfo {
11041
- name: string;
11042
- enabled: boolean;
11043
- updateOrder: number;
11044
- entityCount: number;
11045
- performance?: {
11046
- avgExecutionTime: number;
11047
- maxExecutionTime: number;
11048
- totalCalls: number;
11049
- };
11050
- }
11051
- /**
11052
- * 实体调试信息
11053
- */
11054
- interface EntityDebugInfo {
11055
- id: number;
11056
- name: string;
11057
- enabled: boolean;
11058
- tag: number;
11059
- componentCount: number;
11060
- components: ComponentDebugInfo[];
11061
- }
11062
- /**
11063
- * 组件调试信息
11430
+ * 时间管理工具类
11431
+ * 提供游戏时间相关的功能,包括帧时间、总时间、时间缩放等
11064
11432
  */
11065
- interface ComponentDebugInfo {
11066
- type: string;
11067
- data: any;
11433
+ declare class Time {
11434
+ /**
11435
+ * 上一帧到当前帧的时间间隔(秒)
11436
+ */
11437
+ static deltaTime: number;
11438
+ /**
11439
+ * 未缩放的帧时间间隔(秒)
11440
+ */
11441
+ static unscaledDeltaTime: number;
11442
+ /**
11443
+ * 游戏开始以来的总时间(秒)
11444
+ */
11445
+ static totalTime: number;
11446
+ /**
11447
+ * 未缩放的总时间(秒)
11448
+ */
11449
+ static unscaledTotalTime: number;
11450
+ /**
11451
+ * 时间缩放比例
11452
+ */
11453
+ static timeScale: number;
11454
+ /**
11455
+ * 当前帧数
11456
+ */
11457
+ static frameCount: number;
11458
+ /**
11459
+ * 使用外部引擎提供的deltaTime更新时间信息
11460
+ * @param deltaTime 外部引擎提供的帧时间间隔(秒)
11461
+ */
11462
+ static update(deltaTime: number): void;
11463
+ /**
11464
+ * 场景改变时重置时间
11465
+ */
11466
+ static sceneChanged(): void;
11467
+ /**
11468
+ * 检查指定的时间间隔是否已经过去
11469
+ * @param interval 时间间隔(秒)
11470
+ * @param lastTime 上次检查的时间
11471
+ * @returns 是否已经过去指定时间
11472
+ */
11473
+ static checkEvery(interval: number, lastTime: number): boolean;
11068
11474
  }
11475
+
11069
11476
  /**
11070
- * ECS 调试插件
11071
- *
11072
- * 提供运行时调试功能:
11073
- * - 实时查看实体和组件信息
11074
- * - System 执行统计
11075
- * - 性能监控
11076
- * - 实体查询
11077
- *
11078
- * @example
11079
- * ```typescript
11080
- * const core = Core.create();
11081
- * const debugPlugin = new DebugPlugin({ autoStart: true, updateInterval: 1000 });
11082
- * await core.pluginManager.install(debugPlugin);
11083
- *
11084
- * // 获取调试信息
11085
- * const stats = debugPlugin.getStats();
11086
- * console.log('Total entities:', stats.totalEntities);
11087
- *
11088
- * // 查询实体
11089
- * const entities = debugPlugin.queryEntities({ tag: 1 });
11090
- * ```
11477
+ * 实体数据收集器
11091
11478
  */
11092
- declare class DebugPlugin implements IPlugin, IService {
11093
- readonly name = "@esengine/debug-plugin";
11094
- readonly version = "1.0.0";
11095
- private worldManager;
11096
- private updateInterval;
11097
- private updateTimer;
11098
- private autoStart;
11479
+ declare class EntityDataCollector {
11099
11480
  /**
11100
- * 创建调试插件实例
11101
- *
11102
- * @param options - 配置选项
11481
+ * 收集实体数据
11482
+ * @param scene 场景实例
11103
11483
  */
11104
- constructor(options?: {
11105
- autoStart?: boolean;
11106
- updateInterval?: number;
11107
- });
11484
+ collectEntityData(scene?: IScene | null): IEntityDebugData;
11108
11485
  /**
11109
- * 安装插件
11486
+ * 获取原始实体列表
11487
+ * @param scene 场景实例
11110
11488
  */
11111
- install(_core: Core, services: ServiceContainer): Promise<void>;
11489
+ getRawEntityList(scene?: IScene | null): Array<{
11490
+ id: number;
11491
+ name: string;
11492
+ active: boolean;
11493
+ enabled: boolean;
11494
+ activeInHierarchy: boolean;
11495
+ componentCount: number;
11496
+ componentTypes: string[];
11497
+ parentId: number | null;
11498
+ childIds: number[];
11499
+ depth: number;
11500
+ tag: number;
11501
+ updateOrder: number;
11502
+ }>;
11112
11503
  /**
11113
- * 卸载插件
11504
+ * 获取实体详细信息
11505
+ * @param entityId 实体ID
11506
+ * @param scene 场景实例
11114
11507
  */
11115
- uninstall(): Promise<void>;
11508
+ getEntityDetails(entityId: number, scene?: IScene | null): any;
11509
+ private getSceneInfo;
11116
11510
  /**
11117
- * 实现 IService 接口
11511
+ * 收集实体数据(包含内存信息)
11512
+ * @param scene 场景实例
11118
11513
  */
11119
- dispose(): void;
11514
+ collectEntityDataWithMemory(scene?: IScene | null): IEntityDebugData;
11515
+ private collectArchetypeData;
11516
+ private getArchetypeDistributionFast;
11517
+ private getTopEntitiesByComponentsFast;
11518
+ private collectArchetypeDataWithMemory;
11519
+ private extractArchetypeStatistics;
11520
+ private extractArchetypeStatisticsWithMemory;
11521
+ private getArchetypeDistributionWithMemory;
11522
+ private getTopEntitiesByComponentsWithMemory;
11523
+ private getEmptyEntityDebugData;
11524
+ private calculateFallbackEntityStats;
11525
+ estimateEntityMemoryUsage(entity: any): number;
11526
+ calculateObjectSize(obj: any, excludeKeys?: string[]): number;
11527
+ private buildEntityHierarchyTree;
11120
11528
  /**
11121
- * 启动调试监控
11529
+ * 构建实体层次结构节点
11122
11530
  */
11123
- start(): void;
11531
+ private buildEntityHierarchyNode;
11124
11532
  /**
11125
- * 停止调试监控
11533
+ * 构建实体详情映射
11126
11534
  */
11127
- stop(): void;
11535
+ private buildEntityDetailsMap;
11128
11536
  /**
11129
- * 获取当前 ECS 统计信息
11537
+ * 构建实体基础信息
11130
11538
  */
11131
- getStats(): ECSDebugStats;
11539
+ private buildFallbackEntityInfo;
11132
11540
  /**
11133
- * 获取场景调试信息
11541
+ * 提取组件详细信息
11134
11542
  */
11135
- getSceneInfo(scene: IScene): SceneDebugInfo;
11543
+ extractComponentDetails(components: readonly Component[]): Array<{
11544
+ typeName: string;
11545
+ properties: Record<string, any>;
11546
+ }>;
11136
11547
  /**
11137
- * 获取系统调试信息
11548
+ * 获取组件的完整属性信息(仅在需要时调用)
11549
+ * @param entityId 实体ID
11550
+ * @param componentIndex 组件索引
11551
+ * @param scene 场景实例
11138
11552
  */
11139
- private getSystemInfo;
11553
+ getComponentProperties(entityId: number, componentIndex: number, scene?: IScene | null): Record<string, any>;
11140
11554
  /**
11141
- * 获取实体调试信息
11555
+ * 格式化属性值
11142
11556
  */
11143
- getEntityInfo(entity: Entity): EntityDebugInfo;
11557
+ private formatPropertyValue;
11144
11558
  /**
11145
- * 获取组件调试信息
11559
+ * 格式化对象第一层
11146
11560
  */
11147
- private getComponentInfo;
11561
+ private formatObjectFirstLevel;
11148
11562
  /**
11149
- * 查询实体
11150
- *
11151
- * @param filter - 查询过滤器
11563
+ * 创建懒加载占位符
11152
11564
  */
11153
- queryEntities(filter: {
11154
- sceneName?: string;
11155
- tag?: number;
11156
- name?: string;
11157
- hasComponent?: string;
11158
- }): EntityDebugInfo[];
11565
+ private createLazyLoadPlaceholder;
11159
11566
  /**
11160
- * 打印统计信息到日志
11567
+ * 获取对象摘要信息
11161
11568
  */
11162
- private logStats;
11569
+ private getObjectSummary;
11163
11570
  /**
11164
- * 导出调试数据为 JSON
11571
+ * 生成对象ID
11165
11572
  */
11166
- exportJSON(): string;
11573
+ private generateObjectId;
11574
+ /**
11575
+ * 展开懒加载对象(供调试面板调用)
11576
+ * @param entityId 实体ID
11577
+ * @param componentIndex 组件索引
11578
+ * @param propertyPath 属性路径
11579
+ * @param scene 场景实例
11580
+ */
11581
+ expandLazyObject(entityId: number, componentIndex: number, propertyPath: string, scene?: IScene | null): any;
11582
+ /**
11583
+ * 根据路径获取对象
11584
+ */
11585
+ private getObjectByPath;
11167
11586
  }
11168
11587
 
11169
11588
  /**
11170
- * 依赖注入装饰器
11171
- *
11172
- * 提供 @Injectable、@InjectProperty 和 @Updatable 装饰器,用于标记可注入的类和依赖注入点
11589
+ * 系统数据收集器
11173
11590
  */
11591
+ declare class SystemDataCollector {
11592
+ /**
11593
+ * 收集系统数据
11594
+ * @param performanceMonitor 性能监视器实例
11595
+ * @param scene 场景实例
11596
+ */
11597
+ collectSystemData(performanceMonitor: any, scene?: IScene | null): ISystemDebugData;
11598
+ }
11174
11599
 
11175
11600
  /**
11176
- * 依赖注入元数据存储
11177
- */
11178
- type Constructor = abstract new (...args: unknown[]) => unknown;
11179
- /**
11180
- * 可注入元数据接口
11601
+ * 性能数据收集器
11181
11602
  */
11182
- interface InjectableMetadata {
11603
+ declare class PerformanceDataCollector {
11604
+ private frameTimeHistory;
11605
+ private maxHistoryLength;
11606
+ private gcCollections;
11607
+ private lastMemoryCheck;
11183
11608
  /**
11184
- * 是否可注入
11609
+ * 收集性能数据
11185
11610
  */
11186
- injectable: boolean;
11611
+ collectPerformanceData(performanceMonitor: any): IPerformanceDebugData;
11187
11612
  /**
11188
- * 依赖列表
11613
+ * 获取ECS框架整体性能数据
11189
11614
  */
11190
- dependencies: Array<ServiceType<IService> | string | symbol>;
11615
+ private getECSPerformanceData;
11191
11616
  /**
11192
- * 属性注入映射
11193
- * key: 属性名, value: 服务类型
11617
+ * 获取系统性能数据
11194
11618
  */
11195
- properties?: Map<string | symbol, ServiceType<IService>>;
11619
+ private getSystemPerformance;
11620
+ /**
11621
+ * 获取内存详情
11622
+ */
11623
+ private getMemoryDetails;
11624
+ /**
11625
+ * 更新GC计数
11626
+ */
11627
+ private updateGCCount;
11196
11628
  }
11629
+
11197
11630
  /**
11198
- * 可更新元数据接口
11631
+ * 组件数据收集器
11199
11632
  */
11200
- interface UpdatableMetadata {
11633
+ declare class ComponentDataCollector {
11634
+ private static componentSizeCache;
11201
11635
  /**
11202
- * 是否可更新
11636
+ * 收集组件数据(轻量版,不计算实际内存大小)
11637
+ * @param scene 场景实例
11203
11638
  */
11204
- updatable: boolean;
11639
+ collectComponentData(scene?: IScene | null): IComponentDebugData;
11205
11640
  /**
11206
- * 更新优先级(数值越小越先执行,默认0)
11641
+ * 获取组件类型的估算内存大小(基于预设值,不进行实际计算)
11207
11642
  */
11208
- priority: number;
11209
- }
11210
- /**
11211
- * @Injectable() 装饰器
11212
- *
11213
- * 标记类为可注入的服务,使其可以通过ServiceContainer进行依赖注入
11214
- *
11215
- * @example
11216
- * ```typescript
11217
- * @Injectable()
11218
- * class TimeService implements IService {
11219
- * constructor() {}
11220
- * dispose() {}
11221
- * }
11222
- *
11223
- * @Injectable()
11224
- * class PhysicsSystem extends EntitySystem {
11225
- * @InjectProperty(TimeService)
11226
- * private timeService!: TimeService;
11227
- *
11228
- * constructor() {
11229
- * super(Matcher.empty());
11230
- * }
11231
- * }
11232
- * ```
11233
- */
11234
- declare function Injectable(): ClassDecorator;
11235
- /**
11236
- * @Updatable() 装饰器
11237
- *
11238
- * 标记服务类为可更新的,使其在每帧自动被ServiceContainer调用update方法。
11239
- * 使用此装饰器的类必须实现IUpdatable接口(包含update方法)。
11240
- *
11241
- * @param priority - 更新优先级(数值越小越先执行,默认0)
11242
- * @throws 如果类没有实现update方法,将在运行时抛出错误
11243
- *
11244
- * @example
11245
- * ```typescript
11246
- * @Injectable()
11247
- * @Updatable()
11248
- * class TimerManager implements IService, IUpdatable {
11249
- * update(deltaTime?: number) {
11250
- * // 每帧更新逻辑
11251
- * }
11252
- * dispose() {}
11253
- * }
11254
- *
11255
- * // 指定优先级
11256
- * @Injectable()
11257
- * @Updatable(10)
11258
- * class PhysicsManager implements IService, IUpdatable {
11259
- * update() { }
11260
- * dispose() {}
11261
- * }
11262
- * ```
11263
- */
11264
- declare function Updatable(priority?: number): ClassDecorator;
11265
- /**
11266
- * @InjectProperty() 装饰器
11267
- *
11268
- * 通过属性装饰器注入依赖
11269
- *
11270
- * 注入时机:在构造函数执行后、onInitialize() 调用前完成
11271
- *
11272
- * @param serviceType 服务类型
11273
- *
11274
- * @example
11275
- * ```typescript
11276
- * @Injectable()
11277
- * class PhysicsSystem extends EntitySystem {
11278
- * @InjectProperty(TimeService)
11279
- * private timeService!: TimeService;
11280
- *
11281
- * @InjectProperty(CollisionService)
11282
- * private collision!: CollisionService;
11283
- *
11284
- * constructor() {
11285
- * super(Matcher.empty());
11286
- * }
11287
- *
11288
- * public onInitialize(): void {
11289
- * // 此时属性已注入完成,可以安全使用
11290
- * console.log(this.timeService.getDeltaTime());
11291
- * }
11292
- * }
11293
- * ```
11294
- */
11295
- declare function InjectProperty(serviceType: ServiceType<IService>): PropertyDecorator;
11296
- /**
11297
- * 获取属性注入元数据
11298
- *
11299
- * @param target 目标类
11300
- * @returns 属性名到服务类型的映射
11301
- */
11302
- declare function getPropertyInjectMetadata(target: Constructor): Map<string | symbol, ServiceType<IService>>;
11303
- /**
11304
- * 创建实例并自动注入依赖
11305
- *
11306
- * @param constructor 构造函数
11307
- * @param container 服务容器
11308
- * @returns 创建的实例
11309
- *
11310
- * @example
11311
- * ```typescript
11312
- * const instance = createInstance(MySystem, container);
11313
- * ```
11314
- */
11315
- declare function createInstance<T>(constructor: new (...args: any[]) => T, container: ServiceContainer): T;
11316
- /**
11317
- * 为实例注入属性依赖
11318
- *
11319
- * @param instance 目标实例
11320
- * @param container 服务容器
11321
- */
11322
- declare function injectProperties<T extends object>(instance: T, container: ServiceContainer): void;
11323
- /**
11324
- * 检查类是否标记为可更新
11325
- *
11326
- * @param target 目标类
11327
- * @returns 是否可更新
11328
- */
11329
- declare function isUpdatable(target: Constructor): boolean;
11330
- /**
11331
- * 获取类的可更新元数据
11332
- *
11333
- * @param target 目标类
11334
- * @returns 可更新元数据
11335
- */
11336
- declare function getUpdatableMetadata(target: Constructor): UpdatableMetadata | undefined;
11643
+ private getEstimatedComponentSize;
11644
+ private calculateQuickObjectSize;
11645
+ /**
11646
+ * 为内存快照功能提供的详细内存计算
11647
+ * 只在用户主动请求内存快照时调用
11648
+ * @param typeName 组件类型名称
11649
+ * @param scene 场景实例
11650
+ */
11651
+ calculateDetailedComponentMemory(typeName: string, scene?: IScene | null): number;
11652
+ /**
11653
+ * 估算对象内存大小(仅用于内存快照)
11654
+ * 优化版本:减少递归深度,提高性能
11655
+ */
11656
+ private estimateObjectSize;
11657
+ static clearCache(): void;
11658
+ }
11659
+
11337
11660
  /**
11338
- * 注册可注入的服务到容器
11339
- *
11340
- * 自动检测@Injectable装饰器并注册服务
11341
- *
11342
- * @param container 服务容器
11343
- * @param serviceType 服务类型
11344
- * @param singleton 是否注册为单例(默认true)
11345
- *
11346
- * @example
11347
- * ```typescript
11348
- * @Injectable()
11349
- * class MyService implements IService {
11350
- * dispose() {}
11351
- * }
11352
- *
11353
- * // 自动注册
11354
- * registerInjectable(Core.services, MyService);
11355
- * ```
11661
+ * 场景数据收集器
11356
11662
  */
11357
- declare function registerInjectable<T extends IService>(container: ServiceContainer, serviceType: ServiceType<T>, singleton?: boolean): void;
11663
+ declare class SceneDataCollector {
11664
+ private sceneStartTime;
11665
+ /**
11666
+ * 收集场景数据
11667
+ * @param scene 场景实例
11668
+ */
11669
+ collectSceneData(scene?: IScene | null): ISceneDebugData;
11670
+ /**
11671
+ * 设置场景开始时间
11672
+ */
11673
+ setSceneStartTime(time: number): void;
11674
+ }
11358
11675
 
11359
11676
  /**
11360
- * 用于包装事件的一个小类
11677
+ * WebSocket连接管理器
11361
11678
  */
11362
- declare class FuncPack<TContext = unknown> {
11363
- /** 函数 */
11364
- func: Function;
11365
- /** 上下文 */
11366
- context: TContext;
11367
- constructor(func: Function, context: TContext);
11679
+ declare class WebSocketManager {
11680
+ private ws?;
11681
+ private isConnected;
11682
+ private reconnectAttempts;
11683
+ private maxReconnectAttempts;
11684
+ private url;
11685
+ private autoReconnect;
11686
+ private reconnectTimer?;
11687
+ private onOpen?;
11688
+ private onClose?;
11689
+ private onError?;
11690
+ private messageHandler?;
11691
+ constructor(url: string, autoReconnect?: boolean);
11692
+ /**
11693
+ * 设置消息处理回调
11694
+ */
11695
+ setMessageHandler(handler: (message: any) => void): void;
11696
+ /**
11697
+ * 连接WebSocket
11698
+ */
11699
+ connect(): Promise<void>;
11700
+ /**
11701
+ * 断开连接
11702
+ */
11703
+ disconnect(): void;
11704
+ /**
11705
+ * 发送数据
11706
+ */
11707
+ send(data: any): void;
11708
+ /**
11709
+ * 获取连接状态
11710
+ */
11711
+ getConnectionStatus(): boolean;
11712
+ /**
11713
+ * 设置最大重连次数
11714
+ */
11715
+ setMaxReconnectAttempts(attempts: number): void;
11716
+ /**
11717
+ * 计划重连
11718
+ */
11719
+ private scheduleReconnect;
11720
+ /**
11721
+ * 处理接收到的消息
11722
+ */
11723
+ private handleMessage;
11724
+ private handleOpen;
11725
+ private handleClose;
11726
+ private handleError;
11727
+ private handleConnectionFailure;
11368
11728
  }
11729
+
11369
11730
  /**
11370
- * 用于事件管理
11731
+ * 调试管理器
11732
+ *
11733
+ * 整合所有调试数据收集器,负责收集和发送调试数据
11371
11734
  */
11372
- declare class Emitter<T, TContext = unknown> {
11373
- private _messageTable;
11374
- constructor();
11735
+ declare class DebugManager implements IService, IUpdatable {
11736
+ private config;
11737
+ private webSocketManager;
11738
+ private entityCollector;
11739
+ private systemCollector;
11740
+ private performanceCollector;
11741
+ private componentCollector;
11742
+ private sceneCollector;
11743
+ private advancedProfilerCollector;
11744
+ private sceneManager;
11745
+ private performanceMonitor;
11746
+ private configService;
11747
+ private frameCounter;
11748
+ private lastSendTime;
11749
+ private sendInterval;
11750
+ private isRunning;
11751
+ private originalConsole;
11752
+ onInitialize(): void;
11753
+ /**
11754
+ * 启动调试管理器
11755
+ */
11756
+ start(): void;
11757
+ /**
11758
+ * 停止调试管理器
11759
+ */
11760
+ stop(): void;
11761
+ /**
11762
+ * 拦截 console 日志并转发到编辑器
11763
+ */
11764
+ private interceptConsole;
11765
+ /**
11766
+ * 格式化日志消息
11767
+ */
11768
+ private formatLogMessage;
11769
+ /**
11770
+ * 安全的 JSON 序列化,支持循环引用和深度限制
11771
+ */
11772
+ private safeStringify;
11773
+ /**
11774
+ * 发送日志到编辑器
11775
+ */
11776
+ private sendLog;
11375
11777
  /**
11376
- * 开始监听项
11377
- * @param eventType 监听类型
11378
- * @param handler 监听函数
11379
- * @param context 监听上下文
11778
+ * 更新配置
11380
11779
  */
11381
- addObserver(eventType: T, handler: Function, context: TContext): void;
11780
+ updateConfig(config: IECSDebugConfig): void;
11781
+ update(_deltaTime?: number): void;
11382
11782
  /**
11383
- * 移除监听项
11384
- * @param eventType 事件类型
11385
- * @param handler 事件函数
11783
+ * 场景变更回调
11386
11784
  */
11387
- removeObserver(eventType: T, handler: Function): void;
11785
+ onSceneChanged(): void;
11388
11786
  /**
11389
- * 触发该事件
11390
- * @param eventType 事件类型
11391
- * @param data 事件数据
11787
+ * 处理来自调试面板的消息
11392
11788
  */
11393
- emit<TData = unknown>(eventType: T, ...data: TData[]): void;
11789
+ private handleMessage;
11394
11790
  /**
11395
- * 判断是否存在该类型的观察者
11396
- * @param eventType 事件类型
11397
- * @param handler 事件函数
11791
+ * 处理展开懒加载对象请求
11398
11792
  */
11399
- hasObserver(eventType: T, handler: Function): boolean;
11793
+ private handleExpandLazyObjectRequest;
11400
11794
  /**
11401
- * 移除指定事件类型的所有监听器
11402
- * @param eventType 事件类型
11795
+ * 处理获取组件属性请求
11403
11796
  */
11404
- removeAllObservers(eventType?: T): void;
11797
+ private handleGetComponentPropertiesRequest;
11405
11798
  /**
11406
- * 释放所有资源,清理所有监听器
11799
+ * 处理获取原始实体列表请求
11407
11800
  */
11408
- dispose(): void;
11801
+ private handleGetRawEntityListRequest;
11409
11802
  /**
11410
- * 获取事件类型数量
11803
+ * 处理获取实体详情请求
11411
11804
  */
11412
- getEventTypeCount(): number;
11805
+ private handleGetEntityDetailsRequest;
11413
11806
  /**
11414
- * 获取指定事件类型的监听器数量
11415
- * @param eventType 事件类型
11807
+ * 处理获取高级性能分析数据请求
11416
11808
  */
11417
- getObserverCount(eventType: T): number;
11418
- }
11419
-
11420
- /**
11421
- * 全局管理器的基类。所有全局管理器都应该从此类继承。
11422
- */
11423
- declare class GlobalManager {
11809
+ private handleGetAdvancedProfilerDataRequest;
11424
11810
  /**
11425
- * 表示管理器是否启用
11811
+ * 处理设置性能分析器选中函数请求
11426
11812
  */
11427
- _enabled: boolean;
11813
+ private handleSetProfilerSelectedFunction;
11428
11814
  /**
11429
- * 获取或设置管理器是否启用
11815
+ * 处理内存快照请求
11430
11816
  */
11431
- get enabled(): boolean;
11432
- set enabled(value: boolean);
11817
+ private handleMemorySnapshotRequest;
11433
11818
  /**
11434
- * 设置管理器是否启用
11435
- * @param isEnabled 如果为true,则启用管理器;否则禁用管理器
11819
+ * 捕获内存快照
11436
11820
  */
11437
- setEnabled(isEnabled: boolean): void;
11821
+ private captureMemorySnapshot;
11438
11822
  /**
11439
- * 在启用管理器时调用的回调方法
11823
+ * 收集基础内存信息
11440
11824
  */
11441
- protected onEnabled(): void;
11825
+ private collectBaseMemoryInfo;
11442
11826
  /**
11443
- * 在禁用管理器时调用的回调方法
11827
+ * 收集组件内存统计(仅用于内存快照)
11444
11828
  */
11445
- protected onDisabled(): void;
11829
+ private collectComponentMemoryStats;
11830
+ private collectSystemMemoryStats;
11831
+ private calculateQuickSystemSize;
11446
11832
  /**
11447
- * 更新管理器状态的方法
11833
+ * 收集对象池内存统计
11448
11834
  */
11449
- update(): void;
11835
+ private collectPoolMemoryStats;
11836
+ /**
11837
+ * 收集性能统计信息
11838
+ */
11839
+ private collectPerformanceStats;
11840
+ /**
11841
+ * 获取调试数据
11842
+ */
11843
+ getDebugData(): IECSDebugData;
11844
+ /**
11845
+ * 连接WebSocket
11846
+ */
11847
+ private connectWebSocket;
11848
+ /**
11849
+ * 发送调试数据
11850
+ */
11851
+ private sendDebugData;
11852
+ /**
11853
+ * 释放资源
11854
+ */
11855
+ dispose(): void;
11450
11856
  }
11451
11857
 
11452
11858
  /**
11453
- * Entity类型安全工具函数
11859
+ * 调试配置服务
11454
11860
  *
11455
- * 提供类型安全的组件操作工具函数,无需修改Entity类
11861
+ * 管理调试系统的配置信息
11456
11862
  */
11863
+ declare class DebugConfigService implements IService {
11864
+ private _config;
11865
+ constructor();
11866
+ setConfig(config: IECSDebugConfig): void;
11867
+ getConfig(): IECSDebugConfig;
11868
+ isEnabled(): boolean;
11869
+ dispose(): void;
11870
+ }
11457
11871
 
11458
11872
  /**
11459
- * 获取组件,如果不存在则抛出错误
11460
- *
11461
- * @param entity - 实体实例
11462
- * @param componentType - 组件类型构造函数
11463
- * @returns 组件实例(保证非空)
11464
- * @throws {Error} 如果组件不存在
11465
- *
11466
- * @example
11467
- * ```typescript
11468
- * const position = requireComponent(entity, Position);
11469
- * position.x += 10;
11470
- * ```
11873
+ * 性能分析器类型定义
11874
+ */
11875
+ /**
11876
+ * 性能分析类别
11877
+ */
11878
+ declare enum ProfileCategory {
11879
+ /** ECS 系统 */
11880
+ ECS = "ECS",
11881
+ /** 渲染相关 */
11882
+ Rendering = "Rendering",
11883
+ /** 物理系统 */
11884
+ Physics = "Physics",
11885
+ /** 音频系统 */
11886
+ Audio = "Audio",
11887
+ /** 网络相关 */
11888
+ Network = "Network",
11889
+ /** 用户脚本 */
11890
+ Script = "Script",
11891
+ /** 内存相关 */
11892
+ Memory = "Memory",
11893
+ /** 动画系统 */
11894
+ Animation = "Animation",
11895
+ /** AI/行为树 */
11896
+ AI = "AI",
11897
+ /** 输入处理 */
11898
+ Input = "Input",
11899
+ /** 资源加载 */
11900
+ Loading = "Loading",
11901
+ /** 自定义 */
11902
+ Custom = "Custom"
11903
+ }
11904
+ /**
11905
+ * 采样句柄
11906
+ */
11907
+ interface SampleHandle {
11908
+ id: string;
11909
+ name: string;
11910
+ category: ProfileCategory;
11911
+ startTime: number;
11912
+ depth: number;
11913
+ parentId?: string | undefined;
11914
+ }
11915
+ /**
11916
+ * 性能采样数据
11471
11917
  */
11472
- declare function requireComponent<T extends ComponentConstructor>(entity: Entity, componentType: T): ComponentInstance<T>;
11918
+ interface ProfileSample {
11919
+ id: string;
11920
+ name: string;
11921
+ category: ProfileCategory;
11922
+ startTime: number;
11923
+ endTime: number;
11924
+ duration: number;
11925
+ selfTime: number;
11926
+ parentId?: string | undefined;
11927
+ /** 父级采样的名称(用于构建调用图) */
11928
+ parentName?: string | undefined;
11929
+ depth: number;
11930
+ callCount: number;
11931
+ metadata?: Record<string, unknown>;
11932
+ }
11473
11933
  /**
11474
- * 尝试获取组件
11475
- *
11476
- * @param entity - 实体实例
11477
- * @param componentType - 组件类型构造函数
11478
- * @returns 组件实例或undefined
11479
- *
11480
- * @example
11481
- * ```typescript
11482
- * const health = tryGetComponent(entity, Health);
11483
- * if (health) {
11484
- * health.value -= 10;
11485
- * }
11486
- * ```
11934
+ * 聚合后的采样统计
11487
11935
  */
11488
- declare function tryGetComponent<T extends ComponentConstructor>(entity: Entity, componentType: T): ComponentInstance<T> | undefined;
11936
+ interface ProfileSampleStats {
11937
+ name: string;
11938
+ category: ProfileCategory;
11939
+ /** 包含时间(包含子调用) */
11940
+ inclusiveTime: number;
11941
+ /** 独占时间(不包含子调用) */
11942
+ exclusiveTime: number;
11943
+ /** 调用次数 */
11944
+ callCount: number;
11945
+ /** 平均时间 */
11946
+ averageTime: number;
11947
+ /** 最小时间 */
11948
+ minTime: number;
11949
+ /** 最大时间 */
11950
+ maxTime: number;
11951
+ /** 占总帧时间百分比 */
11952
+ percentOfFrame: number;
11953
+ /** 占父级时间百分比 */
11954
+ percentOfParent: number;
11955
+ /** 子采样 */
11956
+ children: ProfileSampleStats[];
11957
+ /** 深度 */
11958
+ depth: number;
11959
+ }
11489
11960
  /**
11490
- * 批量获取组件
11491
- *
11492
- * @param entity - 实体实例
11493
- * @param types - 组件类型构造函数数组
11494
- * @returns 组件实例元组,每个元素可能为null
11495
- *
11496
- * @example
11497
- * ```typescript
11498
- * const [pos, vel, health] = getComponents(entity, Position, Velocity, Health);
11499
- * if (pos && vel && health) {
11500
- * pos.x += vel.dx;
11501
- * }
11502
- * ```
11961
+ * 内存快照
11503
11962
  */
11504
- declare function getComponents<T extends readonly ComponentConstructor[]>(entity: Entity, ...types: T): {
11505
- [K in keyof T]: ComponentInstance<T[K]> | null;
11506
- };
11963
+ interface MemorySnapshot {
11964
+ timestamp: number;
11965
+ /** 已使用堆内存 (bytes) */
11966
+ usedHeapSize: number;
11967
+ /** 总堆内存 (bytes) */
11968
+ totalHeapSize: number;
11969
+ /** 堆内存限制 (bytes) */
11970
+ heapSizeLimit: number;
11971
+ /** 使用率 (0-100) */
11972
+ utilizationPercent: number;
11973
+ /** 检测到的 GC 次数 */
11974
+ gcCount: number;
11975
+ }
11507
11976
  /**
11508
- * 检查实体是否拥有所有指定的组件
11509
- *
11510
- * @param entity - 实体实例
11511
- * @param types - 组件类型构造函数数组
11512
- * @returns 如果拥有所有组件返回true,否则返回false
11513
- *
11514
- * @example
11515
- * ```typescript
11516
- * if (hasComponents(entity, Position, Velocity)) {
11517
- * const pos = entity.getComponent(Position)!;
11518
- * const vel = entity.getComponent(Velocity)!;
11519
- * }
11520
- * ```
11977
+ * 计数器数据
11521
11978
  */
11522
- declare function hasComponents(entity: Entity, ...types: ComponentConstructor[]): boolean;
11979
+ interface ProfileCounter {
11980
+ name: string;
11981
+ category: ProfileCategory;
11982
+ value: number;
11983
+ type: 'counter' | 'gauge';
11984
+ history: Array<{
11985
+ time: number;
11986
+ value: number;
11987
+ }>;
11988
+ }
11523
11989
  /**
11524
- * 检查实体是否拥有至少一个指定的组件
11525
- *
11526
- * @param entity - 实体实例
11527
- * @param types - 组件类型构造函数数组
11528
- * @returns 如果拥有任意一个组件返回true,否则返回false
11990
+ * 单帧性能数据
11991
+ */
11992
+ interface ProfileFrame {
11993
+ frameNumber: number;
11994
+ startTime: number;
11995
+ endTime: number;
11996
+ duration: number;
11997
+ samples: ProfileSample[];
11998
+ sampleStats: ProfileSampleStats[];
11999
+ counters: Map<string, ProfileCounter>;
12000
+ memory: MemorySnapshot;
12001
+ /** 按类别分组的统计 */
12002
+ categoryStats: Map<ProfileCategory, {
12003
+ totalTime: number;
12004
+ sampleCount: number;
12005
+ percentOfFrame: number;
12006
+ }>;
12007
+ }
12008
+ /**
12009
+ * 分析器配置
11529
12010
  */
11530
- declare function hasAnyComponent(entity: Entity, ...types: ComponentConstructor[]): boolean;
12011
+ interface ProfilerConfig {
12012
+ /** 是否启用 */
12013
+ enabled: boolean;
12014
+ /** 最大历史帧数 */
12015
+ maxFrameHistory: number;
12016
+ /** 采样深度限制 */
12017
+ maxSampleDepth: number;
12018
+ /** 是否收集内存数据 */
12019
+ collectMemory: boolean;
12020
+ /** 内存采样间隔 (ms) */
12021
+ memorySampleInterval: number;
12022
+ /** 是否检测长任务 */
12023
+ detectLongTasks: boolean;
12024
+ /** 长任务阈值 (ms) */
12025
+ longTaskThreshold: number;
12026
+ /** 启用的类别 */
12027
+ enabledCategories: Set<ProfileCategory>;
12028
+ }
11531
12029
  /**
11532
- * 添加组件并立即配置
11533
- *
11534
- * @param entity - 实体实例
11535
- * @param component - 组件实例
11536
- * @param configure - 配置回调函数
11537
- * @returns 实体实例(支持链式调用)
12030
+ * 长任务信息
12031
+ */
12032
+ interface LongTaskInfo {
12033
+ startTime: number;
12034
+ duration: number;
12035
+ attribution: string[];
12036
+ }
12037
+ /**
12038
+ * 调用关系节点
12039
+ */
12040
+ interface CallGraphNode {
12041
+ name: string;
12042
+ category: ProfileCategory;
12043
+ /** 被调用次数 */
12044
+ callCount: number;
12045
+ /** 总耗时 */
12046
+ totalTime: number;
12047
+ /** 调用者列表 */
12048
+ callers: Map<string, {
12049
+ count: number;
12050
+ totalTime: number;
12051
+ }>;
12052
+ /** 被调用者列表 */
12053
+ callees: Map<string, {
12054
+ count: number;
12055
+ totalTime: number;
12056
+ }>;
12057
+ }
12058
+ /**
12059
+ * 性能分析报告
12060
+ */
12061
+ interface ProfileReport {
12062
+ startTime: number;
12063
+ endTime: number;
12064
+ totalFrames: number;
12065
+ averageFrameTime: number;
12066
+ minFrameTime: number;
12067
+ maxFrameTime: number;
12068
+ p95FrameTime: number;
12069
+ p99FrameTime: number;
12070
+ /** 热点函数 (按耗时排序) */
12071
+ hotspots: ProfileSampleStats[];
12072
+ /** 调用图 */
12073
+ callGraph: Map<string, CallGraphNode>;
12074
+ /** 类别统计 */
12075
+ categoryBreakdown: Map<ProfileCategory, {
12076
+ totalTime: number;
12077
+ averageTime: number;
12078
+ percentOfTotal: number;
12079
+ }>;
12080
+ /** 内存趋势 */
12081
+ memoryTrend: MemorySnapshot[];
12082
+ /** 长任务列表 */
12083
+ longTasks: LongTaskInfo[];
12084
+ }
12085
+ /**
12086
+ * 默认配置
12087
+ */
12088
+ declare const DEFAULT_PROFILER_CONFIG: ProfilerConfig;
12089
+
12090
+ /**
12091
+ * 高级性能分析数据收集器
11538
12092
  *
11539
- * @example
11540
- * ```typescript
11541
- * addAndConfigure(entity, new Health(), health => {
11542
- * health.maxValue = 100;
11543
- * health.value = 50;
11544
- * });
11545
- * ```
12093
+ * 整合 ProfilerSDK 和现有 PerformanceMonitor 的数据,
12094
+ * 提供统一的高级性能分析数据接口
12095
+ */
12096
+
12097
+ /**
12098
+ * 旧版 PerformanceMonitor 接口 (用于兼容)
12099
+ */
12100
+ interface ILegacyPerformanceMonitor {
12101
+ getAllSystemStats?: () => Map<string, {
12102
+ averageTime: number;
12103
+ minTime?: number;
12104
+ maxTime?: number;
12105
+ executionCount?: number;
12106
+ }>;
12107
+ getAllSystemData?: () => Map<string, {
12108
+ executionTime: number;
12109
+ entityCount?: number;
12110
+ }>;
12111
+ }
12112
+ /**
12113
+ * 热点函数项(支持递归层级)
12114
+ */
12115
+ interface IHotspotItem {
12116
+ name: string;
12117
+ category: string;
12118
+ inclusiveTime: number;
12119
+ inclusiveTimePercent: number;
12120
+ exclusiveTime: number;
12121
+ exclusiveTimePercent: number;
12122
+ callCount: number;
12123
+ avgCallTime: number;
12124
+ /** 层级深度 */
12125
+ depth: number;
12126
+ /** 子函数 */
12127
+ children?: IHotspotItem[] | undefined;
12128
+ }
12129
+ /**
12130
+ * 高级性能数据接口
12131
+ */
12132
+ interface IAdvancedProfilerData {
12133
+ /** 当前帧信息 */
12134
+ currentFrame: {
12135
+ frameNumber: number;
12136
+ frameTime: number;
12137
+ fps: number;
12138
+ memory: MemorySnapshot;
12139
+ };
12140
+ /** 帧时间历史 (用于绘制图表) */
12141
+ frameTimeHistory: Array<{
12142
+ frameNumber: number;
12143
+ time: number;
12144
+ duration: number;
12145
+ }>;
12146
+ /** 按类别分组的统计 */
12147
+ categoryStats: Array<{
12148
+ category: string;
12149
+ totalTime: number;
12150
+ percentOfFrame: number;
12151
+ sampleCount: number;
12152
+ expanded?: boolean;
12153
+ items: Array<{
12154
+ name: string;
12155
+ inclusiveTime: number;
12156
+ exclusiveTime: number;
12157
+ callCount: number;
12158
+ percentOfCategory: number;
12159
+ percentOfFrame: number;
12160
+ }>;
12161
+ }>;
12162
+ /** 热点函数列表(支持层级) */
12163
+ hotspots: IHotspotItem[];
12164
+ /** 调用关系数据 */
12165
+ callGraph: {
12166
+ /** 当前选中的函数 */
12167
+ currentFunction: string | null;
12168
+ /** 调用当前函数的函数列表 */
12169
+ callers: Array<{
12170
+ name: string;
12171
+ callCount: number;
12172
+ totalTime: number;
12173
+ percentOfCurrent: number;
12174
+ }>;
12175
+ /** 当前函数调用的函数列表 */
12176
+ callees: Array<{
12177
+ name: string;
12178
+ callCount: number;
12179
+ totalTime: number;
12180
+ percentOfCurrent: number;
12181
+ }>;
12182
+ };
12183
+ /** 长任务列表 */
12184
+ longTasks: Array<{
12185
+ startTime: number;
12186
+ duration: number;
12187
+ attribution: string[];
12188
+ }>;
12189
+ /** 内存趋势 */
12190
+ memoryTrend: Array<{
12191
+ time: number;
12192
+ usedMB: number;
12193
+ totalMB: number;
12194
+ gcCount: number;
12195
+ }>;
12196
+ /** 统计摘要 */
12197
+ summary: {
12198
+ totalFrames: number;
12199
+ averageFrameTime: number;
12200
+ minFrameTime: number;
12201
+ maxFrameTime: number;
12202
+ p95FrameTime: number;
12203
+ p99FrameTime: number;
12204
+ currentMemoryMB: number;
12205
+ peakMemoryMB: number;
12206
+ gcCount: number;
12207
+ longTaskCount: number;
12208
+ };
12209
+ }
12210
+ /**
12211
+ * 高级性能分析数据收集器
11546
12212
  */
11547
- declare function addAndConfigure<T extends Component>(entity: Entity, component: T, configure: (component: T) => void): Entity;
12213
+ declare class AdvancedProfilerCollector {
12214
+ private selectedFunction;
12215
+ private peakMemory;
12216
+ constructor();
12217
+ /**
12218
+ * 设置选中的函数(用于调用关系视图)
12219
+ */
12220
+ setSelectedFunction(name: string | null): void;
12221
+ /**
12222
+ * 收集高级性能数据
12223
+ */
12224
+ collectAdvancedData(performanceMonitor?: ILegacyPerformanceMonitor): IAdvancedProfilerData;
12225
+ /**
12226
+ * 从现有 PerformanceMonitor 数据构建兼容格式
12227
+ */
12228
+ collectFromLegacyMonitor(performanceMonitor: ILegacyPerformanceMonitor | null): IAdvancedProfilerData;
12229
+ private buildCurrentFrameData;
12230
+ private buildFrameTimeHistory;
12231
+ private buildCategoryStats;
12232
+ private buildCategoryStatsFromLegacy;
12233
+ private buildHotspots;
12234
+ private buildHotspotsFromLegacy;
12235
+ private buildCallGraph;
12236
+ private buildMemoryTrend;
12237
+ private buildSummary;
12238
+ private getCurrentMemory;
12239
+ private getDefaultMemory;
12240
+ private createEmptyData;
12241
+ }
12242
+
11548
12243
  /**
11549
- * 获取或添加组件
11550
- *
11551
- * 如果组件已存在则返回现有组件,否则通过工厂函数创建并添加
11552
- *
11553
- * @param entity - 实体实例
11554
- * @param componentType - 组件类型构造函数
11555
- * @param factory - 组件工厂函数(仅在组件不存在时调用)
11556
- * @returns 组件实例
11557
- *
11558
- * @example
11559
- * ```typescript
11560
- * const health = getOrAddComponent(entity, Health, () => new Health(100));
11561
- * ```
12244
+ * 二进制序列化器
12245
+ * 将对象转换为UTF8字节数组
11562
12246
  */
11563
- declare function getOrAddComponent<T extends ComponentConstructor>(entity: Entity, componentType: T, factory: () => ComponentInstance<T>): ComponentInstance<T>;
12247
+ declare class BinarySerializer {
12248
+ /**
12249
+ * 将字符串编码为UTF8字节数组
12250
+ */
12251
+ private static stringToUtf8;
12252
+ /**
12253
+ * 将UTF8字节数组解码为字符串
12254
+ */
12255
+ private static utf8ToString;
12256
+ /**
12257
+ * 将对象编码为二进制数据
12258
+ */
12259
+ static encode(value: any): Uint8Array;
12260
+ /**
12261
+ * 将二进制数据解码为对象
12262
+ */
12263
+ static decode(bytes: Uint8Array): any;
12264
+ }
12265
+
11564
12266
  /**
11565
- * 更新组件的部分字段
11566
- *
11567
- * @param entity - 实体实例
11568
- * @param componentType - 组件类型构造函数
11569
- * @param data - 要更新的部分数据
11570
- * @returns 如果更新成功返回true,组件不存在返回false
12267
+ * 性能分析器 SDK
11571
12268
  *
11572
- * @example
11573
- * ```typescript
11574
- * updateComponent(entity, Position, { x: 100 });
11575
- * ```
12269
+ * 提供统一的性能分析接口,支持:
12270
+ * - 手动采样标记
12271
+ * - 自动作用域测量
12272
+ * - 调用层级追踪
12273
+ * - 计数器和仪表
11576
12274
  */
11577
- declare function updateComponent<T extends ComponentConstructor>(entity: Entity, componentType: T, data: Partial<ComponentInstance<T>>): boolean;
12275
+
11578
12276
  /**
11579
- * 类型安全的实体构建器
11580
- *
11581
- * @example
11582
- * ```typescript
11583
- * const player = buildEntity(scene.createEntity("Player"))
11584
- * .with(new Position(100, 100))
11585
- * .with(new Velocity(0, 0))
11586
- * .withTag(1)
11587
- * .build();
11588
- * ```
12277
+ * 性能分析器 SDK
11589
12278
  */
11590
- declare class TypedEntityBuilder {
11591
- private _entity;
11592
- constructor(entity: Entity);
12279
+ declare class ProfilerSDK {
12280
+ private static instance;
12281
+ private config;
12282
+ private currentFrame;
12283
+ private frameHistory;
12284
+ private frameNumber;
12285
+ private activeSamples;
12286
+ private sampleStack;
12287
+ private counters;
12288
+ private callGraph;
12289
+ private gcCount;
12290
+ private previousHeapSize;
12291
+ private longTasks;
12292
+ private performanceObserver;
12293
+ private constructor();
11593
12294
  /**
11594
- * 添加组件
12295
+ * 获取单例实例
11595
12296
  */
11596
- with<T extends Component>(component: T): this;
12297
+ static getInstance(config?: Partial<ProfilerConfig>): ProfilerSDK;
11597
12298
  /**
11598
- * 添加并配置组件
12299
+ * 重置实例(测试用)
11599
12300
  */
11600
- withConfigured<T extends Component>(component: T, configure: (component: T) => void): this;
12301
+ static resetInstance(): void;
11601
12302
  /**
11602
- * 设置标签
12303
+ * 开始采样
11603
12304
  */
11604
- withTag(tag: number): this;
12305
+ static beginSample(name: string, category?: ProfileCategory): SampleHandle | null;
11605
12306
  /**
11606
- * 设置名称
12307
+ * 结束采样
11607
12308
  */
11608
- withName(name: string): this;
12309
+ static endSample(handle: SampleHandle | null): void;
11609
12310
  /**
11610
- * 设置激活状态
12311
+ * 测量同步函数执行时间
11611
12312
  */
11612
- withActive(active: boolean): this;
12313
+ static measure<T>(name: string, fn: () => T, category?: ProfileCategory): T;
12314
+ /**
12315
+ * 测量异步函数执行时间
12316
+ */
12317
+ static measureAsync<T>(name: string, fn: () => Promise<T>, category?: ProfileCategory): Promise<T>;
12318
+ /**
12319
+ * 开始帧
12320
+ */
12321
+ static beginFrame(): void;
12322
+ /**
12323
+ * 结束帧
12324
+ */
12325
+ static endFrame(): void;
12326
+ /**
12327
+ * 递增计数器
12328
+ */
12329
+ static incrementCounter(name: string, value?: number, category?: ProfileCategory): void;
12330
+ /**
12331
+ * 设置仪表值
12332
+ */
12333
+ static setGauge(name: string, value: number, category?: ProfileCategory): void;
12334
+ /**
12335
+ * 启用/禁用分析器
12336
+ */
12337
+ static setEnabled(enabled: boolean): void;
12338
+ /**
12339
+ * 检查是否启用
12340
+ */
12341
+ static isEnabled(): boolean;
12342
+ /**
12343
+ * 获取当前帧数据
12344
+ */
12345
+ static getCurrentFrame(): ProfileFrame | null;
12346
+ /**
12347
+ * 获取帧历史
12348
+ */
12349
+ static getFrameHistory(): ProfileFrame[];
12350
+ /**
12351
+ * 获取分析报告
12352
+ */
12353
+ static getReport(frameCount?: number): ProfileReport;
12354
+ /**
12355
+ * 重置数据
12356
+ */
12357
+ static reset(): void;
12358
+ /**
12359
+ * 开始采样
12360
+ */
12361
+ beginSample(name: string, category?: ProfileCategory): SampleHandle | null;
12362
+ /**
12363
+ * 结束采样
12364
+ */
12365
+ endSample(handle: SampleHandle): void;
12366
+ /**
12367
+ * 测量同步函数
12368
+ */
12369
+ measure<T>(name: string, fn: () => T, category?: ProfileCategory): T;
12370
+ /**
12371
+ * 测量异步函数
12372
+ */
12373
+ measureAsync<T>(name: string, fn: () => Promise<T>, category?: ProfileCategory): Promise<T>;
12374
+ /**
12375
+ * 开始帧
12376
+ */
12377
+ beginFrame(): void;
12378
+ /**
12379
+ * 结束帧
12380
+ */
12381
+ endFrame(): void;
12382
+ /**
12383
+ * 递增计数器
12384
+ */
12385
+ incrementCounter(name: string, value?: number, category?: ProfileCategory): void;
12386
+ /**
12387
+ * 设置仪表值
12388
+ */
12389
+ setGauge(name: string, value: number, category?: ProfileCategory): void;
11613
12390
  /**
11614
12391
  * 设置启用状态
11615
12392
  */
11616
- withEnabled(enabled: boolean): this;
12393
+ setEnabled(enabled: boolean): void;
11617
12394
  /**
11618
- * 设置更新顺序
12395
+ * 重置数据
11619
12396
  */
11620
- withUpdateOrder(order: number): this;
12397
+ reset(): void;
11621
12398
  /**
11622
- * 添加子实体
12399
+ * 生成分析报告
11623
12400
  */
11624
- withChild(child: Entity): this;
12401
+ generateReport(frameCount?: number): ProfileReport;
11625
12402
  /**
11626
- * 完成构建
12403
+ * 从帧历史构建调用图
12404
+ * 注意:totalTime 存储的是平均耗时(总耗时/调用次数),而不是累计总耗时
11627
12405
  */
11628
- build(): Entity;
12406
+ private buildCallGraphFromFrames;
11629
12407
  /**
11630
- * 获取正在构建的实体
12408
+ * 获取调用图数据
11631
12409
  */
11632
- get entity(): Entity;
12410
+ getCallGraph(): Map<string, CallGraphNode>;
12411
+ /**
12412
+ * 获取特定函数的调用关系
12413
+ */
12414
+ getFunctionCallInfo(name: string): {
12415
+ callers: Array<{
12416
+ name: string;
12417
+ count: number;
12418
+ totalTime: number;
12419
+ }>;
12420
+ callees: Array<{
12421
+ name: string;
12422
+ count: number;
12423
+ totalTime: number;
12424
+ }>;
12425
+ } | null;
12426
+ /**
12427
+ * 释放资源
12428
+ */
12429
+ dispose(): void;
12430
+ private captureMemory;
12431
+ private resetFrameCounters;
12432
+ private calculateSampleStats;
12433
+ private calculateCategoryStats;
12434
+ private updateCallGraph;
12435
+ private aggregateSampleStats;
12436
+ private aggregateCategoryStats;
12437
+ private setupLongTaskObserver;
12438
+ private createEmptyReport;
11633
12439
  }
12440
+
11634
12441
  /**
11635
- * 创建类型安全的实体构建器
12442
+ * 自动性能分析器
11636
12443
  *
11637
- * @param entity - 要包装的实体
11638
- * @returns 实体构建器
12444
+ * 提供自动函数包装和采样分析功能,无需手动埋点即可收集性能数据。
12445
+ *
12446
+ * 支持三种分析模式:
12447
+ * 1. 自动包装模式 - 使用 Proxy 自动包装类的所有方法
12448
+ * 2. 采样分析模式 - 定时采样调用栈(需要浏览器支持)
12449
+ * 3. 装饰器模式 - 使用 @Profile() 装饰器手动标记方法
11639
12450
  */
11640
- declare function buildEntity(entity: Entity): TypedEntityBuilder;
11641
12451
 
11642
12452
  /**
11643
- * 类型工具类
11644
- * 提供类型相关的实用方法
12453
+ * 自动分析配置
11645
12454
  */
11646
- declare class TypeUtils {
11647
- /**
11648
- * 获取对象的类型
11649
- * @param obj 对象
11650
- * @returns 对象的构造函数
11651
- */
11652
- static getType(obj: any): any;
12455
+ interface AutoProfilerConfig {
12456
+ /** 是否启用自动包装 */
12457
+ enabled: boolean;
12458
+ /** 采样间隔(毫秒),用于采样分析器 */
12459
+ sampleInterval: number;
12460
+ /** 最小记录耗时(毫秒),低于此值的调用不记录 */
12461
+ minDuration: number;
12462
+ /** 是否追踪异步方法 */
12463
+ trackAsync: boolean;
12464
+ /** 排除的方法名模式 */
12465
+ excludePatterns: RegExp[];
12466
+ /** 最大采样缓冲区大小 */
12467
+ maxBufferSize: number;
11653
12468
  }
11654
-
11655
12469
  /**
11656
- * 数字扩展工具类
11657
- * 提供数字转换的实用方法
12470
+ * 采样数据
11658
12471
  */
11659
- declare class NumberExtension {
11660
- /**
11661
- * 将值转换为数字
11662
- * @param value 要转换的值
11663
- * @returns 转换后的数字,如果值为undefined则返回0
11664
- */
11665
- static toNumber(value: unknown): number;
12472
+ interface SampleData {
12473
+ timestamp: number;
12474
+ stack: string[];
12475
+ duration?: number;
11666
12476
  }
11667
-
11668
12477
  /**
11669
- * 时间管理工具类
11670
- * 提供游戏时间相关的功能,包括帧时间、总时间、时间缩放等
12478
+ * 自动性能分析器
11671
12479
  */
11672
- declare class Time {
12480
+ declare class AutoProfiler {
12481
+ private static instance;
12482
+ private config;
12483
+ private wrappedObjects;
12484
+ private samplingProfiler;
12485
+ private registeredClasses;
12486
+ private constructor();
11673
12487
  /**
11674
- * 上一帧到当前帧的时间间隔(秒)
12488
+ * 获取单例实例
11675
12489
  */
11676
- static deltaTime: number;
12490
+ static getInstance(config?: Partial<AutoProfilerConfig>): AutoProfiler;
11677
12491
  /**
11678
- * 未缩放的帧时间间隔(秒)
12492
+ * 重置实例
11679
12493
  */
11680
- static unscaledDeltaTime: number;
12494
+ static resetInstance(): void;
11681
12495
  /**
11682
- * 游戏开始以来的总时间(秒)
12496
+ * 启用/禁用自动分析
11683
12497
  */
11684
- static totalTime: number;
12498
+ static setEnabled(enabled: boolean): void;
11685
12499
  /**
11686
- * 未缩放的总时间(秒)
12500
+ * 注册类以进行自动分析
12501
+ * 该类的所有实例方法都会被自动包装
11687
12502
  */
11688
- static unscaledTotalTime: number;
12503
+ static registerClass<T extends new (...args: any[]) => any>(constructor: T, category?: ProfileCategory, className?: string): T;
11689
12504
  /**
11690
- * 时间缩放比例
12505
+ * 包装对象实例的所有方法
11691
12506
  */
11692
- static timeScale: number;
12507
+ static wrapInstance<T extends object>(instance: T, className: string, category?: ProfileCategory): T;
11693
12508
  /**
11694
- * 当前帧数
12509
+ * 包装单个函数
11695
12510
  */
11696
- static frameCount: number;
12511
+ static wrapFunction<T extends (...args: any[]) => any>(fn: T, name: string, category?: ProfileCategory): T;
11697
12512
  /**
11698
- * 使用外部引擎提供的deltaTime更新时间信息
11699
- * @param deltaTime 外部引擎提供的帧时间间隔(秒)
12513
+ * 启动采样分析器
11700
12514
  */
11701
- static update(deltaTime: number): void;
12515
+ static startSampling(): void;
11702
12516
  /**
11703
- * 场景改变时重置时间
12517
+ * 停止采样分析器
11704
12518
  */
11705
- static sceneChanged(): void;
12519
+ static stopSampling(): SampleData[];
11706
12520
  /**
11707
- * 检查指定的时间间隔是否已经过去
11708
- * @param interval 时间间隔(秒)
11709
- * @param lastTime 上次检查的时间
11710
- * @returns 是否已经过去指定时间
12521
+ * 设置启用状态
11711
12522
  */
11712
- static checkEvery(interval: number, lastTime: number): boolean;
11713
- }
11714
-
11715
- /**
11716
- * 二进制序列化器
11717
- * 将对象转换为UTF8字节数组
11718
- */
11719
- declare class BinarySerializer {
12523
+ setEnabled(enabled: boolean): void;
11720
12524
  /**
11721
- * 将字符串编码为UTF8字节数组
12525
+ * 注册类以进行自动分析
11722
12526
  */
11723
- private static stringToUtf8;
12527
+ registerClass<T extends new (...args: any[]) => any>(constructor: T, category?: ProfileCategory, className?: string): T;
11724
12528
  /**
11725
- * 将UTF8字节数组解码为字符串
12529
+ * 包装对象实例的所有方法
11726
12530
  */
11727
- private static utf8ToString;
12531
+ wrapInstance<T extends object>(instance: T, className: string, category?: ProfileCategory): T;
11728
12532
  /**
11729
- * 将对象编码为二进制数据
12533
+ * 包装单个函数
11730
12534
  */
11731
- static encode(value: any): Uint8Array;
12535
+ wrapFunction<T extends (...args: any[]) => any>(fn: T, name: string, category?: ProfileCategory): T;
11732
12536
  /**
11733
- * 将二进制数据解码为对象
12537
+ * 启动采样分析器
11734
12538
  */
11735
- static decode(bytes: Uint8Array): any;
12539
+ startSampling(): void;
12540
+ /**
12541
+ * 停止采样分析器
12542
+ */
12543
+ stopSampling(): SampleData[];
12544
+ /**
12545
+ * 释放资源
12546
+ */
12547
+ dispose(): void;
12548
+ /**
12549
+ * 创建包装后的方法
12550
+ */
12551
+ private createWrappedMethod;
12552
+ /**
12553
+ * 获取对象的所有方法名
12554
+ */
12555
+ private getAllMethodNames;
12556
+ /**
12557
+ * 获取属性描述符
12558
+ */
12559
+ private getPropertyDescriptor;
12560
+ /**
12561
+ * 判断是否应该排除该方法
12562
+ */
12563
+ private shouldExcludeMethod;
11736
12564
  }
12565
+ /**
12566
+ * @Profile 装饰器
12567
+ * 用于标记需要性能分析的方法
12568
+ *
12569
+ * @example
12570
+ * ```typescript
12571
+ * class MySystem extends System {
12572
+ * @Profile()
12573
+ * update() {
12574
+ * // 方法执行时间会被自动记录
12575
+ * }
12576
+ *
12577
+ * @Profile('customName', ProfileCategory.Physics)
12578
+ * calculatePhysics() {
12579
+ * // 使用自定义名称和分类
12580
+ * }
12581
+ * }
12582
+ * ```
12583
+ */
12584
+ declare function Profile(name?: string, category?: ProfileCategory): MethodDecorator;
12585
+ /**
12586
+ * @ProfileClass 装饰器
12587
+ * 用于自动包装类的所有方法
12588
+ *
12589
+ * @example
12590
+ * ```typescript
12591
+ * @ProfileClass(ProfileCategory.Physics)
12592
+ * class PhysicsSystem extends System {
12593
+ * update() { ... } // 自动被包装
12594
+ * calculate() { ... } // 自动被包装
12595
+ * }
12596
+ * ```
12597
+ */
12598
+ declare function ProfileClass(category?: ProfileCategory): ClassDecorator;
11737
12599
 
11738
12600
  /**
11739
12601
  * 平台适配器接口
@@ -12008,5 +12870,5 @@ declare function getFullPlatformConfig(): Promise<any>;
12008
12870
  declare function supportsFeature(feature: 'worker' | 'shared-array-buffer' | 'transferable-objects' | 'module-worker'): boolean;
12009
12871
  declare function hasAdapter(): boolean;
12010
12872
 
12011
- export { BinarySerializer, BitMask64Utils, Bits, COMPONENT_DEPENDENCIES, COMPONENT_TYPE_NAME, ChangeOperation, Colors, Component, ComponentDataCollector, ComponentPool, ComponentPoolManager, ComponentRegistry, ComponentSerializer, ComponentSparseSet, ComponentStorage, ConsoleLogger, Core, DebugConfigService, DebugManager, DebugPlugin, DeepCopy, ECSComponent, ECSEventType, ECSFluentAPI, ECSSystem, ENTITY_REF_METADATA, EVENT_TYPES, Emitter, EnableSoA, Entity, EntityDataCollector, EntityList, EntityProcessorList, EntityRef, EntitySerializer, EntitySystem, EventBus, EventPriority, EventTypeValidator, Float32, Float64, FuncPack, GlobalEventBus, GlobalManager, IdentifierPool, IgnoreSerialization, IncrementalSerializer, InjectProperty, Injectable, Int16, Int32, Int8, IntervalSystem, LogLevel, Logger, LoggerManager, Matcher, MigrationBuilder, NumberExtension, PROPERTY_METADATA, PassiveSystem, PerformanceDataCollector, PerformanceMonitor, PerformanceWarningType, PlatformDetector, PlatformManager, PluginManager, PluginState, Pool, PoolManager, ProcessingSystem, Property, QuerySystem, ReactiveQuery, ReactiveQueryChangeType, ReferenceTracker, SERIALIZABLE_METADATA, SERIALIZE_FIELD, SERIALIZE_OPTIONS, SYSTEM_TYPE_NAME, Scene, SceneDataCollector, SceneManager, SceneSerializer, Serializable, Serialize, SerializeArray, SerializeAsMap, SerializeAsSet, SerializeMap, SerializeSet, ServiceContainer, ServiceLifetime, SoAStorage, SparseSet, SystemDataCollector, Time, Timer, TimerManager, TypeSafeEventSystem, TypeUtils, TypedEntityBuilder, TypedQueryBuilder, TypedQueryResult, Uint16, Uint32, Uint8, Uint8Clamped, Updatable, VersionMigrationManager, WebSocketManager, WorkerEntitySystem, World, WorldManager, addAndConfigure, buildEntity, createECSAPI, createInstance, createLogger, createQuery, getBasicWorkerConfig, getComponentDependencies, getComponentInstanceTypeName, getComponentTypeName, getComponents, getCurrentAdapter, getEntityRefMetadata, getFullPlatformConfig, getOrAddComponent, getPropertyInjectMetadata, getPropertyMetadata, getSceneByEntityId, getSerializationMetadata, getSystemInstanceTypeName, getSystemMetadata, getSystemTypeName, getUpdatableMetadata, hasAdapter, hasAnyComponent, hasComponents, hasEntityRef, hasPropertyMetadata, injectProperties, isComponentArray, isComponentType, isSerializable, isUpdatable, queryFor, queryForAll, registerInjectable, registerPlatformAdapter, requireComponent, resetLoggerColors, setGlobalLogLevel, setLoggerColors, setLoggerFactory, supportsFeature, tryGetComponent, updateComponent };
12012
- export type { AnyComponentConstructor, AssetType, BitMask64Data, ComponentChange, ComponentConstructor, ComponentDebugInfo, ComponentInstance, ComponentMigrationFunction, ComponentOptions, ComponentType$1 as ComponentType, ComponentTypeMap, ComponentTypeName, ComponentTypeNames, DataOnly, DeepPartial, DeepReadonly, DeserializationStrategy, ECSDebugStats, EntityChange, EntityDebugInfo, EntityRefMetadata, EntityRefRecord, EntityWithComponents, EnumOption, EventListenerConfig, EventStats, ExtractComponents, FieldSerializeOptions, IComponent, IComponentDebugData, IComponentEventData, ICoreConfig, IECSDebugConfig, IECSDebugData, IEntityDebugData, IEntityEventData, IEntityHierarchyNode, IEventBus, IEventData, IEventListenerConfig, IEventStats, ILogger, IPerformanceDebugData, IPerformanceEventData, IPlatformAdapter, IPlugin, IPluginMetadata, IPoolable, IScene, ISceneConfig, ISceneDebugData, ISceneEventData, ISceneFactory, IService, ISystemBase, ISystemDebugData, ISystemEventData, ITimer, IUpdatable, IWorldConfig, IWorldManagerConfig, IncrementalSerializationFormat, IncrementalSerializationOptions, IncrementalSnapshot, InjectableMetadata, LoggerColorConfig, LoggerConfig, MigrationFunction, PartialComponent, PerformanceData, PerformanceStats, PerformanceThresholds, PerformanceWarning, PlatformConfig, PlatformDetectionResult, PlatformWorker, PoolStats, PropertyAction, PropertyControl, PropertyOptions, PropertyType, QueryResult$1 as QueryResult, ReactiveQueryChange, ReactiveQueryConfig, ReactiveQueryListener, ReadonlyComponent, SceneDataChange, SceneDebugInfo, SceneDeserializationOptions, SceneMigrationFunction, SceneSerializationOptions, SerializableComponent, SerializableFields, SerializableOptions, SerializationFormat, SerializationMetadata, SerializedComponent, SerializedEntity, SerializedScene, ServiceIdentifier, ServiceType, SharedArrayBufferProcessFunction, SupportedTypedArray, SystemDebugInfo, SystemEntityType, SystemLifecycleHooks, SystemMetadata, TypeSafeBuilder, TypedEventHandler, TypedQueryCondition, UpdatableMetadata, ValidComponent, ValidComponentArray, WorkerCreationOptions, WorkerProcessFunction, WorkerSystemConfig };
12873
+ export { AdvancedProfilerCollector, AutoProfiler, BinarySerializer, BitMask64Utils, Bits, COMPONENT_DEPENDENCIES, COMPONENT_TYPE_NAME, ChangeOperation, Colors, Component, ComponentDataCollector, ComponentPool, ComponentPoolManager, ComponentRegistry, ComponentSerializer, ComponentSparseSet, ComponentStorage, ConsoleLogger, Core, DEFAULT_PROFILER_CONFIG, DebugConfigService, DebugManager, DebugPlugin, DeepCopy, ECSComponent, ECSEventType, ECSFluentAPI, ECSSystem, ENTITY_REF_METADATA, EVENT_TYPES, Emitter, EnableSoA, Entity, EntityDataCollector, EntityList, EntityProcessorList, EntityRef, EntitySerializer, EntitySystem, EntityTags, EventBus, EventPriority, EventTypeValidator, Float32, Float64, FuncPack, GlobalEventBus, GlobalManager, HierarchyComponent, HierarchySystem, IdentifierPool, IgnoreSerialization, IncrementalSerializer, InjectProperty, Injectable, Int16, Int32, Int8, IntervalSystem, LogLevel, Logger, LoggerManager, Matcher, MigrationBuilder, NumberExtension, PROPERTY_METADATA, PassiveSystem, PerformanceDataCollector, PerformanceMonitor, PerformanceWarningType, PlatformDetector, PlatformManager, PluginManager, PluginState, Pool, PoolManager, ProcessingSystem, Profile, ProfileCategory, ProfileClass, ProfilerSDK, Property, QuerySystem, ReactiveQuery, ReactiveQueryChangeType, ReferenceTracker, SERIALIZABLE_METADATA, SERIALIZE_FIELD, SERIALIZE_OPTIONS, SYSTEM_TYPE_NAME, Scene, SceneDataCollector, SceneManager, SceneSerializer, Serializable, Serialize, SerializeArray, SerializeAsMap, SerializeAsSet, SerializeMap, SerializeSet, ServiceContainer, ServiceLifetime, SoAStorage, SparseSet, SystemDataCollector, Time, Timer, TimerManager, TypeSafeEventSystem, TypeUtils, TypedEntityBuilder, TypedQueryBuilder, TypedQueryResult, Uint16, Uint32, Uint8, Uint8Clamped, Updatable, VersionMigrationManager, WebSocketManager, WorkerEntitySystem, World, WorldManager, addAndConfigure, addEntityTag, buildEntity, createECSAPI, createInstance, createLogger, createQuery, getBasicWorkerConfig, getComponentDependencies, getComponentInstanceTypeName, getComponentTypeName, getComponents, getCurrentAdapter, getEntityRefMetadata, getFullPlatformConfig, getOrAddComponent, getPropertyInjectMetadata, getPropertyMetadata, getSceneByEntityId, getSerializationMetadata, getSystemInstanceTypeName, getSystemMetadata, getSystemTypeName, getUpdatableMetadata, hasAdapter, hasAnyComponent, hasComponents, hasEntityRef, hasEntityTag, hasPropertyMetadata, injectProperties, isComponentArray, isComponentType, isFolder, isHidden, isLocked, isSerializable, isUpdatable, queryFor, queryForAll, registerInjectable, registerPlatformAdapter, removeEntityTag, requireComponent, resetLoggerColors, setGlobalLogLevel, setLoggerColors, setLoggerFactory, supportsFeature, tryGetComponent, updateComponent };
12874
+ export type { AnyComponentConstructor, AssetType, AutoProfilerConfig, BitMask64Data, CallGraphNode, ComponentChange, ComponentConstructor, ComponentDebugInfo, ComponentInstance, ComponentMigrationFunction, ComponentOptions, ComponentType$1 as ComponentType, ComponentTypeMap, ComponentTypeName, ComponentTypeNames, DataOnly, DeepPartial, DeepReadonly, DeserializationStrategy, ECSDebugStats, EntityChange, EntityDebugInfo, EntityRefMetadata, EntityRefRecord, EntityTagValue, EntityWithComponents, EnumOption, EventListenerConfig, EventStats, ExtractComponents, FieldSerializeOptions, IAdvancedProfilerData, IComponent, IComponentDebugData, IComponentEventData, ICoreConfig, IECSDebugConfig, IECSDebugData, IEntityDebugData, IEntityEventData, IEntityHierarchyNode, IEventBus, IEventData, IEventListenerConfig, IEventStats, ILogger, IPerformanceDebugData, IPerformanceEventData, IPlatformAdapter, IPlugin, IPluginMetadata, IPoolable, IScene, ISceneConfig, ISceneDebugData, ISceneEventData, ISceneFactory, IService, ISystemBase, ISystemDebugData, ISystemEventData, ITimer, IUpdatable, IWorldConfig, IWorldManagerConfig, IncrementalSerializationFormat, IncrementalSerializationOptions, IncrementalSnapshot, InjectableMetadata, LoggerColorConfig, LoggerConfig, LongTaskInfo, MemorySnapshot, MigrationFunction, PartialComponent, PerformanceData, PerformanceStats, PerformanceThresholds, PerformanceWarning, PlatformConfig, PlatformDetectionResult, PlatformWorker, PoolStats, ProfileCounter, ProfileFrame, ProfileReport, ProfileSample, ProfileSampleStats, ProfilerConfig, PropertyAction, PropertyControl, PropertyOptions, PropertyType, QueryResult$1 as QueryResult, ReactiveQueryChange, ReactiveQueryConfig, ReactiveQueryListener, ReadonlyComponent, SampleHandle, SceneDataChange, SceneDebugInfo, SceneDeserializationOptions, SceneMigrationFunction, SceneSerializationOptions, SerializableComponent, SerializableFields, SerializableOptions, SerializationFormat, SerializationMetadata, SerializedComponent, SerializedEntity, SerializedScene, ServiceIdentifier, ServiceType, SharedArrayBufferProcessFunction, SupportedTypedArray, SystemDebugInfo, SystemEntityType, SystemLifecycleHooks, SystemMetadata, TypeSafeBuilder, TypedEventHandler, TypedQueryCondition, UpdatableMetadata, ValidComponent, ValidComponentArray, WorkerCreationOptions, WorkerProcessFunction, WorkerSystemConfig };