统一的World管理路径

This commit is contained in:
YHH
2025-10-11 15:14:37 +08:00
parent c19b5ae9a7
commit 532a52acfc
5 changed files with 119 additions and 65 deletions

View File

@@ -13,6 +13,7 @@ import { ServiceContainer } from './Core/ServiceContainer';
import { PluginManager } from './Core/PluginManager';
import { IPlugin } from './Core/Plugin';
import { WorldManager } from './ECS/WorldManager';
import { registerInjectable } from './Core/DI';
/**
* 游戏引擎核心类
@@ -177,9 +178,14 @@ export class Core {
this._poolManager = new PoolManager();
this._serviceContainer.registerInstance(PoolManager, this._poolManager);
// 初始化场景管理器
this._sceneManager = new SceneManager();
this._serviceContainer.registerInstance(SceneManager, this._sceneManager);
// 使用依赖注入自动注册WorldManager和SceneManager
// WorldManager会在构造时创建默认World
registerInjectable(this._serviceContainer, WorldManager);
this._worldManager = this._serviceContainer.resolve(WorldManager);
// SceneManager会通过@Inject自动获取WorldManager
registerInjectable(this._serviceContainer, SceneManager);
this._sceneManager = this._serviceContainer.resolve(SceneManager);
// 设置场景切换回调,通知调试管理器
this._sceneManager.setSceneChangedCallback(() => {
@@ -188,10 +194,6 @@ export class Core {
}
});
// 初始化World管理器
this._worldManager = new WorldManager();
this._serviceContainer.registerInstance(WorldManager, this._worldManager);
// 初始化插件管理器
this._pluginManager = new PluginManager();
this._pluginManager.initialize(this, this._serviceContainer);
@@ -645,7 +647,7 @@ export class Core {
this._performanceMonitor.updateFPS(Time.deltaTime);
}
// 更新所有可更新的服务
// 更新所有@Updatable服务(包括TimerManager, WorldManager, SceneManager等)
const servicesStartTime = this._performanceMonitor.startMonitoring('Services.update');
this._serviceContainer.updateAll(deltaTime);
this._performanceMonitor.endMonitoring('Services.update', servicesStartTime, this._serviceContainer.getUpdatableCount());
@@ -653,12 +655,6 @@ export class Core {
// 更新对象池管理器
this._poolManager.update();
// 更新默认场景(通过 SceneManager
this._sceneManager.update();
// 更新额外的 WorldManager
this._worldManager.updateAll();
// 更新调试管理器基于FPS的数据发送
if (this._debugManager) {
this._debugManager.onFrameUpdate(deltaTime);