diff --git a/package-lock.json b/package-lock.json index 53d72ecb..0eba6a8e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14515,7 +14515,6 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "dev": true, "license": "0BSD" }, "node_modules/tuf-js": { @@ -15560,7 +15559,8 @@ "version": "2.2.0", "license": "MIT", "dependencies": { - "msgpack-lite": "^0.1.26" + "msgpack-lite": "^0.1.26", + "tslib": "^2.8.1" }, "devDependencies": { "@babel/core": "^7.28.3", diff --git a/packages/core/package.json b/packages/core/package.json index a0c6642a..ad070cf4 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -78,6 +78,7 @@ "directory": "packages/core" }, "dependencies": { - "msgpack-lite": "^0.1.26" + "msgpack-lite": "^0.1.26", + "tslib": "^2.8.1" } } diff --git a/packages/core/rollup.config.cjs b/packages/core/rollup.config.cjs index a490eac2..3beb93a9 100644 --- a/packages/core/rollup.config.cjs +++ b/packages/core/rollup.config.cjs @@ -52,6 +52,13 @@ module.exports = [ }) ], external, + onwarn(warning, warn) { + // 忽略 msgpack-lite 的循环依赖警告 + if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.ids && warning.ids.some(id => id.includes('msgpack-lite'))) { + return; + } + warn(warning); + }, treeshake: { moduleSideEffects: false, propertyReadSideEffects: false, @@ -78,6 +85,12 @@ module.exports = [ }) ], external, + onwarn(warning, warn) { + if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.ids && warning.ids.some(id => id.includes('msgpack-lite'))) { + return; + } + warn(warning); + }, treeshake: { moduleSideEffects: false } @@ -103,6 +116,12 @@ module.exports = [ }) ], external: [], + onwarn(warning, warn) { + if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.ids && warning.ids.some(id => id.includes('msgpack-lite'))) { + return; + } + warn(warning); + }, treeshake: { moduleSideEffects: false } @@ -157,6 +176,12 @@ module.exports = [ }) ], external: [], + onwarn(warning, warn) { + if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.ids && warning.ids.some(id => id.includes('msgpack-lite'))) { + return; + } + warn(warning); + }, treeshake: { moduleSideEffects: false } diff --git a/packages/core/src/Core.ts b/packages/core/src/Core.ts index 47e38d16..b4844d24 100644 --- a/packages/core/src/Core.ts +++ b/packages/core/src/Core.ts @@ -173,6 +173,13 @@ export class Core { this._sceneManager = new SceneManager(); this._serviceContainer.registerInstance(SceneManager, this._sceneManager); + // 设置场景切换回调,通知调试管理器 + this._sceneManager.setSceneChangedCallback(() => { + if (this._debugManager) { + this._debugManager.onSceneChanged(); + } + }); + // 初始化插件管理器 this._pluginManager = new PluginManager(); this._pluginManager.initialize(this, this._serviceContainer); diff --git a/packages/core/src/ECS/Scene.ts b/packages/core/src/ECS/Scene.ts index 5f22110e..f57c5818 100644 --- a/packages/core/src/ECS/Scene.ts +++ b/packages/core/src/ECS/Scene.ts @@ -14,7 +14,6 @@ import { SceneSerializer, SceneSerializationOptions, SceneDeserializationOptions import { IncrementalSerializer, IncrementalSnapshot, IncrementalSerializationOptions } from './Serialization/IncrementalSerializer'; import { ComponentPoolManager } from './Core/ComponentPool'; import { PerformanceMonitor } from '../Utils/PerformanceMonitor'; -import { Core } from '../Core'; import { ServiceContainer, type ServiceType } from '../Core/ServiceContainer'; import { createInstance, isInjectable } from '../Core/DI'; import { isUpdatable, getUpdatableMetadata } from '../Core/DI/Decorators'; @@ -183,11 +182,9 @@ export class Scene implements IScene { this._services = new ServiceContainer(); this.logger = createLogger('Scene'); - if (config?.performanceMonitor) { - this._performanceMonitor = config.performanceMonitor; - } else { - this._performanceMonitor = Core.services.resolve(PerformanceMonitor); - } + // 从配置获取 PerformanceMonitor,如果未提供则创建一个新实例 + // Scene 应该是独立的,不依赖于 Core,通过构造函数参数明确依赖关系 + this._performanceMonitor = config?.performanceMonitor || new PerformanceMonitor(); if (config?.name) { this.name = config.name; diff --git a/packages/core/src/ECS/SceneManager.ts b/packages/core/src/ECS/SceneManager.ts index 6f1c725d..fa33a920 100644 --- a/packages/core/src/ECS/SceneManager.ts +++ b/packages/core/src/ECS/SceneManager.ts @@ -1,7 +1,6 @@ import { IScene } from './IScene'; import { ECSFluentAPI, createECSAPI } from './Core/FluentAPI'; import { Time } from '../Utils/Time'; -import { Core } from '../Core'; import { createLogger } from '../Utils/Logger'; import type { IService } from '../Core/ServiceContainer'; @@ -68,6 +67,21 @@ export class SceneManager implements IService { */ private _logger = createLogger('SceneManager'); + /** + * 场景切换回调函数 + */ + private _onSceneChangedCallback?: () => void; + + /** + * 设置场景切换回调 + * + * @param callback 场景切换时的回调函数 + * @internal + */ + public setSceneChangedCallback(callback: () => void): void { + this._onSceneChangedCallback = callback; + } + /** * 设置当前场景(立即切换) * @@ -104,10 +118,9 @@ export class SceneManager implements IService { // 触发场景切换回调 Time.sceneChanged(); - // 通知调试管理器 - const coreInstance = Core.Instance; - if (coreInstance && coreInstance._debugManager) { - coreInstance._debugManager.onSceneChanged(); + // 通知调试管理器(通过回调) + if (this._onSceneChangedCallback) { + this._onSceneChangedCallback(); } this._logger.info(`Scene changed to: ${scene.name}`); diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index d9789258..ecf4f785 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -28,7 +28,7 @@ "noUncheckedIndexedAccess": false, "experimentalDecorators": true, "emitDecoratorMetadata": true, - "importHelpers": false, + "importHelpers": true, "downlevelIteration": true, "isolatedModules": false, "allowJs": true,