entitysytem的logger返回类型更改,需要重写实现getLoggerName

This commit is contained in:
YHH
2025-09-29 09:53:13 +08:00
parent 61fcd52c65
commit d62bf9f7f9
4 changed files with 28 additions and 7 deletions

View File

@@ -51,7 +51,7 @@ export abstract class EntitySystem implements ISystemBase {
private _matcher: Matcher; private _matcher: Matcher;
private _eventListeners: EventListenerRecord[]; private _eventListeners: EventListenerRecord[];
private _scene: Scene | null; private _scene: Scene | null;
protected logger = createLogger('EntitySystem'); protected logger: ReturnType<typeof createLogger>;
/** /**
@@ -136,6 +136,9 @@ export abstract class EntitySystem implements ISystemBase {
this._entityIdMapVersion = -1; this._entityIdMapVersion = -1;
this._entityIdMapSize = 0; this._entityIdMapSize = 0;
// 初始化logger
this.logger = createLogger(this.getLoggerName());
this._entityCache = { this._entityCache = {
frame: null, frame: null,
@@ -773,6 +776,14 @@ export abstract class EntitySystem implements ISystemBase {
this.onDestroy(); this.onDestroy();
} }
/**
* 获取Logger名称
* 子类可以重写此方法来自定义logger名称
*/
protected getLoggerName(): string {
return 'EntitySystem';
}
/** /**
* 用户销毁回调 * 用户销毁回调
* *

View File

@@ -199,8 +199,6 @@ export abstract class WorkerEntitySystem<TEntityData = any> extends EntitySystem
constructor(matcher?: Matcher, config: WorkerSystemConfig = {}) { constructor(matcher?: Matcher, config: WorkerSystemConfig = {}) {
super(matcher); super(matcher);
this.logger = createLogger('WorkerEntitySystem');
// 验证和调整 worker 数量,确保不超过系统最大值 // 验证和调整 worker 数量,确保不超过系统最大值
const requestedWorkerCount = config.workerCount ?? this.getMaxSystemWorkerCount(); const requestedWorkerCount = config.workerCount ?? this.getMaxSystemWorkerCount();
const maxSystemWorkerCount = this.getMaxSystemWorkerCount(); const maxSystemWorkerCount = this.getMaxSystemWorkerCount();
@@ -827,6 +825,10 @@ export abstract class WorkerEntitySystem<TEntityData = any> extends EntitySystem
this.workerPool = null; this.workerPool = null;
} }
} }
protected override getLoggerName(): string {
return 'WorkerEntitySystem';
}
} }
/** /**

View File

@@ -87,7 +87,6 @@ interface ClientSyncStats {
* 负责接收和应用服务端同步数据,处理本地预测和插值 * 负责接收和应用服务端同步数据,处理本地预测和插值
*/ */
export class ClientSyncSystem extends EntitySystem { export class ClientSyncSystem extends EntitySystem {
private logger = createLogger('ClientSyncSystem');
private config: ClientSyncSystemConfig; private config: ClientSyncSystemConfig;
private syncVarManager: SyncVarManager; private syncVarManager: SyncVarManager;
private serializer: SyncVarSerializer; private serializer: SyncVarSerializer;
@@ -304,11 +303,16 @@ export class ClientSyncSystem extends EntitySystem {
/** /**
* 销毁系统 * 销毁系统
*/ */
public destroy(): void { public override destroy(): void {
this.remoteEntities.clear(); this.remoteEntities.clear();
this.predictions.clear(); this.predictions.clear();
this.interpolations.clear(); this.interpolations.clear();
this.localEntityMap.clear(); this.localEntityMap.clear();
super.destroy();
}
protected override getLoggerName(): string {
return 'ClientSyncSystem';
} }
/** /**

View File

@@ -69,7 +69,6 @@ interface SyncSystemStats {
* 负责收集所有SyncVar变化并向客户端同步 * 负责收集所有SyncVar变化并向客户端同步
*/ */
export class SyncVarSystem extends EntitySystem { export class SyncVarSystem extends EntitySystem {
private logger = createLogger('SyncVarSystem');
private config: SyncVarSystemConfig; private config: SyncVarSystemConfig;
private syncVarManager: SyncVarManager; private syncVarManager: SyncVarManager;
private serializer: SyncVarSerializer; private serializer: SyncVarSerializer;
@@ -239,10 +238,15 @@ export class SyncVarSystem extends EntitySystem {
/** /**
* 销毁系统 * 销毁系统
*/ */
public destroy(): void { public override destroy(): void {
this.stopSyncTimer(); this.stopSyncTimer();
this.clientStates.clear(); this.clientStates.clear();
this.pendingBatches.length = 0; this.pendingBatches.length = 0;
super.destroy();
}
protected override getLoggerName(): string {
return 'SyncVarSystem';
} }
/** /**