@esengine/ecs-framework 2.1.33 → 2.1.34

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.1.33
2
+ * @esengine/ecs-framework v2.1.34
3
3
  * TypeScript definitions
4
4
  */
5
5
  /**
@@ -2954,7 +2954,7 @@ declare function EventHandler(eventType: string, config?: IEventListenerConfig):
2954
2954
  */
2955
2955
  declare function AsyncEventHandler(eventType: string, config?: IEventListenerConfig): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2956
2956
 
2957
- interface IScene {
2957
+ interface IScene$1 {
2958
2958
  readonly name: string;
2959
2959
  readonly componentStorageManager: ComponentStorageManager;
2960
2960
  readonly querySystem: QuerySystem;
@@ -3042,7 +3042,7 @@ declare class Entity {
3042
3042
  *
3043
3043
  * 指向实体所在的场景实例。
3044
3044
  */
3045
- scene: IScene | null;
3045
+ scene: IScene$1 | null;
3046
3046
  /**
3047
3047
  * 更新间隔
3048
3048
  *
@@ -3545,257 +3545,6 @@ declare class Matcher {
3545
3545
  toString(): string;
3546
3546
  }
3547
3547
 
3548
- /**
3549
- * 实体系统的基类
3550
- *
3551
- * 用于处理一组符合特定条件的实体。系统是ECS架构中的逻辑处理单元,
3552
- * 负责对拥有特定组件组合的实体执行业务逻辑。
3553
- *
3554
- * @example
3555
- * ```typescript
3556
- * class MovementSystem extends EntitySystem {
3557
- * constructor() {
3558
- * super(Transform, Velocity);
3559
- * }
3560
- *
3561
- * protected process(entities: Entity[]): void {
3562
- * for (const entity of entities) {
3563
- * const transform = entity.getComponent(Transform);
3564
- * const velocity = entity.getComponent(Velocity);
3565
- * transform.position.add(velocity.value);
3566
- * }
3567
- * }
3568
- * }
3569
- * ```
3570
- */
3571
- declare abstract class EntitySystem implements ISystemBase {
3572
- private _updateOrder;
3573
- private _enabled;
3574
- private _performanceMonitor;
3575
- private _systemName;
3576
- private _initialized;
3577
- private _matcher;
3578
- private _trackedEntities;
3579
- private _lastQueryResult;
3580
- /**
3581
- * 获取系统处理的实体列表(动态查询)
3582
- */
3583
- get entities(): readonly Entity[];
3584
- /**
3585
- * 获取系统的更新时序
3586
- */
3587
- get updateOrder(): number;
3588
- set updateOrder(value: number);
3589
- /**
3590
- * 获取系统的启用状态
3591
- */
3592
- get enabled(): boolean;
3593
- /**
3594
- * 设置系统的启用状态
3595
- */
3596
- set enabled(value: boolean);
3597
- /**
3598
- * 获取系统名称
3599
- */
3600
- get systemName(): string;
3601
- constructor(matcher?: Matcher);
3602
- private _scene;
3603
- /**
3604
- * 这个系统所属的场景
3605
- */
3606
- get scene(): Scene | null;
3607
- set scene(value: Scene | null);
3608
- /**
3609
- * 获取实体匹配器
3610
- */
3611
- get matcher(): Matcher;
3612
- /**
3613
- * 设置更新时序
3614
- * @param order 更新时序
3615
- */
3616
- setUpdateOrder(order: number): void;
3617
- /**
3618
- * 系统初始化(框架调用)
3619
- *
3620
- * 在系统创建时调用。框架内部使用,用户不应直接调用。
3621
- */
3622
- initialize(): void;
3623
- /**
3624
- * 系统初始化回调
3625
- *
3626
- * 子类可以重写此方法进行初始化操作。
3627
- */
3628
- protected onInitialize(): void;
3629
- /**
3630
- * 重置系统状态
3631
- *
3632
- * 当系统从场景中移除时调用,重置初始化状态以便重新添加时能正确初始化。
3633
- */
3634
- reset(): void;
3635
- /**
3636
- * 查询匹配的实体
3637
- */
3638
- private queryEntities;
3639
- /**
3640
- * 检查是否为单一条件查询
3641
- */
3642
- private isSingleCondition;
3643
- /**
3644
- * 执行单一条件查询
3645
- */
3646
- private executeSingleConditionQuery;
3647
- /**
3648
- * 执行复合查询
3649
- */
3650
- private executeComplexQuery;
3651
- /**
3652
- * 更新系统
3653
- *
3654
- * 在每帧调用,处理系统的主要逻辑。
3655
- */
3656
- update(): void;
3657
- /**
3658
- * 后期更新系统
3659
- *
3660
- * 在所有系统的update方法执行完毕后调用。
3661
- */
3662
- lateUpdate(): void;
3663
- /**
3664
- * 在系统处理开始前调用
3665
- *
3666
- * 子类可以重写此方法进行预处理操作。
3667
- */
3668
- protected onBegin(): void;
3669
- /**
3670
- * 处理实体列表
3671
- *
3672
- * 系统的核心逻辑,子类必须实现此方法来定义具体的处理逻辑。
3673
- *
3674
- * @param entities 要处理的实体列表
3675
- */
3676
- protected process(entities: Entity[]): void;
3677
- /**
3678
- * 后期处理实体列表
3679
- *
3680
- * 在主要处理逻辑之后执行,子类可以重写此方法。
3681
- *
3682
- * @param entities 要处理的实体列表
3683
- */
3684
- protected lateProcess(entities: Entity[]): void;
3685
- /**
3686
- * 系统处理完毕后调用
3687
- *
3688
- * 子类可以重写此方法进行后处理操作。
3689
- */
3690
- protected onEnd(): void;
3691
- /**
3692
- * 检查系统是否需要处理
3693
- *
3694
- * 在启用系统时有用,但仅偶尔需要处理。
3695
- * 这只影响处理,不影响事件或订阅列表。
3696
- *
3697
- * @returns 如果系统应该处理,则为true,如果不处理则为false
3698
- */
3699
- protected onCheckProcessing(): boolean;
3700
- /**
3701
- * 获取系统的性能数据
3702
- *
3703
- * @returns 性能数据或undefined
3704
- */
3705
- getPerformanceData(): PerformanceData | undefined;
3706
- /**
3707
- * 获取系统的性能统计
3708
- *
3709
- * @returns 性能统计或undefined
3710
- */
3711
- getPerformanceStats(): PerformanceStats | undefined;
3712
- /**
3713
- * 重置系统的性能数据
3714
- */
3715
- resetPerformanceData(): void;
3716
- /**
3717
- * 获取系统信息的字符串表示
3718
- *
3719
- * @returns 系统信息字符串
3720
- */
3721
- toString(): string;
3722
- /**
3723
- * 更新实体跟踪,检查新增和移除的实体
3724
- */
3725
- private updateEntityTracking;
3726
- /**
3727
- * 当实体被添加到系统时调用
3728
- *
3729
- * 子类可以重写此方法来处理实体添加事件。
3730
- *
3731
- * @param entity 被添加的实体
3732
- */
3733
- protected onAdded(_entity: Entity): void;
3734
- /**
3735
- * 当实体从系统中移除时调用
3736
- *
3737
- * 子类可以重写此方法来处理实体移除事件。
3738
- *
3739
- * @param entity 被移除的实体
3740
- */
3741
- protected onRemoved(_entity: Entity): void;
3742
- }
3743
-
3744
- /**
3745
- * 实体处理器列表管理器
3746
- * 管理场景中的所有实体系统
3747
- */
3748
- declare class EntityProcessorList {
3749
- private static readonly _logger;
3750
- private _processors;
3751
- private _isDirty;
3752
- /**
3753
- * 设置为脏状态,需要重新排序
3754
- */
3755
- setDirty(): void;
3756
- /**
3757
- * 添加实体处理器
3758
- * @param processor 要添加的处理器
3759
- */
3760
- add(processor: EntitySystem): void;
3761
- /**
3762
- * 移除实体处理器
3763
- * @param processor 要移除的处理器
3764
- */
3765
- remove(processor: EntitySystem): void;
3766
- /**
3767
- * 获取指定类型的处理器
3768
- * @param type 处理器类型
3769
- */
3770
- getProcessor<T extends EntitySystem>(type: new (...args: unknown[]) => T): T | null;
3771
- /**
3772
- * 开始处理
3773
- *
3774
- * 对所有处理器进行排序以确保正确的执行顺序。
3775
- */
3776
- begin(): void;
3777
- /**
3778
- * 结束处理
3779
- */
3780
- end(): void;
3781
- /**
3782
- * 更新所有处理器
3783
- */
3784
- update(): void;
3785
- /**
3786
- * 后期更新所有处理器
3787
- */
3788
- lateUpdate(): void;
3789
- /**
3790
- * 排序处理器
3791
- */
3792
- private sortProcessors;
3793
- /** 获取处理器列表 */
3794
- get processors(): EntitySystem[];
3795
- /** 获取处理器数量 */
3796
- get count(): number;
3797
- }
3798
-
3799
3548
  /**
3800
3549
  * 世代式ID池管理器
3801
3550
  *
@@ -3928,296 +3677,645 @@ declare class IdentifierPool {
3928
3677
  /**
3929
3678
  * 强制执行延迟回收处理
3930
3679
  *
3931
- * 在某些情况下可能需要立即处理延迟回收队列,
3932
- * 比如内存压力大或者需要精确的统计信息时。
3680
+ * 在某些情况下可能需要立即处理延迟回收队列,
3681
+ * 比如内存压力大或者需要精确的统计信息时。
3682
+ */
3683
+ forceProcessDelayedRecycle(): void;
3684
+ /**
3685
+ * 清理过期的延迟回收项
3686
+ *
3687
+ * 将超过延迟时间的回收项真正回收到空闲列表中。
3688
+ *
3689
+ * @param forceAll 是否强制处理所有延迟回收项
3690
+ * @private
3691
+ */
3692
+ private _processDelayedRecycle;
3693
+ /**
3694
+ * 预分配世代信息
3695
+ *
3696
+ * @param startIndex 起始索引
3697
+ * @param count 分配数量
3698
+ * @private
3699
+ */
3700
+ private _preAllocateGenerations;
3701
+ /**
3702
+ * 确保指定索引的世代信息存在
3703
+ *
3704
+ * @param index 索引
3705
+ * @private
3706
+ */
3707
+ private _ensureGenerationCapacity;
3708
+ /**
3709
+ * 计算内存使用量
3710
+ *
3711
+ * @returns 内存使用字节数
3712
+ * @private
3713
+ */
3714
+ private _calculateMemoryUsage;
3715
+ /**
3716
+ * 打包索引和世代为32位ID
3717
+ *
3718
+ * @param index 索引(16位)
3719
+ * @param generation 世代版本(16位)
3720
+ * @returns 打包后的32位ID
3721
+ * @private
3722
+ */
3723
+ private _packId;
3724
+ /**
3725
+ * 从ID中解包索引
3726
+ *
3727
+ * @param id 32位ID
3728
+ * @returns 索引部分(16位)
3729
+ * @private
3730
+ */
3731
+ private _unpackIndex;
3732
+ /**
3733
+ * 从ID中解包世代版本
3734
+ *
3735
+ * @param id 32位ID
3736
+ * @returns 世代版本部分(16位)
3737
+ * @private
3738
+ */
3739
+ private _unpackGeneration;
3740
+ /**
3741
+ * 内部ID有效性检查
3742
+ *
3743
+ * @param index 索引
3744
+ * @param generation 世代版本
3745
+ * @returns 是否有效
3746
+ * @private
3747
+ */
3748
+ private _isValidId;
3749
+ }
3750
+
3751
+ /**
3752
+ * 游戏场景默认实现类
3753
+ *
3754
+ * 实现IScene接口,提供场景的基础功能。
3755
+ * 推荐使用组合而非继承的方式来构建自定义场景。
3756
+ */
3757
+ declare class Scene implements IScene {
3758
+ /**
3759
+ * 场景名称
3760
+ *
3761
+ * 用于标识和调试的友好名称。
3762
+ */
3763
+ name: string;
3764
+ /**
3765
+ * 场景中的实体集合
3766
+ *
3767
+ * 管理场景内所有实体的生命周期。
3768
+ */
3769
+ readonly entities: EntityList;
3770
+ /**
3771
+ * 实体系统处理器集合
3772
+ *
3773
+ * 管理场景内所有实体系统的执行。
3774
+ */
3775
+ readonly entityProcessors: EntityProcessorList;
3776
+ /**
3777
+ * 实体ID池
3778
+ *
3779
+ * 用于分配和回收实体的唯一标识符。
3780
+ */
3781
+ readonly identifierPool: IdentifierPool;
3782
+ /**
3783
+ * 组件存储管理器
3784
+ *
3785
+ * 高性能的组件存储和查询系统。
3786
+ */
3787
+ readonly componentStorageManager: ComponentStorageManager;
3788
+ /**
3789
+ * 查询系统
3790
+ *
3791
+ * 基于位掩码的高性能实体查询系统。
3792
+ */
3793
+ readonly querySystem: QuerySystem;
3794
+ /**
3795
+ * 事件系统
3796
+ *
3797
+ * 类型安全的事件系统。
3798
+ */
3799
+ readonly eventSystem: TypeSafeEventSystem;
3800
+ /**
3801
+ * 场景是否已开始运行
3802
+ */
3803
+ private _didSceneBegin;
3804
+ /**
3805
+ * 获取系统列表(兼容性属性)
3806
+ */
3807
+ get systems(): EntitySystem[];
3808
+ /**
3809
+ * 创建场景实例
3810
+ */
3811
+ constructor(config?: ISceneConfig);
3812
+ /**
3813
+ * 初始化场景
3814
+ *
3815
+ * 在场景创建时调用,子类可以重写此方法来设置初始实体和组件。
3816
+ */
3817
+ initialize(): void;
3818
+ /**
3819
+ * 场景开始运行时的回调
3820
+ *
3821
+ * 在场景开始运行时调用,可以在此方法中执行场景启动逻辑。
3822
+ */
3823
+ onStart(): void;
3824
+ /**
3825
+ * 场景卸载时的回调
3826
+ *
3827
+ * 在场景被销毁时调用,可以在此方法中执行清理工作。
3828
+ */
3829
+ unload(): void;
3830
+ /**
3831
+ * 开始场景,启动实体处理器等
3832
+ *
3833
+ * 这个方法会启动场景。它将启动实体处理器等,并调用onStart方法。
3834
+ */
3835
+ begin(): void;
3836
+ /**
3837
+ * 结束场景,清除实体、实体处理器等
3838
+ *
3839
+ * 这个方法会结束场景。它将移除所有实体,结束实体处理器等,并调用unload方法。
3840
+ */
3841
+ end(): void;
3842
+ /**
3843
+ * 更新场景,更新实体组件、实体处理器等
3844
+ */
3845
+ update(): void;
3846
+ /**
3847
+ * 将实体添加到此场景,并返回它
3848
+ * @param name 实体名称
3849
+ */
3850
+ createEntity(name: string): Entity;
3851
+ /**
3852
+ * 在场景的实体列表中添加一个实体
3853
+ * @param entity 要添加的实体
3854
+ * @param deferCacheClear 是否延迟缓存清理(用于批量操作)
3855
+ */
3856
+ addEntity(entity: Entity, deferCacheClear?: boolean): Entity;
3857
+ /**
3858
+ * 批量创建实体(高性能版本)
3859
+ * @param count 要创建的实体数量
3860
+ * @param namePrefix 实体名称前缀
3861
+ * @returns 创建的实体列表
3862
+ */
3863
+ createEntities(count: number, namePrefix?: string): Entity[];
3864
+ /**
3865
+ * 从场景中删除所有实体
3866
+ */
3867
+ destroyAllEntities(): void;
3868
+ /**
3869
+ * 搜索并返回第一个具有名称的实体
3870
+ * @param name 实体名称
3871
+ */
3872
+ findEntity(name: string): Entity | null;
3873
+ /**
3874
+ * 根据ID查找实体
3875
+ * @param id 实体ID
3876
+ */
3877
+ findEntityById(id: number): Entity | null;
3878
+ /**
3879
+ * 根据标签查找实体
3880
+ * @param tag 实体标签
3881
+ */
3882
+ findEntitiesByTag(tag: number): Entity[];
3883
+ /**
3884
+ * 根据名称查找实体(别名方法)
3885
+ * @param name 实体名称
3886
+ */
3887
+ getEntityByName(name: string): Entity | null;
3888
+ /**
3889
+ * 根据标签查找实体(别名方法)
3890
+ * @param tag 实体标签
3891
+ */
3892
+ getEntitiesByTag(tag: number): Entity[];
3893
+ /**
3894
+ * 在场景中添加一个EntitySystem处理器
3895
+ * @param processor 处理器
3896
+ */
3897
+ addEntityProcessor(processor: EntitySystem): EntitySystem;
3898
+ /**
3899
+ * 添加系统到场景(addEntityProcessor的别名)
3900
+ * @param system 系统
3901
+ */
3902
+ addSystem(system: EntitySystem): EntitySystem;
3903
+ /**
3904
+ * 从场景中删除EntitySystem处理器
3905
+ * @param processor 要删除的处理器
3906
+ */
3907
+ removeEntityProcessor(processor: EntitySystem): void;
3908
+ /**
3909
+ * 获取指定类型的EntitySystem处理器
3910
+ * @param type 处理器类型
3911
+ */
3912
+ getEntityProcessor<T extends EntitySystem>(type: new (...args: unknown[]) => T): T | null;
3913
+ /**
3914
+ * 获取场景统计信息
3915
+ */
3916
+ getStats(): {
3917
+ entityCount: number;
3918
+ processorCount: number;
3919
+ componentStorageStats: Map<string, any>;
3920
+ };
3921
+ /**
3922
+ * 压缩组件存储(清理碎片)
3923
+ */
3924
+ compactComponentStorage(): void;
3925
+ /**
3926
+ * 获取场景的调试信息
3927
+ */
3928
+ getDebugInfo(): {
3929
+ name: string;
3930
+ entityCount: number;
3931
+ processorCount: number;
3932
+ isRunning: boolean;
3933
+ entities: Array<{
3934
+ name: string;
3935
+ id: number;
3936
+ componentCount: number;
3937
+ componentTypes: string[];
3938
+ }>;
3939
+ processors: Array<{
3940
+ name: string;
3941
+ updateOrder: number;
3942
+ entityCount: number;
3943
+ }>;
3944
+ componentStats: Map<string, any>;
3945
+ };
3946
+ }
3947
+
3948
+ /**
3949
+ * 实体系统的基类
3950
+ *
3951
+ * 用于处理一组符合特定条件的实体。系统是ECS架构中的逻辑处理单元,
3952
+ * 负责对拥有特定组件组合的实体执行业务逻辑。
3953
+ *
3954
+ * @example
3955
+ * ```typescript
3956
+ * class MovementSystem extends EntitySystem {
3957
+ * constructor() {
3958
+ * super(Transform, Velocity);
3959
+ * }
3960
+ *
3961
+ * protected process(entities: Entity[]): void {
3962
+ * for (const entity of entities) {
3963
+ * const transform = entity.getComponent(Transform);
3964
+ * const velocity = entity.getComponent(Velocity);
3965
+ * transform.position.add(velocity.value);
3966
+ * }
3967
+ * }
3968
+ * }
3969
+ * ```
3970
+ */
3971
+ declare abstract class EntitySystem implements ISystemBase {
3972
+ private _updateOrder;
3973
+ private _enabled;
3974
+ private _performanceMonitor;
3975
+ private _systemName;
3976
+ private _initialized;
3977
+ private _matcher;
3978
+ private _trackedEntities;
3979
+ private _lastQueryResult;
3980
+ /**
3981
+ * 获取系统处理的实体列表(动态查询)
3982
+ */
3983
+ get entities(): readonly Entity[];
3984
+ /**
3985
+ * 获取系统的更新时序
3986
+ */
3987
+ get updateOrder(): number;
3988
+ set updateOrder(value: number);
3989
+ /**
3990
+ * 获取系统的启用状态
3991
+ */
3992
+ get enabled(): boolean;
3993
+ /**
3994
+ * 设置系统的启用状态
3995
+ */
3996
+ set enabled(value: boolean);
3997
+ /**
3998
+ * 获取系统名称
3999
+ */
4000
+ get systemName(): string;
4001
+ constructor(matcher?: Matcher);
4002
+ private _scene;
4003
+ /**
4004
+ * 这个系统所属的场景
4005
+ */
4006
+ get scene(): Scene | null;
4007
+ set scene(value: Scene | null);
4008
+ /**
4009
+ * 获取实体匹配器
4010
+ */
4011
+ get matcher(): Matcher;
4012
+ /**
4013
+ * 设置更新时序
4014
+ * @param order 更新时序
4015
+ */
4016
+ setUpdateOrder(order: number): void;
4017
+ /**
4018
+ * 系统初始化(框架调用)
4019
+ *
4020
+ * 在系统创建时调用。框架内部使用,用户不应直接调用。
4021
+ */
4022
+ initialize(): void;
4023
+ /**
4024
+ * 系统初始化回调
4025
+ *
4026
+ * 子类可以重写此方法进行初始化操作。
4027
+ */
4028
+ protected onInitialize(): void;
4029
+ /**
4030
+ * 重置系统状态
4031
+ *
4032
+ * 当系统从场景中移除时调用,重置初始化状态以便重新添加时能正确初始化。
4033
+ */
4034
+ reset(): void;
4035
+ /**
4036
+ * 查询匹配的实体
4037
+ */
4038
+ private queryEntities;
4039
+ /**
4040
+ * 检查是否为单一条件查询
4041
+ */
4042
+ private isSingleCondition;
4043
+ /**
4044
+ * 执行单一条件查询
4045
+ */
4046
+ private executeSingleConditionQuery;
4047
+ /**
4048
+ * 执行复合查询
4049
+ */
4050
+ private executeComplexQuery;
4051
+ /**
4052
+ * 更新系统
4053
+ *
4054
+ * 在每帧调用,处理系统的主要逻辑。
4055
+ */
4056
+ update(): void;
4057
+ /**
4058
+ * 后期更新系统
4059
+ *
4060
+ * 在所有系统的update方法执行完毕后调用。
4061
+ */
4062
+ lateUpdate(): void;
4063
+ /**
4064
+ * 在系统处理开始前调用
4065
+ *
4066
+ * 子类可以重写此方法进行预处理操作。
4067
+ */
4068
+ protected onBegin(): void;
4069
+ /**
4070
+ * 处理实体列表
4071
+ *
4072
+ * 系统的核心逻辑,子类必须实现此方法来定义具体的处理逻辑。
4073
+ *
4074
+ * @param entities 要处理的实体列表
4075
+ */
4076
+ protected process(entities: Entity[]): void;
4077
+ /**
4078
+ * 后期处理实体列表
4079
+ *
4080
+ * 在主要处理逻辑之后执行,子类可以重写此方法。
4081
+ *
4082
+ * @param entities 要处理的实体列表
4083
+ */
4084
+ protected lateProcess(entities: Entity[]): void;
4085
+ /**
4086
+ * 系统处理完毕后调用
4087
+ *
4088
+ * 子类可以重写此方法进行后处理操作。
4089
+ */
4090
+ protected onEnd(): void;
4091
+ /**
4092
+ * 检查系统是否需要处理
4093
+ *
4094
+ * 在启用系统时有用,但仅偶尔需要处理。
4095
+ * 这只影响处理,不影响事件或订阅列表。
4096
+ *
4097
+ * @returns 如果系统应该处理,则为true,如果不处理则为false
4098
+ */
4099
+ protected onCheckProcessing(): boolean;
4100
+ /**
4101
+ * 获取系统的性能数据
4102
+ *
4103
+ * @returns 性能数据或undefined
4104
+ */
4105
+ getPerformanceData(): PerformanceData | undefined;
4106
+ /**
4107
+ * 获取系统的性能统计
4108
+ *
4109
+ * @returns 性能统计或undefined
4110
+ */
4111
+ getPerformanceStats(): PerformanceStats | undefined;
4112
+ /**
4113
+ * 重置系统的性能数据
4114
+ */
4115
+ resetPerformanceData(): void;
4116
+ /**
4117
+ * 获取系统信息的字符串表示
4118
+ *
4119
+ * @returns 系统信息字符串
4120
+ */
4121
+ toString(): string;
4122
+ /**
4123
+ * 更新实体跟踪,检查新增和移除的实体
4124
+ */
4125
+ private updateEntityTracking;
4126
+ /**
4127
+ * 当实体被添加到系统时调用
4128
+ *
4129
+ * 子类可以重写此方法来处理实体添加事件。
4130
+ *
4131
+ * @param entity 被添加的实体
3933
4132
  */
3934
- forceProcessDelayedRecycle(): void;
4133
+ protected onAdded(_entity: Entity): void;
3935
4134
  /**
3936
- * 清理过期的延迟回收项
4135
+ * 当实体从系统中移除时调用
3937
4136
  *
3938
- * 将超过延迟时间的回收项真正回收到空闲列表中。
4137
+ * 子类可以重写此方法来处理实体移除事件。
3939
4138
  *
3940
- * @param forceAll 是否强制处理所有延迟回收项
3941
- * @private
4139
+ * @param entity 被移除的实体
3942
4140
  */
3943
- private _processDelayedRecycle;
4141
+ protected onRemoved(_entity: Entity): void;
4142
+ }
4143
+
4144
+ /**
4145
+ * 实体处理器列表管理器
4146
+ * 管理场景中的所有实体系统
4147
+ */
4148
+ declare class EntityProcessorList {
4149
+ private static readonly _logger;
4150
+ private _processors;
4151
+ private _isDirty;
3944
4152
  /**
3945
- * 预分配世代信息
3946
- *
3947
- * @param startIndex 起始索引
3948
- * @param count 分配数量
3949
- * @private
4153
+ * 设置为脏状态,需要重新排序
3950
4154
  */
3951
- private _preAllocateGenerations;
4155
+ setDirty(): void;
3952
4156
  /**
3953
- * 确保指定索引的世代信息存在
3954
- *
3955
- * @param index 索引
3956
- * @private
4157
+ * 添加实体处理器
4158
+ * @param processor 要添加的处理器
3957
4159
  */
3958
- private _ensureGenerationCapacity;
4160
+ add(processor: EntitySystem): void;
3959
4161
  /**
3960
- * 计算内存使用量
3961
- *
3962
- * @returns 内存使用字节数
3963
- * @private
4162
+ * 移除实体处理器
4163
+ * @param processor 要移除的处理器
3964
4164
  */
3965
- private _calculateMemoryUsage;
4165
+ remove(processor: EntitySystem): void;
3966
4166
  /**
3967
- * 打包索引和世代为32位ID
3968
- *
3969
- * @param index 索引(16位)
3970
- * @param generation 世代版本(16位)
3971
- * @returns 打包后的32位ID
3972
- * @private
4167
+ * 获取指定类型的处理器
4168
+ * @param type 处理器类型
3973
4169
  */
3974
- private _packId;
4170
+ getProcessor<T extends EntitySystem>(type: new (...args: unknown[]) => T): T | null;
3975
4171
  /**
3976
- * 从ID中解包索引
4172
+ * 开始处理
3977
4173
  *
3978
- * @param id 32位ID
3979
- * @returns 索引部分(16位)
3980
- * @private
4174
+ * 对所有处理器进行排序以确保正确的执行顺序。
3981
4175
  */
3982
- private _unpackIndex;
4176
+ begin(): void;
3983
4177
  /**
3984
- * 从ID中解包世代版本
3985
- *
3986
- * @param id 32位ID
3987
- * @returns 世代版本部分(16位)
3988
- * @private
4178
+ * 结束处理
3989
4179
  */
3990
- private _unpackGeneration;
4180
+ end(): void;
3991
4181
  /**
3992
- * 内部ID有效性检查
3993
- *
3994
- * @param index 索引
3995
- * @param generation 世代版本
3996
- * @returns 是否有效
3997
- * @private
4182
+ * 更新所有处理器
3998
4183
  */
3999
- private _isValidId;
4184
+ update(): void;
4185
+ /**
4186
+ * 后期更新所有处理器
4187
+ */
4188
+ lateUpdate(): void;
4189
+ /**
4190
+ * 排序处理器
4191
+ */
4192
+ private sortProcessors;
4193
+ /** 获取处理器列表 */
4194
+ get processors(): EntitySystem[];
4195
+ /** 获取处理器数量 */
4196
+ get count(): number;
4000
4197
  }
4001
4198
 
4002
4199
  /**
4003
- * 游戏场景类
4200
+ * 场景接口定义
4004
4201
  *
4005
- * 管理游戏场景中的所有实体和系统,提供场景生命周期管理。
4006
- * 场景是游戏世界的容器,负责协调实体和系统的运行。
4007
- *
4008
- * @example
4009
- * ```typescript
4010
- * class GameScene extends Scene {
4011
- * public initialize(): void {
4012
- * // 创建游戏实体
4013
- * const player = this.createEntity("Player");
4014
- *
4015
- * // 添加系统
4016
- * this.addEntityProcessor(new MovementSystem());
4017
- * }
4018
- * }
4019
- * ```
4202
+ * 定义场景应该实现的核心功能和属性,使用接口而非继承提供更灵活的实现方式。
4020
4203
  */
4021
- declare class Scene {
4204
+ interface IScene {
4022
4205
  /**
4023
4206
  * 场景名称
4024
- *
4025
- * 用于标识和调试的友好名称。
4026
4207
  */
4027
4208
  name: string;
4028
4209
  /**
4029
4210
  * 场景中的实体集合
4030
- *
4031
- * 管理场景内所有实体的生命周期。
4032
4211
  */
4033
4212
  readonly entities: EntityList;
4034
4213
  /**
4035
4214
  * 实体系统处理器集合
4036
- *
4037
- * 管理场景内所有实体系统的执行。
4038
4215
  */
4039
4216
  readonly entityProcessors: EntityProcessorList;
4040
4217
  /**
4041
- * 实体ID池
4042
- *
4043
- * 用于分配和回收实体的唯一标识符。
4218
+ * 标识符池
4044
4219
  */
4045
4220
  readonly identifierPool: IdentifierPool;
4046
4221
  /**
4047
4222
  * 组件存储管理器
4048
- *
4049
- * 高性能的组件存储和查询系统。
4050
4223
  */
4051
4224
  readonly componentStorageManager: ComponentStorageManager;
4052
4225
  /**
4053
4226
  * 查询系统
4054
- *
4055
- * 基于位掩码的高性能实体查询系统。
4056
4227
  */
4057
4228
  readonly querySystem: QuerySystem;
4058
4229
  /**
4059
4230
  * 事件系统
4060
- *
4061
- * 类型安全的事件系统。
4062
4231
  */
4063
4232
  readonly eventSystem: TypeSafeEventSystem;
4064
4233
  /**
4065
- * 场景是否已开始运行
4066
- */
4067
- private _didSceneBegin;
4068
- /**
4069
- * 场景是否已初始化
4070
- */
4071
- private _isInitialized;
4072
- /**
4073
- * 获取系统列表(兼容性属性)
4074
- */
4075
- get systems(): EntitySystem[];
4076
- /**
4077
- * 创建场景实例
4234
+ * 获取系统列表
4078
4235
  */
4079
- constructor();
4236
+ readonly systems: EntitySystem[];
4080
4237
  /**
4081
4238
  * 初始化场景
4082
- *
4083
- * 在场景创建时调用,子类可以重写此方法来设置初始实体和组件。
4084
4239
  */
4085
4240
  initialize(): void;
4086
4241
  /**
4087
4242
  * 场景开始运行时的回调
4088
- *
4089
- * 在场景开始运行时调用,可以在此方法中执行场景启动逻辑。
4090
4243
  */
4091
4244
  onStart(): void;
4092
4245
  /**
4093
4246
  * 场景卸载时的回调
4094
- *
4095
- * 在场景被销毁时调用,可以在此方法中执行清理工作。
4096
4247
  */
4097
4248
  unload(): void;
4098
4249
  /**
4099
- * 开始场景,启动实体处理器等
4100
- *
4101
- * 这个方法会启动场景。它将启动实体处理器等,并调用onStart方法。
4250
+ * 开始场景
4102
4251
  */
4103
4252
  begin(): void;
4104
4253
  /**
4105
- * 结束场景,清除实体、实体处理器等
4106
- *
4107
- * 这个方法会结束场景。它将移除所有实体,结束实体处理器等,并调用unload方法。
4254
+ * 结束场景
4108
4255
  */
4109
4256
  end(): void;
4110
4257
  /**
4111
- * 更新场景,更新实体组件、实体处理器等
4258
+ * 更新场景
4112
4259
  */
4113
4260
  update(): void;
4114
4261
  /**
4115
- * 将实体添加到此场景,并返回它
4116
- * @param name 实体名称
4262
+ * 创建实体
4117
4263
  */
4118
4264
  createEntity(name: string): Entity;
4119
4265
  /**
4120
- * 在场景的实体列表中添加一个实体
4121
- * @param entity 要添加的实体
4122
- * @param deferCacheClear 是否延迟缓存清理(用于批量操作)
4266
+ * 添加实体
4123
4267
  */
4124
4268
  addEntity(entity: Entity, deferCacheClear?: boolean): Entity;
4125
- /**
4126
- * 批量创建实体(高性能版本)
4127
- * @param count 要创建的实体数量
4128
- * @param namePrefix 实体名称前缀
4129
- * @returns 创建的实体列表
4130
- */
4131
- createEntities(count: number, namePrefix?: string): Entity[];
4132
4269
  /**
4133
4270
  * 批量创建实体
4134
- * @param count 要创建的实体数量
4135
- * @param namePrefix 实体名称前缀
4136
- * @returns 创建的实体列表
4137
4271
  */
4138
- createEntitiesOld(count: number, namePrefix?: string): Entity[];
4272
+ createEntities(count: number, namePrefix?: string): Entity[];
4139
4273
  /**
4140
- * 从场景中删除所有实体
4274
+ * 销毁所有实体
4141
4275
  */
4142
4276
  destroyAllEntities(): void;
4143
4277
  /**
4144
- * 搜索并返回第一个具有名称的实体
4145
- * @param name 实体名称
4278
+ * 查找实体
4146
4279
  */
4147
4280
  findEntity(name: string): Entity | null;
4148
- /**
4149
- * 根据ID查找实体
4150
- * @param id 实体ID
4151
- */
4152
- findEntityById(id: number): Entity | null;
4153
4281
  /**
4154
4282
  * 根据标签查找实体
4155
- * @param tag 实体标签
4156
4283
  */
4157
4284
  findEntitiesByTag(tag: number): Entity[];
4158
4285
  /**
4159
- * 根据名称查找实体(别名方法)
4160
- * @param name 实体名称
4161
- */
4162
- getEntityByName(name: string): Entity | null;
4163
- /**
4164
- * 根据标签查找实体(别名方法)
4165
- * @param tag 实体标签
4166
- */
4167
- getEntitiesByTag(tag: number): Entity[];
4168
- /**
4169
- * 在场景中添加一个EntitySystem处理器
4170
- * @param processor 处理器
4286
+ * 添加实体处理器
4171
4287
  */
4172
4288
  addEntityProcessor(processor: EntitySystem): EntitySystem;
4173
4289
  /**
4174
- * 添加系统到场景(addEntityProcessor的别名)
4175
- * @param system 系统
4176
- */
4177
- addSystem(system: EntitySystem): EntitySystem;
4178
- /**
4179
- * 从场景中删除EntitySystem处理器
4180
- * @param processor 要删除的处理器
4290
+ * 移除实体处理器
4181
4291
  */
4182
4292
  removeEntityProcessor(processor: EntitySystem): void;
4183
4293
  /**
4184
- * 获取指定类型的EntitySystem处理器
4185
- * @param type 处理器类型
4294
+ * 获取实体处理器
4186
4295
  */
4187
- getEntityProcessor<T extends EntitySystem>(type: new (...args: unknown[]) => T): T | null;
4296
+ getEntityProcessor<T extends EntitySystem>(type: new (...args: any[]) => T): T | null;
4297
+ }
4298
+ /**
4299
+ * 场景工厂接口
4300
+ */
4301
+ interface ISceneFactory<T extends IScene> {
4188
4302
  /**
4189
- * 获取场景统计信息
4303
+ * 创建场景实例
4190
4304
  */
4191
- getStats(): {
4192
- entityCount: number;
4193
- processorCount: number;
4194
- componentStorageStats: Map<string, any>;
4195
- };
4305
+ createScene(): T;
4306
+ }
4307
+ /**
4308
+ * 场景配置接口
4309
+ */
4310
+ interface ISceneConfig {
4196
4311
  /**
4197
- * 压缩组件存储(清理碎片)
4312
+ * 场景名称
4198
4313
  */
4199
- compactComponentStorage(): void;
4314
+ name?: string;
4200
4315
  /**
4201
- * 获取场景的调试信息
4316
+ * 调试配置
4202
4317
  */
4203
- getDebugInfo(): {
4204
- name: string;
4205
- entityCount: number;
4206
- processorCount: number;
4207
- isRunning: boolean;
4208
- entities: Array<{
4209
- name: string;
4210
- id: number;
4211
- componentCount: number;
4212
- componentTypes: string[];
4213
- }>;
4214
- processors: Array<{
4215
- name: string;
4216
- updateOrder: number;
4217
- entityCount: number;
4218
- }>;
4219
- componentStats: Map<string, any>;
4220
- };
4318
+ debug?: boolean;
4221
4319
  }
4222
4320
 
4223
4321
  /**
@@ -4227,7 +4325,7 @@ declare class EntityBuilder {
4227
4325
  private entity;
4228
4326
  private scene;
4229
4327
  private storageManager;
4230
- constructor(scene: Scene, storageManager: ComponentStorageManager);
4328
+ constructor(scene: IScene, storageManager: ComponentStorageManager);
4231
4329
  /**
4232
4330
  * 设置实体名称
4233
4331
  * @param name 实体名称
@@ -4472,7 +4570,7 @@ declare class ECSFluentAPI {
4472
4570
  private scene;
4473
4571
  private querySystem;
4474
4572
  private eventSystem;
4475
- constructor(scene: Scene, querySystem: QuerySystem, eventSystem: TypeSafeEventSystem);
4573
+ constructor(scene: IScene, querySystem: QuerySystem, eventSystem: TypeSafeEventSystem);
4476
4574
  /**
4477
4575
  * 创建实体构建器
4478
4576
  * @returns 实体构建器
@@ -4564,9 +4662,9 @@ declare class ECSFluentAPI {
4564
4662
  getStats(): {
4565
4663
  entityCount: number;
4566
4664
  systemCount: number;
4567
- componentStats: Map<string, any>;
4665
+ componentStats: Map<string, unknown>;
4568
4666
  queryStats: unknown;
4569
- eventStats: Map<string, any>;
4667
+ eventStats: Map<string, unknown>;
4570
4668
  };
4571
4669
  }
4572
4670
  /**
@@ -4576,7 +4674,7 @@ declare class ECSFluentAPI {
4576
4674
  * @param eventSystem 事件系统
4577
4675
  * @returns ECS流式API实例
4578
4676
  */
4579
- declare function createECSAPI(scene: Scene, querySystem: QuerySystem, eventSystem: TypeSafeEventSystem): ECSFluentAPI;
4677
+ declare function createECSAPI(scene: IScene, querySystem: QuerySystem, eventSystem: TypeSafeEventSystem): ECSFluentAPI;
4580
4678
 
4581
4679
  /**
4582
4680
  * 实体数据收集器
@@ -4894,10 +4992,6 @@ declare class DebugManager {
4894
4992
  * 收集性能统计信息
4895
4993
  */
4896
4994
  private collectPerformanceStats;
4897
- /**
4898
- * 获取内存大小分类
4899
- */
4900
- private getMemorySizeCategory;
4901
4995
  /**
4902
4996
  * 获取调试数据
4903
4997
  */
@@ -4970,7 +5064,7 @@ declare class Core {
4970
5064
  *
4971
5065
  * 存储下一帧要切换到的场景实例。
4972
5066
  */
4973
- _nextScene: Scene | null;
5067
+ _nextScene: IScene | null;
4974
5068
  /**
4975
5069
  * 全局管理器集合
4976
5070
  *
@@ -5004,7 +5098,7 @@ declare class Core {
5004
5098
  /**
5005
5099
  * 当前活动场景
5006
5100
  */
5007
- _scene?: Scene;
5101
+ _scene?: IScene;
5008
5102
  /**
5009
5103
  * 调试管理器
5010
5104
  *
@@ -5036,16 +5130,54 @@ declare class Core {
5036
5130
  *
5037
5131
  * @returns 当前场景实例,如果没有则返回null
5038
5132
  */
5039
- static get scene(): Scene | null;
5133
+ static get scene(): IScene | null;
5134
+ /**
5135
+ * 设置当前场景(已废弃)
5136
+ *
5137
+ * @deprecated 请使用 Core.setScene() 方法代替。scene setter 可能导致场景延迟激活的时序问题,
5138
+ * 而 setScene() 提供更好的类型安全性和可预测的激活时序。
5139
+ *
5140
+ * 迁移示例:
5141
+ * ```typescript
5142
+ * // 旧方式(已废弃)
5143
+ * Core.scene = myScene;
5144
+ *
5145
+ * // 新方式(推荐)
5146
+ * Core.setScene(myScene);
5147
+ * ```
5148
+ *
5149
+ * 如果当前没有场景,会立即切换;否则会在下一帧切换。
5150
+ *
5151
+ * @param value - 场景实例
5152
+ */
5153
+ static set scene(value: IScene | null);
5040
5154
  /**
5041
- * 设置当前活动的场景
5155
+ * 类型安全的场景设置方法(推荐)
5156
+ *
5157
+ * 这是设置场景的推荐方法,提供更好的类型安全性和可预测的激活时序。
5158
+ * 相比于 scene setter,此方法能确保场景正确初始化和激活。
5042
5159
  *
5043
5160
  * 如果当前没有场景,会立即切换;否则会在下一帧切换。
5044
5161
  *
5045
- * @param value - 要设置的场景实例
5046
- * @throws {Error} 当场景为空时抛出错误
5162
+ * @param scene - 要设置的场景实例
5163
+ * @returns 设置的场景实例,便于链式调用
5164
+ *
5165
+ * @example
5166
+ * ```typescript
5167
+ * const myScene = new MyScene();
5168
+ * Core.setScene(myScene);
5169
+ *
5170
+ * // 链式调用
5171
+ * const scene = Core.setScene(new MyScene()).addSystem(new MySystem());
5172
+ * ```
5173
+ */
5174
+ static setScene<T extends IScene>(scene: T): T;
5175
+ /**
5176
+ * 类型安全的场景获取方法
5177
+ *
5178
+ * @returns 当前场景实例
5047
5179
  */
5048
- static set scene(value: Scene | null);
5180
+ static getScene<T extends IScene>(): T | null;
5049
5181
  /**
5050
5182
  * 创建Core实例
5051
5183
  *
@@ -5113,7 +5245,7 @@ declare class Core {
5113
5245
  * @param onTime - 定时器触发时的回调函数
5114
5246
  * @returns 创建的定时器实例
5115
5247
  */
5116
- static schedule<TContext = unknown>(timeInSeconds: number, repeats: boolean | undefined, context: TContext | undefined, onTime: (timer: ITimer<TContext>) => void): Timer<TContext>;
5248
+ static schedule<TContext = unknown>(timeInSeconds: number, repeats?: boolean, context?: TContext, onTime?: (timer: ITimer<TContext>) => void): Timer<TContext>;
5117
5249
  /**
5118
5250
  * 获取ECS流式API
5119
5251
  *
@@ -5135,7 +5267,7 @@ declare class Core {
5135
5267
  *
5136
5268
  * @returns 当前调试数据,如果调试未启用则返回null
5137
5269
  */
5138
- static getDebugData(): any;
5270
+ static getDebugData(): unknown;
5139
5271
  /**
5140
5272
  * 检查调试是否启用
5141
5273
  *
@@ -5154,6 +5286,12 @@ declare class Core {
5154
5286
  * @returns 是否支持BigInt
5155
5287
  */
5156
5288
  static get supportsBigInt(): boolean;
5289
+ /**
5290
+ * 内部场景设置方法
5291
+ *
5292
+ * @param scene - 要设置的场景实例
5293
+ */
5294
+ private setSceneInternal;
5157
5295
  /**
5158
5296
  * 场景切换回调
5159
5297
  *
@@ -6358,4 +6496,4 @@ declare class Time {
6358
6496
  }
6359
6497
 
6360
6498
  export { ArchetypeSystem, AsyncEventHandler, BigIntFactory, BitmapComponentIndex, Bits, Component, ComponentDataCollector, ComponentIndexManager, ComponentPool, ComponentPoolManager, ComponentRegistry, ComponentStorage, ComponentTypeManager, ConsoleLogger, Core, DebugManager, DirtyFlag, DirtyTrackingSystem, ECSEventType, ECSFluentAPI, EVENT_TYPES, Emitter, EnableSoA, Entity, EntityDataCollector, EntityList, EntityManager, EntityProcessorList, EntityQueryBuilder, EntitySystem, EventBus, EventHandler, EventPriority, EventTypeValidator, Float32, Float64, FuncPack, GlobalEventBus, GlobalManager, HashComponentIndex, HighPrecision, IdentifierPool, IndexType, Int32, IntervalSystem, LogLevel, Logger, LoggerManager, Matcher, NumberExtension, PassiveSystem, PerformanceDataCollector, PerformanceMonitor, PerformanceWarningType, Pool, PoolManager, ProcessingSystem, QuerySystem, Scene, SceneDataCollector, SerializeMap, SoAStorage, SystemDataCollector, Time, Timer, TimerManager, TypeSafeEventSystem, TypeUtils, WebSocketManager, createECSAPI, createLogger, setGlobalLogLevel };
6361
- export type { Archetype, ArchetypeQueryResult, ComponentType$1 as ComponentType, DirtyData, DirtyListener, EventListenerConfig, EventStats, IComponent, IComponentDebugData, IComponentEventData, ICoreConfig, IECSDebugConfig, IECSDebugData, IEntityDebugData, IEntityEventData, IEntityHierarchyNode, IEventBus, IEventData, IEventListenerConfig, IEventStats, ILogger, IPerformanceDebugData, IPerformanceEventData, IPoolable, ISceneDebugData, ISceneEventData, ISystemBase, ISystemDebugData, ISystemEventData, ITimer, LoggerConfig, PerformanceData, PerformanceStats, PerformanceThresholds, PerformanceWarning, PoolStats };
6499
+ export type { Archetype, ArchetypeQueryResult, ComponentType$1 as ComponentType, DirtyData, DirtyListener, EventListenerConfig, EventStats, IComponent, IComponentDebugData, IComponentEventData, ICoreConfig, IECSDebugConfig, IECSDebugData, IEntityDebugData, IEntityEventData, IEntityHierarchyNode, IEventBus, IEventData, IEventListenerConfig, IEventStats, ILogger, IPerformanceDebugData, IPerformanceEventData, IPoolable, IScene, ISceneConfig, ISceneDebugData, ISceneEventData, ISceneFactory, ISystemBase, ISystemDebugData, ISystemEventData, ITimer, LoggerConfig, PerformanceData, PerformanceStats, PerformanceThresholds, PerformanceWarning, PoolStats };