@esengine/ecs-framework 2.1.33 → 2.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +1 -1
- package/index.cjs.map +1 -1
- package/index.d.ts +599 -459
- package/index.mjs +1 -1
- package/index.mjs.map +1 -1
- package/index.umd.js +1 -1
- package/index.umd.js.map +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @esengine/ecs-framework v2.1.
|
|
2
|
+
* @esengine/ecs-framework v2.1.35
|
|
3
3
|
* TypeScript definitions
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -583,8 +583,9 @@ interface ISystemBase {
|
|
|
583
583
|
* 组件类型定义
|
|
584
584
|
*
|
|
585
585
|
* 用于类型安全的组件操作
|
|
586
|
+
* 支持任意构造函数签名,提供更好的类型安全性
|
|
586
587
|
*/
|
|
587
|
-
type ComponentType$1<T extends IComponent = IComponent> = new (...args:
|
|
588
|
+
type ComponentType$1<T extends IComponent = IComponent> = new (...args: any[]) => T;
|
|
588
589
|
/**
|
|
589
590
|
* 事件总线接口
|
|
590
591
|
* 提供类型安全的事件发布订阅机制
|
|
@@ -1850,8 +1851,9 @@ declare class SoAStorage<T extends Component> {
|
|
|
1850
1851
|
|
|
1851
1852
|
/**
|
|
1852
1853
|
* 组件类型定义
|
|
1854
|
+
* 支持任意构造函数签名,提供更好的类型安全性
|
|
1853
1855
|
*/
|
|
1854
|
-
type ComponentType<T extends Component = Component> = new (...args:
|
|
1856
|
+
type ComponentType<T extends Component = Component> = new (...args: any[]) => T;
|
|
1855
1857
|
/**
|
|
1856
1858
|
* 组件注册表
|
|
1857
1859
|
* 管理组件类型的位掩码分配
|
|
@@ -2954,7 +2956,7 @@ declare function EventHandler(eventType: string, config?: IEventListenerConfig):
|
|
|
2954
2956
|
*/
|
|
2955
2957
|
declare function AsyncEventHandler(eventType: string, config?: IEventListenerConfig): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
2956
2958
|
|
|
2957
|
-
interface IScene {
|
|
2959
|
+
interface IScene$1 {
|
|
2958
2960
|
readonly name: string;
|
|
2959
2961
|
readonly componentStorageManager: ComponentStorageManager;
|
|
2960
2962
|
readonly querySystem: QuerySystem;
|
|
@@ -3042,7 +3044,7 @@ declare class Entity {
|
|
|
3042
3044
|
*
|
|
3043
3045
|
* 指向实体所在的场景实例。
|
|
3044
3046
|
*/
|
|
3045
|
-
scene: IScene | null;
|
|
3047
|
+
scene: IScene$1 | null;
|
|
3046
3048
|
/**
|
|
3047
3049
|
* 更新间隔
|
|
3048
3050
|
*
|
|
@@ -3205,7 +3207,7 @@ declare class Entity {
|
|
|
3205
3207
|
* @param args - 组件构造函数参数
|
|
3206
3208
|
* @returns 创建的组件实例
|
|
3207
3209
|
*/
|
|
3208
|
-
createComponent<T extends Component>(componentType: ComponentType<T>, ...args:
|
|
3210
|
+
createComponent<T extends Component>(componentType: ComponentType<T>, ...args: any[]): T;
|
|
3209
3211
|
/**
|
|
3210
3212
|
* 内部添加组件方法(不进行重复检查,用于初始化)
|
|
3211
3213
|
*
|
|
@@ -3246,7 +3248,7 @@ declare class Entity {
|
|
|
3246
3248
|
* @param args - 组件构造函数参数(仅在创建时使用)
|
|
3247
3249
|
* @returns 组件实例
|
|
3248
3250
|
*/
|
|
3249
|
-
getOrCreateComponent<T extends Component>(type: ComponentType<T>, ...args:
|
|
3251
|
+
getOrCreateComponent<T extends Component>(type: ComponentType<T>, ...args: any[]): T;
|
|
3250
3252
|
/**
|
|
3251
3253
|
* 移除指定的组件
|
|
3252
3254
|
*
|
|
@@ -3545,257 +3547,6 @@ declare class Matcher {
|
|
|
3545
3547
|
toString(): string;
|
|
3546
3548
|
}
|
|
3547
3549
|
|
|
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
3550
|
/**
|
|
3800
3551
|
* 世代式ID池管理器
|
|
3801
3552
|
*
|
|
@@ -3928,296 +3679,645 @@ declare class IdentifierPool {
|
|
|
3928
3679
|
/**
|
|
3929
3680
|
* 强制执行延迟回收处理
|
|
3930
3681
|
*
|
|
3931
|
-
* 在某些情况下可能需要立即处理延迟回收队列,
|
|
3932
|
-
* 比如内存压力大或者需要精确的统计信息时。
|
|
3682
|
+
* 在某些情况下可能需要立即处理延迟回收队列,
|
|
3683
|
+
* 比如内存压力大或者需要精确的统计信息时。
|
|
3684
|
+
*/
|
|
3685
|
+
forceProcessDelayedRecycle(): void;
|
|
3686
|
+
/**
|
|
3687
|
+
* 清理过期的延迟回收项
|
|
3688
|
+
*
|
|
3689
|
+
* 将超过延迟时间的回收项真正回收到空闲列表中。
|
|
3690
|
+
*
|
|
3691
|
+
* @param forceAll 是否强制处理所有延迟回收项
|
|
3692
|
+
* @private
|
|
3693
|
+
*/
|
|
3694
|
+
private _processDelayedRecycle;
|
|
3695
|
+
/**
|
|
3696
|
+
* 预分配世代信息
|
|
3697
|
+
*
|
|
3698
|
+
* @param startIndex 起始索引
|
|
3699
|
+
* @param count 分配数量
|
|
3700
|
+
* @private
|
|
3701
|
+
*/
|
|
3702
|
+
private _preAllocateGenerations;
|
|
3703
|
+
/**
|
|
3704
|
+
* 确保指定索引的世代信息存在
|
|
3705
|
+
*
|
|
3706
|
+
* @param index 索引
|
|
3707
|
+
* @private
|
|
3708
|
+
*/
|
|
3709
|
+
private _ensureGenerationCapacity;
|
|
3710
|
+
/**
|
|
3711
|
+
* 计算内存使用量
|
|
3712
|
+
*
|
|
3713
|
+
* @returns 内存使用字节数
|
|
3714
|
+
* @private
|
|
3715
|
+
*/
|
|
3716
|
+
private _calculateMemoryUsage;
|
|
3717
|
+
/**
|
|
3718
|
+
* 打包索引和世代为32位ID
|
|
3719
|
+
*
|
|
3720
|
+
* @param index 索引(16位)
|
|
3721
|
+
* @param generation 世代版本(16位)
|
|
3722
|
+
* @returns 打包后的32位ID
|
|
3723
|
+
* @private
|
|
3724
|
+
*/
|
|
3725
|
+
private _packId;
|
|
3726
|
+
/**
|
|
3727
|
+
* 从ID中解包索引
|
|
3728
|
+
*
|
|
3729
|
+
* @param id 32位ID
|
|
3730
|
+
* @returns 索引部分(16位)
|
|
3731
|
+
* @private
|
|
3732
|
+
*/
|
|
3733
|
+
private _unpackIndex;
|
|
3734
|
+
/**
|
|
3735
|
+
* 从ID中解包世代版本
|
|
3736
|
+
*
|
|
3737
|
+
* @param id 32位ID
|
|
3738
|
+
* @returns 世代版本部分(16位)
|
|
3739
|
+
* @private
|
|
3740
|
+
*/
|
|
3741
|
+
private _unpackGeneration;
|
|
3742
|
+
/**
|
|
3743
|
+
* 内部ID有效性检查
|
|
3744
|
+
*
|
|
3745
|
+
* @param index 索引
|
|
3746
|
+
* @param generation 世代版本
|
|
3747
|
+
* @returns 是否有效
|
|
3748
|
+
* @private
|
|
3749
|
+
*/
|
|
3750
|
+
private _isValidId;
|
|
3751
|
+
}
|
|
3752
|
+
|
|
3753
|
+
/**
|
|
3754
|
+
* 游戏场景默认实现类
|
|
3755
|
+
*
|
|
3756
|
+
* 实现IScene接口,提供场景的基础功能。
|
|
3757
|
+
* 推荐使用组合而非继承的方式来构建自定义场景。
|
|
3758
|
+
*/
|
|
3759
|
+
declare class Scene implements IScene {
|
|
3760
|
+
/**
|
|
3761
|
+
* 场景名称
|
|
3762
|
+
*
|
|
3763
|
+
* 用于标识和调试的友好名称。
|
|
3764
|
+
*/
|
|
3765
|
+
name: string;
|
|
3766
|
+
/**
|
|
3767
|
+
* 场景中的实体集合
|
|
3768
|
+
*
|
|
3769
|
+
* 管理场景内所有实体的生命周期。
|
|
3770
|
+
*/
|
|
3771
|
+
readonly entities: EntityList;
|
|
3772
|
+
/**
|
|
3773
|
+
* 实体系统处理器集合
|
|
3774
|
+
*
|
|
3775
|
+
* 管理场景内所有实体系统的执行。
|
|
3776
|
+
*/
|
|
3777
|
+
readonly entityProcessors: EntityProcessorList;
|
|
3778
|
+
/**
|
|
3779
|
+
* 实体ID池
|
|
3780
|
+
*
|
|
3781
|
+
* 用于分配和回收实体的唯一标识符。
|
|
3782
|
+
*/
|
|
3783
|
+
readonly identifierPool: IdentifierPool;
|
|
3784
|
+
/**
|
|
3785
|
+
* 组件存储管理器
|
|
3786
|
+
*
|
|
3787
|
+
* 高性能的组件存储和查询系统。
|
|
3788
|
+
*/
|
|
3789
|
+
readonly componentStorageManager: ComponentStorageManager;
|
|
3790
|
+
/**
|
|
3791
|
+
* 查询系统
|
|
3792
|
+
*
|
|
3793
|
+
* 基于位掩码的高性能实体查询系统。
|
|
3794
|
+
*/
|
|
3795
|
+
readonly querySystem: QuerySystem;
|
|
3796
|
+
/**
|
|
3797
|
+
* 事件系统
|
|
3798
|
+
*
|
|
3799
|
+
* 类型安全的事件系统。
|
|
3800
|
+
*/
|
|
3801
|
+
readonly eventSystem: TypeSafeEventSystem;
|
|
3802
|
+
/**
|
|
3803
|
+
* 场景是否已开始运行
|
|
3804
|
+
*/
|
|
3805
|
+
private _didSceneBegin;
|
|
3806
|
+
/**
|
|
3807
|
+
* 获取系统列表(兼容性属性)
|
|
3808
|
+
*/
|
|
3809
|
+
get systems(): EntitySystem[];
|
|
3810
|
+
/**
|
|
3811
|
+
* 创建场景实例
|
|
3812
|
+
*/
|
|
3813
|
+
constructor(config?: ISceneConfig);
|
|
3814
|
+
/**
|
|
3815
|
+
* 初始化场景
|
|
3816
|
+
*
|
|
3817
|
+
* 在场景创建时调用,子类可以重写此方法来设置初始实体和组件。
|
|
3818
|
+
*/
|
|
3819
|
+
initialize(): void;
|
|
3820
|
+
/**
|
|
3821
|
+
* 场景开始运行时的回调
|
|
3822
|
+
*
|
|
3823
|
+
* 在场景开始运行时调用,可以在此方法中执行场景启动逻辑。
|
|
3824
|
+
*/
|
|
3825
|
+
onStart(): void;
|
|
3826
|
+
/**
|
|
3827
|
+
* 场景卸载时的回调
|
|
3828
|
+
*
|
|
3829
|
+
* 在场景被销毁时调用,可以在此方法中执行清理工作。
|
|
3830
|
+
*/
|
|
3831
|
+
unload(): void;
|
|
3832
|
+
/**
|
|
3833
|
+
* 开始场景,启动实体处理器等
|
|
3834
|
+
*
|
|
3835
|
+
* 这个方法会启动场景。它将启动实体处理器等,并调用onStart方法。
|
|
3836
|
+
*/
|
|
3837
|
+
begin(): void;
|
|
3838
|
+
/**
|
|
3839
|
+
* 结束场景,清除实体、实体处理器等
|
|
3840
|
+
*
|
|
3841
|
+
* 这个方法会结束场景。它将移除所有实体,结束实体处理器等,并调用unload方法。
|
|
3842
|
+
*/
|
|
3843
|
+
end(): void;
|
|
3844
|
+
/**
|
|
3845
|
+
* 更新场景,更新实体组件、实体处理器等
|
|
3846
|
+
*/
|
|
3847
|
+
update(): void;
|
|
3848
|
+
/**
|
|
3849
|
+
* 将实体添加到此场景,并返回它
|
|
3850
|
+
* @param name 实体名称
|
|
3851
|
+
*/
|
|
3852
|
+
createEntity(name: string): Entity;
|
|
3853
|
+
/**
|
|
3854
|
+
* 在场景的实体列表中添加一个实体
|
|
3855
|
+
* @param entity 要添加的实体
|
|
3856
|
+
* @param deferCacheClear 是否延迟缓存清理(用于批量操作)
|
|
3857
|
+
*/
|
|
3858
|
+
addEntity(entity: Entity, deferCacheClear?: boolean): Entity;
|
|
3859
|
+
/**
|
|
3860
|
+
* 批量创建实体(高性能版本)
|
|
3861
|
+
* @param count 要创建的实体数量
|
|
3862
|
+
* @param namePrefix 实体名称前缀
|
|
3863
|
+
* @returns 创建的实体列表
|
|
3864
|
+
*/
|
|
3865
|
+
createEntities(count: number, namePrefix?: string): Entity[];
|
|
3866
|
+
/**
|
|
3867
|
+
* 从场景中删除所有实体
|
|
3868
|
+
*/
|
|
3869
|
+
destroyAllEntities(): void;
|
|
3870
|
+
/**
|
|
3871
|
+
* 搜索并返回第一个具有名称的实体
|
|
3872
|
+
* @param name 实体名称
|
|
3873
|
+
*/
|
|
3874
|
+
findEntity(name: string): Entity | null;
|
|
3875
|
+
/**
|
|
3876
|
+
* 根据ID查找实体
|
|
3877
|
+
* @param id 实体ID
|
|
3878
|
+
*/
|
|
3879
|
+
findEntityById(id: number): Entity | null;
|
|
3880
|
+
/**
|
|
3881
|
+
* 根据标签查找实体
|
|
3882
|
+
* @param tag 实体标签
|
|
3883
|
+
*/
|
|
3884
|
+
findEntitiesByTag(tag: number): Entity[];
|
|
3885
|
+
/**
|
|
3886
|
+
* 根据名称查找实体(别名方法)
|
|
3887
|
+
* @param name 实体名称
|
|
3888
|
+
*/
|
|
3889
|
+
getEntityByName(name: string): Entity | null;
|
|
3890
|
+
/**
|
|
3891
|
+
* 根据标签查找实体(别名方法)
|
|
3892
|
+
* @param tag 实体标签
|
|
3893
|
+
*/
|
|
3894
|
+
getEntitiesByTag(tag: number): Entity[];
|
|
3895
|
+
/**
|
|
3896
|
+
* 在场景中添加一个EntitySystem处理器
|
|
3897
|
+
* @param processor 处理器
|
|
3898
|
+
*/
|
|
3899
|
+
addEntityProcessor(processor: EntitySystem): EntitySystem;
|
|
3900
|
+
/**
|
|
3901
|
+
* 添加系统到场景(addEntityProcessor的别名)
|
|
3902
|
+
* @param system 系统
|
|
3903
|
+
*/
|
|
3904
|
+
addSystem(system: EntitySystem): EntitySystem;
|
|
3905
|
+
/**
|
|
3906
|
+
* 从场景中删除EntitySystem处理器
|
|
3907
|
+
* @param processor 要删除的处理器
|
|
3908
|
+
*/
|
|
3909
|
+
removeEntityProcessor(processor: EntitySystem): void;
|
|
3910
|
+
/**
|
|
3911
|
+
* 获取指定类型的EntitySystem处理器
|
|
3912
|
+
* @param type 处理器类型
|
|
3913
|
+
*/
|
|
3914
|
+
getEntityProcessor<T extends EntitySystem>(type: new (...args: unknown[]) => T): T | null;
|
|
3915
|
+
/**
|
|
3916
|
+
* 获取场景统计信息
|
|
3917
|
+
*/
|
|
3918
|
+
getStats(): {
|
|
3919
|
+
entityCount: number;
|
|
3920
|
+
processorCount: number;
|
|
3921
|
+
componentStorageStats: Map<string, any>;
|
|
3922
|
+
};
|
|
3923
|
+
/**
|
|
3924
|
+
* 压缩组件存储(清理碎片)
|
|
3925
|
+
*/
|
|
3926
|
+
compactComponentStorage(): void;
|
|
3927
|
+
/**
|
|
3928
|
+
* 获取场景的调试信息
|
|
3929
|
+
*/
|
|
3930
|
+
getDebugInfo(): {
|
|
3931
|
+
name: string;
|
|
3932
|
+
entityCount: number;
|
|
3933
|
+
processorCount: number;
|
|
3934
|
+
isRunning: boolean;
|
|
3935
|
+
entities: Array<{
|
|
3936
|
+
name: string;
|
|
3937
|
+
id: number;
|
|
3938
|
+
componentCount: number;
|
|
3939
|
+
componentTypes: string[];
|
|
3940
|
+
}>;
|
|
3941
|
+
processors: Array<{
|
|
3942
|
+
name: string;
|
|
3943
|
+
updateOrder: number;
|
|
3944
|
+
entityCount: number;
|
|
3945
|
+
}>;
|
|
3946
|
+
componentStats: Map<string, any>;
|
|
3947
|
+
};
|
|
3948
|
+
}
|
|
3949
|
+
|
|
3950
|
+
/**
|
|
3951
|
+
* 实体系统的基类
|
|
3952
|
+
*
|
|
3953
|
+
* 用于处理一组符合特定条件的实体。系统是ECS架构中的逻辑处理单元,
|
|
3954
|
+
* 负责对拥有特定组件组合的实体执行业务逻辑。
|
|
3955
|
+
*
|
|
3956
|
+
* @example
|
|
3957
|
+
* ```typescript
|
|
3958
|
+
* class MovementSystem extends EntitySystem {
|
|
3959
|
+
* constructor() {
|
|
3960
|
+
* super(Transform, Velocity);
|
|
3961
|
+
* }
|
|
3962
|
+
*
|
|
3963
|
+
* protected process(entities: Entity[]): void {
|
|
3964
|
+
* for (const entity of entities) {
|
|
3965
|
+
* const transform = entity.getComponent(Transform);
|
|
3966
|
+
* const velocity = entity.getComponent(Velocity);
|
|
3967
|
+
* transform.position.add(velocity.value);
|
|
3968
|
+
* }
|
|
3969
|
+
* }
|
|
3970
|
+
* }
|
|
3971
|
+
* ```
|
|
3972
|
+
*/
|
|
3973
|
+
declare abstract class EntitySystem implements ISystemBase {
|
|
3974
|
+
private _updateOrder;
|
|
3975
|
+
private _enabled;
|
|
3976
|
+
private _performanceMonitor;
|
|
3977
|
+
private _systemName;
|
|
3978
|
+
private _initialized;
|
|
3979
|
+
private _matcher;
|
|
3980
|
+
private _trackedEntities;
|
|
3981
|
+
private _lastQueryResult;
|
|
3982
|
+
/**
|
|
3983
|
+
* 获取系统处理的实体列表(动态查询)
|
|
3984
|
+
*/
|
|
3985
|
+
get entities(): readonly Entity[];
|
|
3986
|
+
/**
|
|
3987
|
+
* 获取系统的更新时序
|
|
3988
|
+
*/
|
|
3989
|
+
get updateOrder(): number;
|
|
3990
|
+
set updateOrder(value: number);
|
|
3991
|
+
/**
|
|
3992
|
+
* 获取系统的启用状态
|
|
3993
|
+
*/
|
|
3994
|
+
get enabled(): boolean;
|
|
3995
|
+
/**
|
|
3996
|
+
* 设置系统的启用状态
|
|
3997
|
+
*/
|
|
3998
|
+
set enabled(value: boolean);
|
|
3999
|
+
/**
|
|
4000
|
+
* 获取系统名称
|
|
4001
|
+
*/
|
|
4002
|
+
get systemName(): string;
|
|
4003
|
+
constructor(matcher?: Matcher);
|
|
4004
|
+
private _scene;
|
|
4005
|
+
/**
|
|
4006
|
+
* 这个系统所属的场景
|
|
4007
|
+
*/
|
|
4008
|
+
get scene(): Scene | null;
|
|
4009
|
+
set scene(value: Scene | null);
|
|
4010
|
+
/**
|
|
4011
|
+
* 获取实体匹配器
|
|
4012
|
+
*/
|
|
4013
|
+
get matcher(): Matcher;
|
|
4014
|
+
/**
|
|
4015
|
+
* 设置更新时序
|
|
4016
|
+
* @param order 更新时序
|
|
4017
|
+
*/
|
|
4018
|
+
setUpdateOrder(order: number): void;
|
|
4019
|
+
/**
|
|
4020
|
+
* 系统初始化(框架调用)
|
|
4021
|
+
*
|
|
4022
|
+
* 在系统创建时调用。框架内部使用,用户不应直接调用。
|
|
4023
|
+
*/
|
|
4024
|
+
initialize(): void;
|
|
4025
|
+
/**
|
|
4026
|
+
* 系统初始化回调
|
|
4027
|
+
*
|
|
4028
|
+
* 子类可以重写此方法进行初始化操作。
|
|
4029
|
+
*/
|
|
4030
|
+
protected onInitialize(): void;
|
|
4031
|
+
/**
|
|
4032
|
+
* 重置系统状态
|
|
4033
|
+
*
|
|
4034
|
+
* 当系统从场景中移除时调用,重置初始化状态以便重新添加时能正确初始化。
|
|
4035
|
+
*/
|
|
4036
|
+
reset(): void;
|
|
4037
|
+
/**
|
|
4038
|
+
* 查询匹配的实体
|
|
4039
|
+
*/
|
|
4040
|
+
private queryEntities;
|
|
4041
|
+
/**
|
|
4042
|
+
* 检查是否为单一条件查询
|
|
4043
|
+
*/
|
|
4044
|
+
private isSingleCondition;
|
|
4045
|
+
/**
|
|
4046
|
+
* 执行单一条件查询
|
|
4047
|
+
*/
|
|
4048
|
+
private executeSingleConditionQuery;
|
|
4049
|
+
/**
|
|
4050
|
+
* 执行复合查询
|
|
4051
|
+
*/
|
|
4052
|
+
private executeComplexQuery;
|
|
4053
|
+
/**
|
|
4054
|
+
* 更新系统
|
|
4055
|
+
*
|
|
4056
|
+
* 在每帧调用,处理系统的主要逻辑。
|
|
4057
|
+
*/
|
|
4058
|
+
update(): void;
|
|
4059
|
+
/**
|
|
4060
|
+
* 后期更新系统
|
|
4061
|
+
*
|
|
4062
|
+
* 在所有系统的update方法执行完毕后调用。
|
|
4063
|
+
*/
|
|
4064
|
+
lateUpdate(): void;
|
|
4065
|
+
/**
|
|
4066
|
+
* 在系统处理开始前调用
|
|
4067
|
+
*
|
|
4068
|
+
* 子类可以重写此方法进行预处理操作。
|
|
4069
|
+
*/
|
|
4070
|
+
protected onBegin(): void;
|
|
4071
|
+
/**
|
|
4072
|
+
* 处理实体列表
|
|
4073
|
+
*
|
|
4074
|
+
* 系统的核心逻辑,子类必须实现此方法来定义具体的处理逻辑。
|
|
4075
|
+
*
|
|
4076
|
+
* @param entities 要处理的实体列表
|
|
4077
|
+
*/
|
|
4078
|
+
protected process(entities: Entity[]): void;
|
|
4079
|
+
/**
|
|
4080
|
+
* 后期处理实体列表
|
|
4081
|
+
*
|
|
4082
|
+
* 在主要处理逻辑之后执行,子类可以重写此方法。
|
|
4083
|
+
*
|
|
4084
|
+
* @param entities 要处理的实体列表
|
|
4085
|
+
*/
|
|
4086
|
+
protected lateProcess(entities: Entity[]): void;
|
|
4087
|
+
/**
|
|
4088
|
+
* 系统处理完毕后调用
|
|
4089
|
+
*
|
|
4090
|
+
* 子类可以重写此方法进行后处理操作。
|
|
4091
|
+
*/
|
|
4092
|
+
protected onEnd(): void;
|
|
4093
|
+
/**
|
|
4094
|
+
* 检查系统是否需要处理
|
|
4095
|
+
*
|
|
4096
|
+
* 在启用系统时有用,但仅偶尔需要处理。
|
|
4097
|
+
* 这只影响处理,不影响事件或订阅列表。
|
|
4098
|
+
*
|
|
4099
|
+
* @returns 如果系统应该处理,则为true,如果不处理则为false
|
|
4100
|
+
*/
|
|
4101
|
+
protected onCheckProcessing(): boolean;
|
|
4102
|
+
/**
|
|
4103
|
+
* 获取系统的性能数据
|
|
4104
|
+
*
|
|
4105
|
+
* @returns 性能数据或undefined
|
|
4106
|
+
*/
|
|
4107
|
+
getPerformanceData(): PerformanceData | undefined;
|
|
4108
|
+
/**
|
|
4109
|
+
* 获取系统的性能统计
|
|
4110
|
+
*
|
|
4111
|
+
* @returns 性能统计或undefined
|
|
4112
|
+
*/
|
|
4113
|
+
getPerformanceStats(): PerformanceStats | undefined;
|
|
4114
|
+
/**
|
|
4115
|
+
* 重置系统的性能数据
|
|
4116
|
+
*/
|
|
4117
|
+
resetPerformanceData(): void;
|
|
4118
|
+
/**
|
|
4119
|
+
* 获取系统信息的字符串表示
|
|
4120
|
+
*
|
|
4121
|
+
* @returns 系统信息字符串
|
|
4122
|
+
*/
|
|
4123
|
+
toString(): string;
|
|
4124
|
+
/**
|
|
4125
|
+
* 更新实体跟踪,检查新增和移除的实体
|
|
4126
|
+
*/
|
|
4127
|
+
private updateEntityTracking;
|
|
4128
|
+
/**
|
|
4129
|
+
* 当实体被添加到系统时调用
|
|
4130
|
+
*
|
|
4131
|
+
* 子类可以重写此方法来处理实体添加事件。
|
|
4132
|
+
*
|
|
4133
|
+
* @param entity 被添加的实体
|
|
3933
4134
|
*/
|
|
3934
|
-
|
|
4135
|
+
protected onAdded(_entity: Entity): void;
|
|
3935
4136
|
/**
|
|
3936
|
-
*
|
|
4137
|
+
* 当实体从系统中移除时调用
|
|
3937
4138
|
*
|
|
3938
|
-
*
|
|
4139
|
+
* 子类可以重写此方法来处理实体移除事件。
|
|
3939
4140
|
*
|
|
3940
|
-
* @param
|
|
3941
|
-
* @private
|
|
4141
|
+
* @param entity 被移除的实体
|
|
3942
4142
|
*/
|
|
3943
|
-
|
|
4143
|
+
protected onRemoved(_entity: Entity): void;
|
|
4144
|
+
}
|
|
4145
|
+
|
|
4146
|
+
/**
|
|
4147
|
+
* 实体处理器列表管理器
|
|
4148
|
+
* 管理场景中的所有实体系统
|
|
4149
|
+
*/
|
|
4150
|
+
declare class EntityProcessorList {
|
|
4151
|
+
private static readonly _logger;
|
|
4152
|
+
private _processors;
|
|
4153
|
+
private _isDirty;
|
|
3944
4154
|
/**
|
|
3945
|
-
*
|
|
3946
|
-
*
|
|
3947
|
-
* @param startIndex 起始索引
|
|
3948
|
-
* @param count 分配数量
|
|
3949
|
-
* @private
|
|
4155
|
+
* 设置为脏状态,需要重新排序
|
|
3950
4156
|
*/
|
|
3951
|
-
|
|
4157
|
+
setDirty(): void;
|
|
3952
4158
|
/**
|
|
3953
|
-
*
|
|
3954
|
-
*
|
|
3955
|
-
* @param index 索引
|
|
3956
|
-
* @private
|
|
4159
|
+
* 添加实体处理器
|
|
4160
|
+
* @param processor 要添加的处理器
|
|
3957
4161
|
*/
|
|
3958
|
-
|
|
4162
|
+
add(processor: EntitySystem): void;
|
|
3959
4163
|
/**
|
|
3960
|
-
*
|
|
3961
|
-
*
|
|
3962
|
-
* @returns 内存使用字节数
|
|
3963
|
-
* @private
|
|
4164
|
+
* 移除实体处理器
|
|
4165
|
+
* @param processor 要移除的处理器
|
|
3964
4166
|
*/
|
|
3965
|
-
|
|
4167
|
+
remove(processor: EntitySystem): void;
|
|
3966
4168
|
/**
|
|
3967
|
-
*
|
|
3968
|
-
*
|
|
3969
|
-
* @param index 索引(16位)
|
|
3970
|
-
* @param generation 世代版本(16位)
|
|
3971
|
-
* @returns 打包后的32位ID
|
|
3972
|
-
* @private
|
|
4169
|
+
* 获取指定类型的处理器
|
|
4170
|
+
* @param type 处理器类型
|
|
3973
4171
|
*/
|
|
3974
|
-
|
|
4172
|
+
getProcessor<T extends EntitySystem>(type: new (...args: unknown[]) => T): T | null;
|
|
3975
4173
|
/**
|
|
3976
|
-
*
|
|
4174
|
+
* 开始处理
|
|
3977
4175
|
*
|
|
3978
|
-
*
|
|
3979
|
-
* @returns 索引部分(16位)
|
|
3980
|
-
* @private
|
|
4176
|
+
* 对所有处理器进行排序以确保正确的执行顺序。
|
|
3981
4177
|
*/
|
|
3982
|
-
|
|
4178
|
+
begin(): void;
|
|
3983
4179
|
/**
|
|
3984
|
-
*
|
|
3985
|
-
*
|
|
3986
|
-
* @param id 32位ID
|
|
3987
|
-
* @returns 世代版本部分(16位)
|
|
3988
|
-
* @private
|
|
4180
|
+
* 结束处理
|
|
3989
4181
|
*/
|
|
3990
|
-
|
|
4182
|
+
end(): void;
|
|
3991
4183
|
/**
|
|
3992
|
-
*
|
|
3993
|
-
*
|
|
3994
|
-
* @param index 索引
|
|
3995
|
-
* @param generation 世代版本
|
|
3996
|
-
* @returns 是否有效
|
|
3997
|
-
* @private
|
|
4184
|
+
* 更新所有处理器
|
|
3998
4185
|
*/
|
|
3999
|
-
|
|
4186
|
+
update(): void;
|
|
4187
|
+
/**
|
|
4188
|
+
* 后期更新所有处理器
|
|
4189
|
+
*/
|
|
4190
|
+
lateUpdate(): void;
|
|
4191
|
+
/**
|
|
4192
|
+
* 排序处理器
|
|
4193
|
+
*/
|
|
4194
|
+
private sortProcessors;
|
|
4195
|
+
/** 获取处理器列表 */
|
|
4196
|
+
get processors(): EntitySystem[];
|
|
4197
|
+
/** 获取处理器数量 */
|
|
4198
|
+
get count(): number;
|
|
4000
4199
|
}
|
|
4001
4200
|
|
|
4002
4201
|
/**
|
|
4003
|
-
*
|
|
4202
|
+
* 场景接口定义
|
|
4004
4203
|
*
|
|
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
|
-
* ```
|
|
4204
|
+
* 定义场景应该实现的核心功能和属性,使用接口而非继承提供更灵活的实现方式。
|
|
4020
4205
|
*/
|
|
4021
|
-
|
|
4206
|
+
interface IScene {
|
|
4022
4207
|
/**
|
|
4023
4208
|
* 场景名称
|
|
4024
|
-
*
|
|
4025
|
-
* 用于标识和调试的友好名称。
|
|
4026
4209
|
*/
|
|
4027
4210
|
name: string;
|
|
4028
4211
|
/**
|
|
4029
4212
|
* 场景中的实体集合
|
|
4030
|
-
*
|
|
4031
|
-
* 管理场景内所有实体的生命周期。
|
|
4032
4213
|
*/
|
|
4033
4214
|
readonly entities: EntityList;
|
|
4034
4215
|
/**
|
|
4035
4216
|
* 实体系统处理器集合
|
|
4036
|
-
*
|
|
4037
|
-
* 管理场景内所有实体系统的执行。
|
|
4038
4217
|
*/
|
|
4039
4218
|
readonly entityProcessors: EntityProcessorList;
|
|
4040
4219
|
/**
|
|
4041
|
-
*
|
|
4042
|
-
*
|
|
4043
|
-
* 用于分配和回收实体的唯一标识符。
|
|
4220
|
+
* 标识符池
|
|
4044
4221
|
*/
|
|
4045
4222
|
readonly identifierPool: IdentifierPool;
|
|
4046
4223
|
/**
|
|
4047
4224
|
* 组件存储管理器
|
|
4048
|
-
*
|
|
4049
|
-
* 高性能的组件存储和查询系统。
|
|
4050
4225
|
*/
|
|
4051
4226
|
readonly componentStorageManager: ComponentStorageManager;
|
|
4052
4227
|
/**
|
|
4053
4228
|
* 查询系统
|
|
4054
|
-
*
|
|
4055
|
-
* 基于位掩码的高性能实体查询系统。
|
|
4056
4229
|
*/
|
|
4057
4230
|
readonly querySystem: QuerySystem;
|
|
4058
4231
|
/**
|
|
4059
4232
|
* 事件系统
|
|
4060
|
-
*
|
|
4061
|
-
* 类型安全的事件系统。
|
|
4062
4233
|
*/
|
|
4063
4234
|
readonly eventSystem: TypeSafeEventSystem;
|
|
4064
4235
|
/**
|
|
4065
|
-
*
|
|
4066
|
-
*/
|
|
4067
|
-
private _didSceneBegin;
|
|
4068
|
-
/**
|
|
4069
|
-
* 场景是否已初始化
|
|
4070
|
-
*/
|
|
4071
|
-
private _isInitialized;
|
|
4072
|
-
/**
|
|
4073
|
-
* 获取系统列表(兼容性属性)
|
|
4074
|
-
*/
|
|
4075
|
-
get systems(): EntitySystem[];
|
|
4076
|
-
/**
|
|
4077
|
-
* 创建场景实例
|
|
4236
|
+
* 获取系统列表
|
|
4078
4237
|
*/
|
|
4079
|
-
|
|
4238
|
+
readonly systems: EntitySystem[];
|
|
4080
4239
|
/**
|
|
4081
4240
|
* 初始化场景
|
|
4082
|
-
*
|
|
4083
|
-
* 在场景创建时调用,子类可以重写此方法来设置初始实体和组件。
|
|
4084
4241
|
*/
|
|
4085
4242
|
initialize(): void;
|
|
4086
4243
|
/**
|
|
4087
4244
|
* 场景开始运行时的回调
|
|
4088
|
-
*
|
|
4089
|
-
* 在场景开始运行时调用,可以在此方法中执行场景启动逻辑。
|
|
4090
4245
|
*/
|
|
4091
4246
|
onStart(): void;
|
|
4092
4247
|
/**
|
|
4093
4248
|
* 场景卸载时的回调
|
|
4094
|
-
*
|
|
4095
|
-
* 在场景被销毁时调用,可以在此方法中执行清理工作。
|
|
4096
4249
|
*/
|
|
4097
4250
|
unload(): void;
|
|
4098
4251
|
/**
|
|
4099
|
-
*
|
|
4100
|
-
*
|
|
4101
|
-
* 这个方法会启动场景。它将启动实体处理器等,并调用onStart方法。
|
|
4252
|
+
* 开始场景
|
|
4102
4253
|
*/
|
|
4103
4254
|
begin(): void;
|
|
4104
4255
|
/**
|
|
4105
|
-
*
|
|
4106
|
-
*
|
|
4107
|
-
* 这个方法会结束场景。它将移除所有实体,结束实体处理器等,并调用unload方法。
|
|
4256
|
+
* 结束场景
|
|
4108
4257
|
*/
|
|
4109
4258
|
end(): void;
|
|
4110
4259
|
/**
|
|
4111
|
-
*
|
|
4260
|
+
* 更新场景
|
|
4112
4261
|
*/
|
|
4113
4262
|
update(): void;
|
|
4114
4263
|
/**
|
|
4115
|
-
*
|
|
4116
|
-
* @param name 实体名称
|
|
4264
|
+
* 创建实体
|
|
4117
4265
|
*/
|
|
4118
4266
|
createEntity(name: string): Entity;
|
|
4119
4267
|
/**
|
|
4120
|
-
*
|
|
4121
|
-
* @param entity 要添加的实体
|
|
4122
|
-
* @param deferCacheClear 是否延迟缓存清理(用于批量操作)
|
|
4268
|
+
* 添加实体
|
|
4123
4269
|
*/
|
|
4124
4270
|
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
4271
|
/**
|
|
4133
4272
|
* 批量创建实体
|
|
4134
|
-
* @param count 要创建的实体数量
|
|
4135
|
-
* @param namePrefix 实体名称前缀
|
|
4136
|
-
* @returns 创建的实体列表
|
|
4137
4273
|
*/
|
|
4138
|
-
|
|
4274
|
+
createEntities(count: number, namePrefix?: string): Entity[];
|
|
4139
4275
|
/**
|
|
4140
|
-
*
|
|
4276
|
+
* 销毁所有实体
|
|
4141
4277
|
*/
|
|
4142
4278
|
destroyAllEntities(): void;
|
|
4143
4279
|
/**
|
|
4144
|
-
*
|
|
4145
|
-
* @param name 实体名称
|
|
4280
|
+
* 查找实体
|
|
4146
4281
|
*/
|
|
4147
4282
|
findEntity(name: string): Entity | null;
|
|
4148
|
-
/**
|
|
4149
|
-
* 根据ID查找实体
|
|
4150
|
-
* @param id 实体ID
|
|
4151
|
-
*/
|
|
4152
|
-
findEntityById(id: number): Entity | null;
|
|
4153
4283
|
/**
|
|
4154
4284
|
* 根据标签查找实体
|
|
4155
|
-
* @param tag 实体标签
|
|
4156
4285
|
*/
|
|
4157
4286
|
findEntitiesByTag(tag: number): Entity[];
|
|
4158
4287
|
/**
|
|
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 处理器
|
|
4288
|
+
* 添加实体处理器
|
|
4171
4289
|
*/
|
|
4172
4290
|
addEntityProcessor(processor: EntitySystem): EntitySystem;
|
|
4173
4291
|
/**
|
|
4174
|
-
*
|
|
4175
|
-
* @param system 系统
|
|
4176
|
-
*/
|
|
4177
|
-
addSystem(system: EntitySystem): EntitySystem;
|
|
4178
|
-
/**
|
|
4179
|
-
* 从场景中删除EntitySystem处理器
|
|
4180
|
-
* @param processor 要删除的处理器
|
|
4292
|
+
* 移除实体处理器
|
|
4181
4293
|
*/
|
|
4182
4294
|
removeEntityProcessor(processor: EntitySystem): void;
|
|
4183
4295
|
/**
|
|
4184
|
-
*
|
|
4185
|
-
* @param type 处理器类型
|
|
4296
|
+
* 获取实体处理器
|
|
4186
4297
|
*/
|
|
4187
|
-
getEntityProcessor<T extends EntitySystem>(type: new (...args:
|
|
4298
|
+
getEntityProcessor<T extends EntitySystem>(type: new (...args: any[]) => T): T | null;
|
|
4299
|
+
}
|
|
4300
|
+
/**
|
|
4301
|
+
* 场景工厂接口
|
|
4302
|
+
*/
|
|
4303
|
+
interface ISceneFactory<T extends IScene> {
|
|
4188
4304
|
/**
|
|
4189
|
-
*
|
|
4305
|
+
* 创建场景实例
|
|
4190
4306
|
*/
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4307
|
+
createScene(): T;
|
|
4308
|
+
}
|
|
4309
|
+
/**
|
|
4310
|
+
* 场景配置接口
|
|
4311
|
+
*/
|
|
4312
|
+
interface ISceneConfig {
|
|
4196
4313
|
/**
|
|
4197
|
-
*
|
|
4314
|
+
* 场景名称
|
|
4198
4315
|
*/
|
|
4199
|
-
|
|
4316
|
+
name?: string;
|
|
4200
4317
|
/**
|
|
4201
|
-
*
|
|
4318
|
+
* 调试配置
|
|
4202
4319
|
*/
|
|
4203
|
-
|
|
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
|
-
};
|
|
4320
|
+
debug?: boolean;
|
|
4221
4321
|
}
|
|
4222
4322
|
|
|
4223
4323
|
/**
|
|
@@ -4227,7 +4327,7 @@ declare class EntityBuilder {
|
|
|
4227
4327
|
private entity;
|
|
4228
4328
|
private scene;
|
|
4229
4329
|
private storageManager;
|
|
4230
|
-
constructor(scene:
|
|
4330
|
+
constructor(scene: IScene, storageManager: ComponentStorageManager);
|
|
4231
4331
|
/**
|
|
4232
4332
|
* 设置实体名称
|
|
4233
4333
|
* @param name 实体名称
|
|
@@ -4472,7 +4572,7 @@ declare class ECSFluentAPI {
|
|
|
4472
4572
|
private scene;
|
|
4473
4573
|
private querySystem;
|
|
4474
4574
|
private eventSystem;
|
|
4475
|
-
constructor(scene:
|
|
4575
|
+
constructor(scene: IScene, querySystem: QuerySystem, eventSystem: TypeSafeEventSystem);
|
|
4476
4576
|
/**
|
|
4477
4577
|
* 创建实体构建器
|
|
4478
4578
|
* @returns 实体构建器
|
|
@@ -4564,9 +4664,9 @@ declare class ECSFluentAPI {
|
|
|
4564
4664
|
getStats(): {
|
|
4565
4665
|
entityCount: number;
|
|
4566
4666
|
systemCount: number;
|
|
4567
|
-
componentStats: Map<string,
|
|
4667
|
+
componentStats: Map<string, unknown>;
|
|
4568
4668
|
queryStats: unknown;
|
|
4569
|
-
eventStats: Map<string,
|
|
4669
|
+
eventStats: Map<string, unknown>;
|
|
4570
4670
|
};
|
|
4571
4671
|
}
|
|
4572
4672
|
/**
|
|
@@ -4576,7 +4676,7 @@ declare class ECSFluentAPI {
|
|
|
4576
4676
|
* @param eventSystem 事件系统
|
|
4577
4677
|
* @returns ECS流式API实例
|
|
4578
4678
|
*/
|
|
4579
|
-
declare function createECSAPI(scene:
|
|
4679
|
+
declare function createECSAPI(scene: IScene, querySystem: QuerySystem, eventSystem: TypeSafeEventSystem): ECSFluentAPI;
|
|
4580
4680
|
|
|
4581
4681
|
/**
|
|
4582
4682
|
* 实体数据收集器
|
|
@@ -4894,10 +4994,6 @@ declare class DebugManager {
|
|
|
4894
4994
|
* 收集性能统计信息
|
|
4895
4995
|
*/
|
|
4896
4996
|
private collectPerformanceStats;
|
|
4897
|
-
/**
|
|
4898
|
-
* 获取内存大小分类
|
|
4899
|
-
*/
|
|
4900
|
-
private getMemorySizeCategory;
|
|
4901
4997
|
/**
|
|
4902
4998
|
* 获取调试数据
|
|
4903
4999
|
*/
|
|
@@ -4970,7 +5066,7 @@ declare class Core {
|
|
|
4970
5066
|
*
|
|
4971
5067
|
* 存储下一帧要切换到的场景实例。
|
|
4972
5068
|
*/
|
|
4973
|
-
_nextScene:
|
|
5069
|
+
_nextScene: IScene | null;
|
|
4974
5070
|
/**
|
|
4975
5071
|
* 全局管理器集合
|
|
4976
5072
|
*
|
|
@@ -5004,7 +5100,7 @@ declare class Core {
|
|
|
5004
5100
|
/**
|
|
5005
5101
|
* 当前活动场景
|
|
5006
5102
|
*/
|
|
5007
|
-
_scene?:
|
|
5103
|
+
_scene?: IScene;
|
|
5008
5104
|
/**
|
|
5009
5105
|
* 调试管理器
|
|
5010
5106
|
*
|
|
@@ -5036,16 +5132,54 @@ declare class Core {
|
|
|
5036
5132
|
*
|
|
5037
5133
|
* @returns 当前场景实例,如果没有则返回null
|
|
5038
5134
|
*/
|
|
5039
|
-
static get scene():
|
|
5135
|
+
static get scene(): IScene | null;
|
|
5136
|
+
/**
|
|
5137
|
+
* 设置当前场景(已废弃)
|
|
5138
|
+
*
|
|
5139
|
+
* @deprecated 请使用 Core.setScene() 方法代替。scene setter 可能导致场景延迟激活的时序问题,
|
|
5140
|
+
* 而 setScene() 提供更好的类型安全性和可预测的激活时序。
|
|
5141
|
+
*
|
|
5142
|
+
* 迁移示例:
|
|
5143
|
+
* ```typescript
|
|
5144
|
+
* // 旧方式(已废弃)
|
|
5145
|
+
* Core.scene = myScene;
|
|
5146
|
+
*
|
|
5147
|
+
* // 新方式(推荐)
|
|
5148
|
+
* Core.setScene(myScene);
|
|
5149
|
+
* ```
|
|
5150
|
+
*
|
|
5151
|
+
* 如果当前没有场景,会立即切换;否则会在下一帧切换。
|
|
5152
|
+
*
|
|
5153
|
+
* @param value - 场景实例
|
|
5154
|
+
*/
|
|
5155
|
+
static set scene(value: IScene | null);
|
|
5040
5156
|
/**
|
|
5041
|
-
*
|
|
5157
|
+
* 类型安全的场景设置方法(推荐)
|
|
5158
|
+
*
|
|
5159
|
+
* 这是设置场景的推荐方法,提供更好的类型安全性和可预测的激活时序。
|
|
5160
|
+
* 相比于 scene setter,此方法能确保场景正确初始化和激活。
|
|
5042
5161
|
*
|
|
5043
5162
|
* 如果当前没有场景,会立即切换;否则会在下一帧切换。
|
|
5044
5163
|
*
|
|
5045
|
-
* @param
|
|
5046
|
-
* @
|
|
5164
|
+
* @param scene - 要设置的场景实例
|
|
5165
|
+
* @returns 设置的场景实例,便于链式调用
|
|
5166
|
+
*
|
|
5167
|
+
* @example
|
|
5168
|
+
* ```typescript
|
|
5169
|
+
* const myScene = new MyScene();
|
|
5170
|
+
* Core.setScene(myScene);
|
|
5171
|
+
*
|
|
5172
|
+
* // 链式调用
|
|
5173
|
+
* const scene = Core.setScene(new MyScene()).addSystem(new MySystem());
|
|
5174
|
+
* ```
|
|
5175
|
+
*/
|
|
5176
|
+
static setScene<T extends IScene>(scene: T): T;
|
|
5177
|
+
/**
|
|
5178
|
+
* 类型安全的场景获取方法
|
|
5179
|
+
*
|
|
5180
|
+
* @returns 当前场景实例
|
|
5047
5181
|
*/
|
|
5048
|
-
static
|
|
5182
|
+
static getScene<T extends IScene>(): T | null;
|
|
5049
5183
|
/**
|
|
5050
5184
|
* 创建Core实例
|
|
5051
5185
|
*
|
|
@@ -5113,7 +5247,7 @@ declare class Core {
|
|
|
5113
5247
|
* @param onTime - 定时器触发时的回调函数
|
|
5114
5248
|
* @returns 创建的定时器实例
|
|
5115
5249
|
*/
|
|
5116
|
-
static schedule<TContext = unknown>(timeInSeconds: number, repeats
|
|
5250
|
+
static schedule<TContext = unknown>(timeInSeconds: number, repeats?: boolean, context?: TContext, onTime?: (timer: ITimer<TContext>) => void): Timer<TContext>;
|
|
5117
5251
|
/**
|
|
5118
5252
|
* 获取ECS流式API
|
|
5119
5253
|
*
|
|
@@ -5135,7 +5269,7 @@ declare class Core {
|
|
|
5135
5269
|
*
|
|
5136
5270
|
* @returns 当前调试数据,如果调试未启用则返回null
|
|
5137
5271
|
*/
|
|
5138
|
-
static getDebugData():
|
|
5272
|
+
static getDebugData(): unknown;
|
|
5139
5273
|
/**
|
|
5140
5274
|
* 检查调试是否启用
|
|
5141
5275
|
*
|
|
@@ -5154,6 +5288,12 @@ declare class Core {
|
|
|
5154
5288
|
* @returns 是否支持BigInt
|
|
5155
5289
|
*/
|
|
5156
5290
|
static get supportsBigInt(): boolean;
|
|
5291
|
+
/**
|
|
5292
|
+
* 内部场景设置方法
|
|
5293
|
+
*
|
|
5294
|
+
* @param scene - 要设置的场景实例
|
|
5295
|
+
*/
|
|
5296
|
+
private setSceneInternal;
|
|
5157
5297
|
/**
|
|
5158
5298
|
* 场景切换回调
|
|
5159
5299
|
*
|
|
@@ -6358,4 +6498,4 @@ declare class Time {
|
|
|
6358
6498
|
}
|
|
6359
6499
|
|
|
6360
6500
|
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 };
|
|
6501
|
+
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 };
|