WorldManager 现在由 ServiceContainer 统一管理

This commit is contained in:
YHH
2025-10-11 10:40:10 +08:00
parent a0177c9163
commit 4a060e1ce3
2 changed files with 22 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ import { IScene } from './ECS/IScene';
import { ServiceContainer } from './Core/ServiceContainer';
import { PluginManager } from './Core/PluginManager';
import { IPlugin } from './Core/Plugin';
import { WorldManager } from './ECS/WorldManager';
/**
* 游戏引擎核心类
@@ -122,6 +123,13 @@ export class Core {
*/
private _sceneManager: SceneManager;
/**
* World管理器
*
* 管理多个独立的World实例可选
*/
private _worldManager: WorldManager;
/**
* 插件管理器
*
@@ -180,6 +188,10 @@ export class Core {
}
});
// 初始化World管理器
this._worldManager = new WorldManager();
this._serviceContainer.registerInstance(WorldManager, this._worldManager);
// 初始化插件管理器
this._pluginManager = new PluginManager();
this._pluginManager.initialize(this, this._serviceContainer);

View File

@@ -1,5 +1,6 @@
import { World, IWorldConfig } from './World';
import { createLogger } from '../Utils/Logger';
import type { IService } from '../Core/ServiceContainer';
const logger = createLogger('WorldManager');
@@ -61,7 +62,7 @@ export interface IWorldManagerConfig {
* }
* ```
*/
export class WorldManager {
export class WorldManager implements IService {
private readonly _config: IWorldManagerConfig;
private readonly _worlds: Map<string, World> = new Map();
private readonly _activeWorlds: Set<string> = new Set();
@@ -387,6 +388,14 @@ export class WorldManager {
logger.info('WorldManager已销毁');
}
/**
* 实现 IService 接口的 dispose 方法
* 调用 destroy 方法进行清理
*/
public dispose(): void {
this.destroy();
}
// ===== 私有方法 =====
/**