新增组件/系统装饰器避免混淆

更改Set兼容web/小游戏
This commit is contained in:
YHH
2025-08-14 18:35:03 +08:00
parent 62f250b43c
commit 0b7e623748
19 changed files with 434 additions and 90 deletions

View File

@@ -1,6 +1,7 @@
import { IComponentDebugData } from '../../Types';
import { Core } from '../../Core';
import { ComponentPoolManager } from '../../ECS/Core/ComponentPool';
import { getComponentInstanceTypeName } from '../../ECS/Decorators';
/**
* 组件数据收集器
@@ -36,7 +37,7 @@ export class ComponentDataCollector {
entityList.buffer.forEach((entity: any) => {
if (entity.components) {
entity.components.forEach((component: any) => {
const typeName = component.constructor.name;
const typeName = getComponentInstanceTypeName(component);
const stats = componentStats.get(typeName) || { count: 0, entities: 0 };
stats.count++;
totalInstances++;
@@ -106,7 +107,7 @@ export class ComponentDataCollector {
try {
for (const entity of entityList.buffer) {
if (entity.components) {
const component = entity.components.find((c: any) => c.constructor.name === typeName);
const component = entity.components.find((c: any) => getComponentInstanceTypeName(c) === typeName);
if (component) {
calculatedSize = this.calculateQuickObjectSize(component);
break;
@@ -180,7 +181,7 @@ export class ComponentDataCollector {
// 找到第一个包含此组件的实体,分析组件大小
for (const entity of entityList.buffer) {
if (entity.components) {
const component = entity.components.find((c: any) => c.constructor.name === typeName);
const component = entity.components.find((c: any) => getComponentInstanceTypeName(c) === typeName);
if (component) {
return this.estimateObjectSize(component);
}

View File

@@ -1,4 +1,5 @@
import { Component } from '../../ECS/Component';
import { getComponentInstanceTypeName } from '../../ECS/Decorators';
/**
* 调试数据格式化工具
@@ -56,7 +57,7 @@ export class DebugDataFormatter {
}> {
return components.map((component: Component) => {
const componentDetail = {
typeName: component.constructor.name,
typeName: getComponentInstanceTypeName(component),
properties: {} as Record<string, any>
};

View File

@@ -9,6 +9,7 @@ import { Core } from '../../Core';
import { Component } from '../../ECS/Component';
import { ComponentPoolManager } from '../../ECS/Core/ComponentPool';
import { Pool } from '../../Utils/Pool';
import { getComponentInstanceTypeName, getSystemInstanceTypeName } from '../../ECS/Decorators';
/**
* 调试管理器
@@ -467,7 +468,7 @@ export class DebugManager {
if (!entity || entity.destroyed || !entity.components) continue;
for (const component of entity.components) {
const typeName = component.constructor.name;
const typeName = getComponentInstanceTypeName(component);
componentTypeCounts.set(typeName, (componentTypeCounts.get(typeName) || 0) + 1);
}
}
@@ -486,7 +487,7 @@ export class DebugManager {
if (!entity || entity.destroyed || !entity.components) continue;
for (const component of entity.components) {
if (component.constructor.name === typeName) {
if (getComponentInstanceTypeName(component) === typeName) {
instances.push({
entityId: entity.id,
entityName: entity.name || `Entity_${entity.id}`,
@@ -550,7 +551,7 @@ export class DebugManager {
const systemTypeMemoryCache = new Map<string, number>();
for (const system of entityProcessors.processors) {
const systemTypeName = system.constructor.name;
const systemTypeName = getSystemInstanceTypeName(system);
let systemMemory: number;
if (systemTypeMemoryCache.has(systemTypeName)) {

View File

@@ -3,6 +3,7 @@ import { Core } from '../../Core';
import { Entity } from '../../ECS/Entity';
import { Component } from '../../ECS/Component';
import { ComponentTypeManager } from '../../ECS/Utils/ComponentTypeManager';
import { getComponentInstanceTypeName, getSystemInstanceTypeName } from '../../ECS/Decorators';
/**
* 实体数据收集器
@@ -77,7 +78,7 @@ export class EntityDataCollector {
enabled: entity.enabled !== false,
activeInHierarchy: entity.activeInHierarchy !== false,
componentCount: entity.components.length,
componentTypes: entity.components.map((component: Component) => component.constructor.name),
componentTypes: entity.components.map((component: Component) => getComponentInstanceTypeName(component)),
parentId: entity.parent?.id || null,
childIds: entity.children?.map((child: Entity) => child.id) || [],
depth: entity.getDepth ? entity.getDepth() : 0,
@@ -114,7 +115,7 @@ export class EntityDataCollector {
parentName: entity.parent?.name || null,
components: componentDetails || [],
componentCount: entity.components?.length || 0,
componentTypes: entity.components?.map((comp: any) => comp.constructor.name) || []
componentTypes: entity.components?.map((comp: any) => getComponentInstanceTypeName(comp)) || []
};
} catch (error) {
return {
@@ -216,7 +217,7 @@ export class EntityDataCollector {
if (entityContainer && entityContainer.entities) {
entityContainer.entities.forEach((entity: any) => {
const componentTypes = entity.components?.map((comp: any) => comp.constructor.name) || [];
const componentTypes = entity.components?.map((comp: any) => getComponentInstanceTypeName(comp)) || [];
const signature = componentTypes.length > 0 ? componentTypes.sort().join(', ') : '无组件';
const existing = distribution.get(signature);
@@ -378,7 +379,7 @@ export class EntityDataCollector {
if (entityContainer && entityContainer.entities) {
entityContainer.entities.forEach((entity: any) => {
const componentTypes = entity.components?.map((comp: any) => comp.constructor.name) || [];
const componentTypes = entity.components?.map((comp: any) => getComponentInstanceTypeName(comp)) || [];
const signature = componentTypes.length > 0 ? componentTypes.sort().join(', ') : '无组件';
const existing = distribution.get(signature);
@@ -601,7 +602,7 @@ export class EntityDataCollector {
enabled: entity.enabled !== false,
activeInHierarchy: entity.activeInHierarchy !== false,
componentCount: entity.components.length,
componentTypes: entity.components.map((component: Component) => component.constructor.name),
componentTypes: entity.components.map((component: Component) => getComponentInstanceTypeName(component)),
parentId: entity.parent?.id || null,
children: [] as any[],
depth: entity.getDepth ? entity.getDepth() : 0,
@@ -690,7 +691,7 @@ export class EntityDataCollector {
sceneName: sceneInfo.name,
sceneType: sceneInfo.type,
componentCount: entity.components.length,
componentTypes: entity.components.map((component: Component) => component.constructor.name),
componentTypes: entity.components.map((component: Component) => getComponentInstanceTypeName(component)),
componentMask: entity.componentMask?.toString() || '0',
parentId: entity.parent?.id || null,
childCount: entity.children?.length || 0,
@@ -709,7 +710,7 @@ export class EntityDataCollector {
properties: Record<string, any>;
}> {
return components.map((component: Component) => {
let typeName = component.constructor.name;
let typeName = getComponentInstanceTypeName(component);
if (!typeName || typeName === 'Object' || typeName === 'Function') {
try {
@@ -739,11 +740,11 @@ export class EntityDataCollector {
// 如果没有找到任何属性,添加一些调试信息
if (Object.keys(properties).length === 0) {
properties._info = '该组件没有公开属性';
properties._componentId = component.constructor.name;
properties._componentId = getComponentInstanceTypeName(component);
}
} catch (error) {
properties._error = '属性提取失败';
properties._componentId = component.constructor.name;
properties._componentId = getComponentInstanceTypeName(component);
}
return {

View File

@@ -1,5 +1,6 @@
import { ISystemDebugData } from '../../Types';
import { Core } from '../../Core';
import { getSystemInstanceTypeName } from '../../ECS/Decorators';
/**
* 系统数据收集器
@@ -43,13 +44,13 @@ export class SystemDataCollector {
return {
totalSystems: systems.length,
systemsInfo: systems.map((system: any) => {
const systemName = system.systemName || system.constructor.name;
const systemName = system.systemName || getSystemInstanceTypeName(system);
const stats = systemStats.get(systemName);
const data = systemData.get(systemName);
return {
name: systemName,
type: system.constructor.name,
type: getSystemInstanceTypeName(system),
entityCount: system.entities?.length || 0,
executionTime: stats?.averageTime || data?.executionTime || 0,
minExecutionTime: stats?.minTime === Number.MAX_VALUE ? 0 : (stats?.minTime || 0),