更新性能分析器及更改部分注释
This commit is contained in:
@@ -329,7 +329,7 @@ export class DirtyTrackingSystem {
|
||||
try {
|
||||
listener.callback(dirtyData);
|
||||
} catch (error) {
|
||||
console.error('Dirty listener error:', error);
|
||||
console.error('脏数据监听器错误:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -346,7 +346,7 @@ export class DirtyTrackingSystem {
|
||||
try {
|
||||
listener.callback(dirtyData);
|
||||
} catch (error) {
|
||||
console.error('Dirty listener notification error:', error);
|
||||
console.error('脏数据监听器通知错误:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export class EventBus implements IEventBus {
|
||||
const enhancedData = this.enhanceEventData(eventType, data);
|
||||
|
||||
if (this.isDebugMode) {
|
||||
console.log(`[EventBus] Emitting event: ${eventType}`, enhancedData);
|
||||
console.log(`[EventBus] 发射事件: ${eventType}`, enhancedData);
|
||||
}
|
||||
|
||||
this.eventSystem.emitSync(eventType, enhancedData);
|
||||
@@ -65,7 +65,7 @@ export class EventBus implements IEventBus {
|
||||
const enhancedData = this.enhanceEventData(eventType, data);
|
||||
|
||||
if (this.isDebugMode) {
|
||||
console.log(`[EventBus] Emitting async event: ${eventType}`, enhancedData);
|
||||
console.log(`[EventBus] 发射异步事件: ${eventType}`, enhancedData);
|
||||
}
|
||||
|
||||
await this.eventSystem.emit(eventType, enhancedData);
|
||||
@@ -93,7 +93,7 @@ export class EventBus implements IEventBus {
|
||||
};
|
||||
|
||||
if (this.isDebugMode) {
|
||||
console.log(`[EventBus] Adding listener for: ${eventType}`, eventConfig);
|
||||
console.log(`[EventBus] 添加监听器: ${eventType}`, eventConfig);
|
||||
}
|
||||
|
||||
return this.eventSystem.on(eventType, handler, eventConfig);
|
||||
@@ -136,7 +136,7 @@ export class EventBus implements IEventBus {
|
||||
*/
|
||||
public off(eventType: string, listenerId: string): boolean {
|
||||
if (this.isDebugMode) {
|
||||
console.log(`[EventBus] Removing listener: ${listenerId} for event: ${eventType}`);
|
||||
console.log(`[EventBus] 移除监听器: ${listenerId} 事件: ${eventType}`);
|
||||
}
|
||||
|
||||
return this.eventSystem.off(eventType, listenerId);
|
||||
@@ -148,7 +148,7 @@ export class EventBus implements IEventBus {
|
||||
*/
|
||||
public offAll(eventType: string): void {
|
||||
if (this.isDebugMode) {
|
||||
console.log(`[EventBus] Removing all listeners for event: ${eventType}`);
|
||||
console.log(`[EventBus] 移除所有监听器: ${eventType}`);
|
||||
}
|
||||
|
||||
this.eventSystem.offAll(eventType);
|
||||
@@ -186,7 +186,7 @@ export class EventBus implements IEventBus {
|
||||
*/
|
||||
public clear(): void {
|
||||
if (this.isDebugMode) {
|
||||
console.log('[EventBus] Clearing all listeners');
|
||||
console.log('[EventBus] 清空所有监听器');
|
||||
}
|
||||
|
||||
this.eventSystem.clear();
|
||||
@@ -379,7 +379,7 @@ export class EventBus implements IEventBus {
|
||||
private validateEventType(eventType: string): void {
|
||||
if (!EventTypeValidator.isValid(eventType)) {
|
||||
if (this.isDebugMode) {
|
||||
console.warn(`[EventBus] Unknown event type: ${eventType}`);
|
||||
console.warn(`[EventBus] 未知事件类型: ${eventType}`);
|
||||
}
|
||||
// 在调试模式下添加自定义事件类型
|
||||
if (this.isDebugMode) {
|
||||
|
||||
@@ -83,8 +83,8 @@ export class TypeSafeEventSystem {
|
||||
* @returns 监听器ID(用于移除)
|
||||
*/
|
||||
public on<T>(
|
||||
eventType: string,
|
||||
handler: EventHandler<T>,
|
||||
eventType: string,
|
||||
handler: EventHandler<T>,
|
||||
config: EventListenerConfig = {}
|
||||
): string {
|
||||
return this.addListener(eventType, handler, config);
|
||||
@@ -98,8 +98,8 @@ export class TypeSafeEventSystem {
|
||||
* @returns 监听器ID
|
||||
*/
|
||||
public once<T>(
|
||||
eventType: string,
|
||||
handler: EventHandler<T>,
|
||||
eventType: string,
|
||||
handler: EventHandler<T>,
|
||||
config: EventListenerConfig = {}
|
||||
): string {
|
||||
return this.addListener(eventType, handler, { ...config, once: true });
|
||||
@@ -113,8 +113,8 @@ export class TypeSafeEventSystem {
|
||||
* @returns 监听器ID
|
||||
*/
|
||||
public onAsync<T>(
|
||||
eventType: string,
|
||||
handler: AsyncEventHandler<T>,
|
||||
eventType: string,
|
||||
handler: AsyncEventHandler<T>,
|
||||
config: EventListenerConfig = {}
|
||||
): string {
|
||||
return this.addListener(eventType, handler, { ...config, async: true });
|
||||
@@ -134,7 +134,7 @@ export class TypeSafeEventSystem {
|
||||
if (index === -1) return false;
|
||||
|
||||
listeners.splice(index, 1);
|
||||
|
||||
|
||||
// 如果没有监听器了,清理相关数据
|
||||
if (listeners.length === 0) {
|
||||
this.listeners.delete(eventType);
|
||||
@@ -204,7 +204,7 @@ export class TypeSafeEventSystem {
|
||||
toRemove.push(listener.id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error in event handler for ${eventType}:`, error);
|
||||
console.error(`事件处理器执行错误 ${eventType}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ export class TypeSafeEventSystem {
|
||||
|
||||
// 处理批处理事件
|
||||
this.processBatch(eventType, batch);
|
||||
|
||||
|
||||
// 清空队列
|
||||
this.batchQueue.delete(eventType);
|
||||
}
|
||||
@@ -323,12 +323,12 @@ export class TypeSafeEventSystem {
|
||||
* @returns 监听器ID
|
||||
*/
|
||||
private addListener<T>(
|
||||
eventType: string,
|
||||
handler: EventHandler<T> | AsyncEventHandler<T>,
|
||||
eventType: string,
|
||||
handler: EventHandler<T> | AsyncEventHandler<T>,
|
||||
config: EventListenerConfig
|
||||
): string {
|
||||
let listeners = this.listeners.get(eventType);
|
||||
|
||||
|
||||
if (!listeners) {
|
||||
listeners = [];
|
||||
this.listeners.set(eventType, listeners);
|
||||
@@ -336,7 +336,7 @@ export class TypeSafeEventSystem {
|
||||
|
||||
// 检查监听器数量限制
|
||||
if (listeners.length >= this.maxListeners) {
|
||||
console.warn(`Maximum listeners (${this.maxListeners}) exceeded for event type: ${eventType}`);
|
||||
console.warn(`事件类型 ${eventType} 的监听器数量超过最大限制 (${this.maxListeners})`);
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ export class TypeSafeEventSystem {
|
||||
toRemove.push(listener.id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error in sync event handler for ${eventType}:`, error);
|
||||
console.error(`同步事件处理器执行错误 ${eventType}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,7 +409,7 @@ export class TypeSafeEventSystem {
|
||||
toRemove.push(listener.id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error in async event handler for ${eventType}:`, error);
|
||||
console.error(`异步事件处理器执行错误 ${eventType}:`, error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -472,7 +472,7 @@ export class TypeSafeEventSystem {
|
||||
batch.push(event);
|
||||
|
||||
const config = this.batchConfigs.get(eventType)!;
|
||||
|
||||
|
||||
// 如果达到批处理大小,立即处理
|
||||
if (batch.length >= config.batchSize) {
|
||||
this.flushBatch(eventType);
|
||||
@@ -484,7 +484,7 @@ export class TypeSafeEventSystem {
|
||||
const timer = setTimeout(() => {
|
||||
this.flushBatch(eventType);
|
||||
}, config.delay);
|
||||
|
||||
|
||||
this.batchTimers.set(eventType, timer as any);
|
||||
}
|
||||
}
|
||||
@@ -513,7 +513,7 @@ export class TypeSafeEventSystem {
|
||||
*/
|
||||
private clearBatch(eventType: string): void {
|
||||
this.batchQueue.delete(eventType);
|
||||
|
||||
|
||||
const timer = this.batchTimers.get(eventType);
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
@@ -526,7 +526,7 @@ export class TypeSafeEventSystem {
|
||||
*/
|
||||
private clearAllBatches(): void {
|
||||
this.batchQueue.clear();
|
||||
|
||||
|
||||
for (const timer of this.batchTimers.values()) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
@@ -583,10 +583,10 @@ export const GlobalEventSystem = new TypeSafeEventSystem();
|
||||
export function EventListener(eventType: string, config: EventListenerConfig = {}) {
|
||||
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||
const originalMethod = descriptor.value;
|
||||
|
||||
|
||||
// 在类实例化时自动注册监听器
|
||||
const initMethod = target.constructor.prototype.initEventListeners || function() {};
|
||||
target.constructor.prototype.initEventListeners = function() {
|
||||
const initMethod = target.constructor.prototype.initEventListeners || function () { };
|
||||
target.constructor.prototype.initEventListeners = function () {
|
||||
initMethod.call(this);
|
||||
GlobalEventSystem.on(eventType, originalMethod.bind(this), config);
|
||||
};
|
||||
@@ -601,9 +601,9 @@ export function EventListener(eventType: string, config: EventListenerConfig = {
|
||||
export function AsyncEventListener(eventType: string, config: EventListenerConfig = {}) {
|
||||
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||
const originalMethod = descriptor.value;
|
||||
|
||||
const initMethod = target.constructor.prototype.initEventListeners || function() {};
|
||||
target.constructor.prototype.initEventListeners = function() {
|
||||
|
||||
const initMethod = target.constructor.prototype.initEventListeners || function () { };
|
||||
target.constructor.prototype.initEventListeners = function () {
|
||||
initMethod.call(this);
|
||||
GlobalEventSystem.onAsync(eventType, originalMethod.bind(this), config);
|
||||
};
|
||||
|
||||
@@ -857,7 +857,7 @@ export class Entity {
|
||||
addedComponents.push(this.addComponent(component));
|
||||
} catch (error) {
|
||||
// 如果某个组件添加失败,继续添加其他组件
|
||||
console.warn(`Failed to add component ${component.constructor.name}:`, error);
|
||||
console.warn(`添加组件失败 ${component.constructor.name}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user