* @zh 创建核心实例 * @en Create core instance * * @param config - @zh Core配置对象 @en Core configuration object
(config: ICoreConfig = {})
| 129 | * @param config - @zh Core配置对象 @en Core configuration object |
| 130 | */ |
| 131 | private constructor(config: ICoreConfig = {}) { |
| 132 | Core._instance = this; |
| 133 | this._config = { debug: true, ...config }; |
| 134 | this._serviceContainer = new ServiceContainer(); |
| 135 | |
| 136 | this._timerManager = new TimerManager(); |
| 137 | this._serviceContainer.registerInstance(TimerManager, this._timerManager); |
| 138 | |
| 139 | this._performanceMonitor = new PerformanceMonitor(); |
| 140 | this._serviceContainer.registerInstance(PerformanceMonitor, this._performanceMonitor); |
| 141 | if (this._config.debug) { |
| 142 | this._performanceMonitor.enable(); |
| 143 | } |
| 144 | |
| 145 | this._poolManager = new PoolManager(); |
| 146 | this._serviceContainer.registerInstance(PoolManager, this._poolManager); |
| 147 | |
| 148 | this._sceneManager = new SceneManager(this._performanceMonitor); |
| 149 | this._serviceContainer.registerInstance(SceneManager, this._sceneManager); |
| 150 | this._sceneManager.setSceneChangedCallback(() => this._debugManager?.onSceneChanged()); |
| 151 | |
| 152 | this._worldManager = new WorldManager({ debug: !!this._config.debug, ...this._config.worldManagerConfig }); |
| 153 | this._serviceContainer.registerInstance(WorldManager, this._worldManager); |
| 154 | |
| 155 | this._pluginManager = new PluginManager(); |
| 156 | this._pluginManager.initialize(this, this._serviceContainer); |
| 157 | this._serviceContainer.registerInstance(PluginManager, this._pluginManager); |
| 158 | |
| 159 | this._pluginServiceRegistry = new PluginServiceRegistry(); |
| 160 | this._serviceContainer.registerInstance(PluginServiceRegistry, this._pluginServiceRegistry); |
| 161 | |
| 162 | this.debug = this._config.debug ?? true; |
| 163 | |
| 164 | if (this._config.debugConfig?.enabled) { |
| 165 | const configService = new DebugConfigService(); |
| 166 | configService.setConfig(this._config.debugConfig); |
| 167 | this._serviceContainer.registerInstance(DebugConfigService, configService); |
| 168 | this._serviceContainer.registerSingleton(DebugManager, (c) => createInstance(DebugManager, c)); |
| 169 | this._debugManager = this._serviceContainer.resolve(DebugManager); |
| 170 | this._debugManager.onInitialize(); |
| 171 | } |
| 172 | |
| 173 | this.initialize(); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * @zh 获取核心实例 |
nothing calls this directly
no test coverage detected