collect method
Collects the summary snapshot: counts, entity summaries (type names only), resources, profiled timings, event channels.
Implementation
InspectorSnapshot collect() {
final stores = <StoreSnapshot>[];
for (final (type, store) in world.stores.entries) {
stores.add(StoreSnapshot(type: '$type', count: store.length));
}
final entities = <EntitySnapshot>[];
final registry = world.entities;
for (var index = 0; index < registry.slotCount; index++) {
if (!registry.isIndexAlive(index)) continue;
final entity = registry.resolve(index);
final componentTypes = <String>[];
for (final (type, store) in world.stores.entries) {
if (store.containsIndex(index)) componentTypes.add('$type');
}
entities.add(
EntitySnapshot(
index: entity.index,
generation: entity.generation,
name: world.tryGet<Name>(entity)?.value,
componentTypes: componentTypes,
),
);
}
final resources = <ResourceSnapshot>[];
for (final (type, value) in world.resources.entries) {
resources.add(
ResourceSnapshot(type: '$type', value: _overriddenToString(value)),
);
}
final systems = <SystemSnapshot>[];
final profiler = world.resources.tryGet<SystemProfiler>();
if (profiler != null) {
for (final timing in profiler.timings) {
systems.add(
SystemSnapshot(
label: timing.debugName,
schedule: timing.schedule.id.toString(),
lastMs: timing.latestMicros / 1000,
averageMs: timing.average.inMicroseconds / 1000,
),
);
}
}
final events = <EventChannelSnapshot>[];
for (final (type, channel) in world.debugEventChannels) {
events.add(
EventChannelSnapshot(
type: '$type',
pending: channel.pendingCount,
readerLagged: channel.readerLagged,
),
);
}
return InspectorSnapshot(
entityCount: registry.aliveCount,
stores: stores,
entities: entities,
resources: resources,
systems: systems,
events: events,
);
}