Merge remote-tracking branch 'origin/master' into issue-94-响应式查询(Reactive_Query_System)/_Event-driven_Query
This commit is contained in:
@@ -13,6 +13,8 @@ import { ServiceContainer } from './Core/ServiceContainer';
|
||||
import { PluginManager } from './Core/PluginManager';
|
||||
import { IPlugin } from './Core/Plugin';
|
||||
import { WorldManager } from './ECS/WorldManager';
|
||||
import { DebugConfigService } from './Utils/Debug/DebugConfigService';
|
||||
import { createInstance } from './Core/DI/Decorators';
|
||||
|
||||
/**
|
||||
* 游戏引擎核心类
|
||||
@@ -202,14 +204,15 @@ export class Core {
|
||||
|
||||
// 初始化调试管理器
|
||||
if (this._config.debugConfig?.enabled) {
|
||||
// 使用DI容器创建DebugManager(前两个参数从容器解析,config手动传入)
|
||||
const config = this._config.debugConfig;
|
||||
this._debugManager = new DebugManager(
|
||||
this._serviceContainer.resolve(SceneManager),
|
||||
this._serviceContainer.resolve(PerformanceMonitor),
|
||||
config
|
||||
const configService = new DebugConfigService();
|
||||
configService.setConfig(this._config.debugConfig);
|
||||
this._serviceContainer.registerInstance(DebugConfigService, configService);
|
||||
|
||||
this._serviceContainer.registerSingleton(DebugManager, (c) =>
|
||||
createInstance(DebugManager, c)
|
||||
);
|
||||
this._serviceContainer.registerInstance(DebugManager, this._debugManager);
|
||||
|
||||
this._debugManager = this._serviceContainer.resolve(DebugManager);
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
@@ -476,13 +479,15 @@ export class Core {
|
||||
if (this._instance._debugManager) {
|
||||
this._instance._debugManager.updateConfig(config);
|
||||
} else {
|
||||
// 使用DI容器创建DebugManager
|
||||
this._instance._debugManager = new DebugManager(
|
||||
this._instance._serviceContainer.resolve(SceneManager),
|
||||
this._instance._serviceContainer.resolve(PerformanceMonitor),
|
||||
config
|
||||
const configService = new DebugConfigService();
|
||||
configService.setConfig(config);
|
||||
this._instance._serviceContainer.registerInstance(DebugConfigService, configService);
|
||||
|
||||
this._instance._serviceContainer.registerSingleton(DebugManager, (c) =>
|
||||
createInstance(DebugManager, c)
|
||||
);
|
||||
this._instance._serviceContainer.registerInstance(DebugManager, this._instance._debugManager);
|
||||
|
||||
this._instance._debugManager = this._instance._serviceContainer.resolve(DebugManager);
|
||||
}
|
||||
|
||||
// 更新Core配置
|
||||
@@ -659,11 +664,6 @@ export class Core {
|
||||
// 更新额外的 WorldManager
|
||||
this._worldManager.updateAll();
|
||||
|
||||
// 更新调试管理器(基于FPS的数据发送)
|
||||
if (this._debugManager) {
|
||||
this._debugManager.onFrameUpdate(deltaTime);
|
||||
}
|
||||
|
||||
// 结束性能监控
|
||||
this._performanceMonitor.endMonitoring('Core.update', frameStartTime);
|
||||
}
|
||||
|
||||
45
packages/core/src/Utils/Debug/DebugConfigService.ts
Normal file
45
packages/core/src/Utils/Debug/DebugConfigService.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { IECSDebugConfig } from '../../Types';
|
||||
import { Injectable } from '../../Core/DI/Decorators';
|
||||
import type { IService } from '../../Core/ServiceContainer';
|
||||
|
||||
/**
|
||||
* 调试配置服务
|
||||
*
|
||||
* 管理调试系统的配置信息
|
||||
*/
|
||||
@Injectable()
|
||||
export class DebugConfigService implements IService {
|
||||
private _config: IECSDebugConfig;
|
||||
|
||||
constructor() {
|
||||
this._config = {
|
||||
enabled: false,
|
||||
websocketUrl: '',
|
||||
debugFrameRate: 30,
|
||||
autoReconnect: true,
|
||||
channels: {
|
||||
entities: true,
|
||||
systems: true,
|
||||
performance: true,
|
||||
components: true,
|
||||
scenes: true
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public setConfig(config: IECSDebugConfig): void {
|
||||
this._config = config;
|
||||
}
|
||||
|
||||
public getConfig(): IECSDebugConfig {
|
||||
return this._config;
|
||||
}
|
||||
|
||||
public isEnabled(): boolean {
|
||||
return this._config.enabled;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
// 清理资源
|
||||
}
|
||||
}
|
||||
@@ -10,17 +10,20 @@ import { ComponentPoolManager } from '../../ECS/Core/ComponentPool';
|
||||
import { Pool } from '../../Utils/Pool';
|
||||
import { getComponentInstanceTypeName, getSystemInstanceTypeName } from '../../ECS/Decorators';
|
||||
import type { IService } from '../../Core/ServiceContainer';
|
||||
import type { IUpdatable } from '../../Types/IUpdatable';
|
||||
import { SceneManager } from '../../ECS/SceneManager';
|
||||
import { PerformanceMonitor } from '../PerformanceMonitor';
|
||||
import { Injectable, Inject, Updatable } from '../../Core/DI/Decorators';
|
||||
import { DebugConfigService } from './DebugConfigService';
|
||||
|
||||
/**
|
||||
* 调试管理器
|
||||
*
|
||||
* 整合所有调试数据收集器,负责收集和发送调试数据
|
||||
*
|
||||
* 通过构造函数接收SceneManager和PerformanceMonitor,避免直接依赖Core实例
|
||||
*/
|
||||
export class DebugManager implements IService {
|
||||
@Injectable()
|
||||
@Updatable()
|
||||
export class DebugManager implements IService, IUpdatable {
|
||||
private config: IECSDebugConfig;
|
||||
private webSocketManager: WebSocketManager;
|
||||
private entityCollector: EntityDataCollector;
|
||||
@@ -36,18 +39,12 @@ export class DebugManager implements IService {
|
||||
private sendInterval: number;
|
||||
private isRunning: boolean = false;
|
||||
|
||||
/**
|
||||
* 构造调试管理器
|
||||
* @param sceneManager 场景管理器
|
||||
* @param performanceMonitor 性能监控器
|
||||
* @param config 调试配置
|
||||
*/
|
||||
constructor(
|
||||
sceneManager: SceneManager,
|
||||
performanceMonitor: PerformanceMonitor,
|
||||
config: IECSDebugConfig
|
||||
@Inject(SceneManager) sceneManager: SceneManager,
|
||||
@Inject(PerformanceMonitor) performanceMonitor: PerformanceMonitor,
|
||||
@Inject(DebugConfigService) configService: DebugConfigService
|
||||
) {
|
||||
this.config = config;
|
||||
this.config = configService.getConfig();
|
||||
this.sceneManager = sceneManager;
|
||||
this.performanceMonitor = performanceMonitor;
|
||||
|
||||
@@ -60,15 +57,15 @@ export class DebugManager implements IService {
|
||||
|
||||
// 初始化WebSocket管理器
|
||||
this.webSocketManager = new WebSocketManager(
|
||||
config.websocketUrl,
|
||||
config.autoReconnect !== false
|
||||
this.config.websocketUrl,
|
||||
this.config.autoReconnect !== false
|
||||
);
|
||||
|
||||
// 设置消息处理回调
|
||||
this.webSocketManager.setMessageHandler(this.handleMessage.bind(this));
|
||||
|
||||
// 计算发送间隔(基于帧率)
|
||||
const debugFrameRate = config.debugFrameRate || 30;
|
||||
const debugFrameRate = this.config.debugFrameRate || 30;
|
||||
this.sendInterval = 1000 / debugFrameRate;
|
||||
|
||||
this.start();
|
||||
@@ -116,16 +113,12 @@ export class DebugManager implements IService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 帧更新回调
|
||||
*/
|
||||
public onFrameUpdate(deltaTime: number): void {
|
||||
public update(deltaTime?: number): void {
|
||||
if (!this.isRunning || !this.config.enabled) return;
|
||||
|
||||
this.frameCounter++;
|
||||
const currentTime = Date.now();
|
||||
|
||||
// 基于配置的帧率发送数据
|
||||
if (currentTime - this.lastSendTime >= this.sendInterval) {
|
||||
this.sendDebugData();
|
||||
this.lastSendTime = currentTime;
|
||||
|
||||
@@ -4,4 +4,5 @@ export { PerformanceDataCollector } from './PerformanceDataCollector';
|
||||
export { ComponentDataCollector } from './ComponentDataCollector';
|
||||
export { SceneDataCollector } from './SceneDataCollector';
|
||||
export { WebSocketManager } from './WebSocketManager';
|
||||
export { DebugManager } from './DebugManager';
|
||||
export { DebugManager } from './DebugManager';
|
||||
export { DebugConfigService } from './DebugConfigService';
|
||||
Reference in New Issue
Block a user