performancemonitor由内部框架维护
This commit is contained in:
@@ -21,7 +21,7 @@ import { createLogger } from '../Utils/Logger';
|
||||
|
||||
/**
|
||||
* 游戏场景默认实现类
|
||||
*
|
||||
*
|
||||
* 实现IScene接口,提供场景的基础功能。
|
||||
* 推荐使用组合而非继承的方式来构建自定义场景。
|
||||
*/
|
||||
@@ -97,11 +97,11 @@ export class Scene implements IScene {
|
||||
private readonly logger: ReturnType<typeof createLogger>;
|
||||
|
||||
/**
|
||||
* 性能监控器
|
||||
* 性能监控器缓存
|
||||
*
|
||||
* 用于监控场景和系统的性能。可以在构造函数中注入,如果不提供则从Core获取。
|
||||
* 用于监控场景和系统的性能。从 ServiceContainer 获取。
|
||||
*/
|
||||
private readonly _performanceMonitor: PerformanceMonitor;
|
||||
private _performanceMonitor: PerformanceMonitor | null = null;
|
||||
|
||||
/**
|
||||
* 场景是否已开始运行
|
||||
@@ -182,10 +182,6 @@ export class Scene implements IScene {
|
||||
this._services = new ServiceContainer();
|
||||
this.logger = createLogger('Scene');
|
||||
|
||||
// 从配置获取 PerformanceMonitor,如果未提供则创建一个新实例
|
||||
// Scene 应该是独立的,不依赖于 Core,通过构造函数参数明确依赖关系
|
||||
this._performanceMonitor = config?.performanceMonitor || new PerformanceMonitor();
|
||||
|
||||
if (config?.name) {
|
||||
this.name = config.name;
|
||||
}
|
||||
@@ -201,6 +197,19 @@ export class Scene implements IScene {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取性能监控器
|
||||
*
|
||||
* 从 ServiceContainer 获取,如果未注册则创建默认实例(向后兼容)
|
||||
*/
|
||||
private get performanceMonitor(): PerformanceMonitor {
|
||||
if (!this._performanceMonitor) {
|
||||
this._performanceMonitor = this._services.tryResolve(PerformanceMonitor)
|
||||
?? new PerformanceMonitor();
|
||||
}
|
||||
return this._performanceMonitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化场景
|
||||
*
|
||||
@@ -578,7 +587,7 @@ export class Scene implements IScene {
|
||||
|
||||
system.scene = this;
|
||||
|
||||
system.setPerformanceMonitor(this._performanceMonitor);
|
||||
system.setPerformanceMonitor(this.performanceMonitor);
|
||||
|
||||
const metadata = getSystemMetadata(constructor);
|
||||
if (metadata?.updateOrder !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user