@esengine/ecs-framework 2.2.12 → 2.2.13

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.12
2
+ * @esengine/ecs-framework v2.2.13
3
3
  * TypeScript definitions
4
4
  */
5
5
  /**
@@ -1286,6 +1286,9 @@ declare class LoggerManager {
1286
1286
  /**
1287
1287
  * 设置日志器工厂方法
1288
1288
  * @param factory 日志器工厂方法
1289
+ *
1290
+ * 注意: 应该在导入 ECS 模块之前调用此方法。
1291
+ * 设置后, 每次调用 getLogger() 都会通过 factory 创建新的 logger 实例, 由用户侧管理
1289
1292
  */
1290
1293
  setLoggerFactory(factory: (name?: string) => ILogger): void;
1291
1294
  }
@@ -5037,7 +5040,7 @@ declare class Scene implements IScene {
5037
5040
  *
5038
5041
  * 从 ServiceContainer 获取,如果未注册则创建默认实例(向后兼容)
5039
5042
  */
5040
- private get performanceMonitor();
5043
+ get performanceMonitor(): PerformanceMonitor;
5041
5044
  /**
5042
5045
  * 初始化场景
5043
5046
  *
@@ -5066,6 +5069,16 @@ declare class Scene implements IScene {
5066
5069
  * 结束场景,清除实体、实体处理器等
5067
5070
  *
5068
5071
  * 这个方法会结束场景。它将移除所有实体,结束实体处理器等,并调用unload方法。
5072
+ *
5073
+ * 执行顺序:
5074
+ * 1. 调用 unload() - 用户可以在此访问实体和系统进行清理
5075
+ * 2. 清理所有实体
5076
+ * 3. 清空服务容器,触发所有系统的 onDestroy()
5077
+ *
5078
+ * 注意:
5079
+ * - onRemoved 回调不会在 Scene.end() 时触发,因为这是批量销毁场景
5080
+ * - 用户清理:在 Scene.unload() 中处理(可访问实体和系统)
5081
+ * - 系统清理:在 System.onDestroy() 中处理(实体已被清理)
5069
5082
  */
5070
5083
  end(): void;
5071
5084
  /**
@@ -5539,6 +5552,7 @@ declare abstract class EntitySystem implements ISystemBase, IService {
5539
5552
  private _matcher;
5540
5553
  private _eventListeners;
5541
5554
  private _scene;
5555
+ private _destroyed;
5542
5556
  protected logger: ReturnType<typeof createLogger>;
5543
5557
  /**
5544
5558
  * 实体ID映射缓存
@@ -5614,6 +5628,10 @@ declare abstract class EntitySystem implements ISystemBase, IService {
5614
5628
  * 重置系统状态
5615
5629
  *
5616
5630
  * 当系统从场景中移除时调用,重置初始化状态以便重新添加时能正确初始化。
5631
+ *
5632
+ * 注意:此方法由 Scene.removeEntityProcessor 调用,在 unregister(触发dispose)之后调用。
5633
+ * dispose 已经调用了 onDestroy 并设置了 _destroyed 标志,所以这里不需要重置该标志。
5634
+ * 重置 _destroyed 会违反服务容器的语义(dispose 后不应重用)。
5617
5635
  */
5618
5636
  reset(): void;
5619
5637
  /**
@@ -5765,6 +5783,7 @@ declare abstract class EntitySystem implements ISystemBase, IService {
5765
5783
  *
5766
5784
  * 默认行为:
5767
5785
  * - 移除所有事件监听器
5786
+ * - 调用 onDestroy 回调(仅首次)
5768
5787
  * - 清空所有缓存
5769
5788
  * - 重置初始化状态
5770
5789
  *
@@ -7937,6 +7956,13 @@ interface IWorldConfig {
7937
7956
  * World类 - ECS世界管理器
7938
7957
  *
7939
7958
  * World是Scene的容器,每个World可以管理多个Scene。
7959
+ * World拥有独立的服务容器,用于管理World级别的全局服务。
7960
+ *
7961
+ * 服务容器层级:
7962
+ * - Core.services: 应用程序全局服务
7963
+ * - World.services: World级别服务(每个World独立)
7964
+ * - Scene.services: Scene级别服务(每个Scene独立)
7965
+ *
7940
7966
  * 这种设计允许创建独立的游戏世界,如:
7941
7967
  * - 游戏房间(每个房间一个World)
7942
7968
  * - 不同的游戏模式
@@ -7947,10 +7973,16 @@ interface IWorldConfig {
7947
7973
  * // 创建游戏房间的World
7948
7974
  * const roomWorld = new World({ name: 'Room_001' });
7949
7975
  *
7976
+ * // 注册World级别的服务
7977
+ * roomWorld.services.registerSingleton(RoomManager);
7978
+ *
7950
7979
  * // 在World中创建Scene
7951
7980
  * const gameScene = roomWorld.createScene('game', new Scene());
7952
7981
  * const uiScene = roomWorld.createScene('ui', new Scene());
7953
7982
  *
7983
+ * // 在Scene中使用World级别的服务
7984
+ * const roomManager = roomWorld.services.resolve(RoomManager);
7985
+ *
7954
7986
  * // 更新整个World
7955
7987
  * roomWorld.update(deltaTime);
7956
7988
  * ```
@@ -7961,9 +7993,15 @@ declare class World {
7961
7993
  private readonly _scenes;
7962
7994
  private readonly _activeScenes;
7963
7995
  private readonly _globalSystems;
7996
+ private readonly _services;
7964
7997
  private _isActive;
7965
7998
  private _createdAt;
7966
7999
  constructor(config?: IWorldConfig);
8000
+ /**
8001
+ * World级别的服务容器
8002
+ * 用于管理World范围内的全局服务
8003
+ */
8004
+ get services(): ServiceContainer;
7967
8005
  /**
7968
8006
  * 创建并添加Scene到World
7969
8007
  */
@@ -8116,9 +8154,9 @@ interface IWorldManagerConfig {
8116
8154
  */
8117
8155
  autoCleanup?: boolean;
8118
8156
  /**
8119
- * 清理间隔(毫秒)
8157
+ * 清理间隔(帧数)
8120
8158
  */
8121
- cleanupInterval?: number;
8159
+ cleanupFrameInterval?: number;
8122
8160
  /**
8123
8161
  * 是否启用调试模式
8124
8162
  */
@@ -8160,9 +8198,8 @@ interface IWorldManagerConfig {
8160
8198
  declare class WorldManager implements IService {
8161
8199
  private readonly _config;
8162
8200
  private readonly _worlds;
8163
- private readonly _activeWorlds;
8164
- private _cleanupTimer;
8165
8201
  private _isRunning;
8202
+ private _framesSinceCleanup;
8166
8203
  constructor(config?: IWorldManagerConfig);
8167
8204
  /**
8168
8205
  * 创建新World
@@ -8239,22 +8276,10 @@ declare class WorldManager implements IService {
8239
8276
  memoryUsage: number;
8240
8277
  isRunning: boolean;
8241
8278
  config: {
8242
- /**
8243
- * 最大World数量
8244
- */
8245
- maxWorlds?: number;
8246
- /**
8247
- * 是否自动清理空World
8248
- */
8249
- autoCleanup?: boolean;
8250
- /**
8251
- * 清理间隔(毫秒)
8252
- */
8253
- cleanupInterval?: number;
8254
- /**
8255
- * 是否启用调试模式
8256
- */
8257
- debug?: boolean;
8279
+ maxWorlds: number;
8280
+ autoCleanup: boolean;
8281
+ cleanupFrameInterval: number;
8282
+ debug: boolean;
8258
8283
  };
8259
8284
  worlds: any[];
8260
8285
  };
@@ -8293,22 +8318,10 @@ declare class WorldManager implements IService {
8293
8318
  memoryUsage: number;
8294
8319
  isRunning: boolean;
8295
8320
  config: {
8296
- /**
8297
- * 最大World数量
8298
- */
8299
- maxWorlds?: number;
8300
- /**
8301
- * 是否自动清理空World
8302
- */
8303
- autoCleanup?: boolean;
8304
- /**
8305
- * 清理间隔(毫秒)
8306
- */
8307
- cleanupInterval?: number;
8308
- /**
8309
- * 是否启用调试模式
8310
- */
8311
- debug?: boolean;
8321
+ maxWorlds: number;
8322
+ autoCleanup: boolean;
8323
+ cleanupFrameInterval: number;
8324
+ debug: boolean;
8312
8325
  };
8313
8326
  };
8314
8327
  /**
@@ -8324,16 +8337,12 @@ declare class WorldManager implements IService {
8324
8337
  * 调用 destroy 方法进行清理
8325
8338
  */
8326
8339
  dispose(): void;
8327
- /**
8328
- * 启动清理定时器
8329
- */
8330
- private startCleanupTimer;
8331
- /**
8332
- * 停止清理定时器
8333
- */
8334
- private stopCleanupTimer;
8335
8340
  /**
8336
8341
  * 判断World是否应该被清理
8342
+ * 清理策略:
8343
+ * 1. World未激活
8344
+ * 2. 没有Scene或所有Scene都是空的
8345
+ * 3. 创建时间超过10分钟
8337
8346
  */
8338
8347
  private shouldCleanupWorld;
8339
8348
  /**