// Package stats provides the structs returned by ecs.World.Stats().
package stats import ( ) // World statistics. type World struct { // Component types, indexed by component ID. // Note that this field is excluded from JSON marshalling and un-marshalling. // Use ComponentTypeNames instead. ComponentTypes []reflect.Type `json:"-"` // Component type names, indexed by component ID. ComponentTypeNames []string // Archetype statistics. Archetypes []Archetype // Entity statistics. Entities Entities // Memory reserved for entities and components, in bytes. Memory int // Memory actually used for alive entities and their components components, in bytes. MemoryUsed int // Number of cached filters. CachedFilters int // Number of registered observers. Observers int // Locked state of the world. Locked bool } // Entities statistics. type Entities struct { // Currently used/alive entities. Used int // Recycled/available entities. Recycled int // Current total number of entities in the pool (used + recycled). Total int // Current capacity of entity pool and entity list. Capacity int } // Archetype statistics. type Archetype struct { // Component IDs. ComponentIDs []uint8 // Component types for ComponentIDs. // Note that this field is excluded from JSON marshalling and un-marshalling. // Use ComponentTypeNames instead. ComponentTypes []reflect.Type `json:"-"` // Component type names for ComponentIDs. ComponentTypeNames []string // Table statistics. Tables []Table // Number of entities in the tables of this archetype. Size int // Sum of capacity of the tables in this archetype. Capacity int // Number of relation components in the archetype. NumRelations int // Memory reserved for entities and components, in bytes. Memory int // Memory actually used for alive entities and their components components, in bytes. MemoryUsed int // Memory for components per entity, in bytes. MemoryPerEntity int // Number of free tables. FreeTables int } // Table statistics. type Table struct { // Number of entities in the table. Size int // Capacity of the table. Capacity int // Memory reserved for entities and components, in bytes. Memory int // Memory actually used for alive entities and their components components, in bytes. MemoryUsed int } func ( *World) () string { := strings.Builder{} fmt.Fprintf( &, "World -- Components: %d, Archetypes: %d, Filters: %d, Observers: %d, Memory: %.1f/%.1f kB, Locked: %t\n", len(.ComponentTypeNames), len(.Archetypes), .CachedFilters, .Observers, float64(.MemoryUsed)/1024.0, float64(.Memory)/1024.0, .Locked, ) fmt.Fprintf(&, " Components: %s\n", strings.Join(.ComponentTypeNames, ", ")) fmt.Fprint(&, .Entities.String()) for := range .Archetypes { fmt.Fprint(&, .Archetypes[].String()) } return .String() } func ( *Entities) () string { return fmt.Sprintf("Entities -- Used: %d, Recycled: %d, Total: %d, Capacity: %d\n", .Used, .Recycled, .Total, .Capacity) } func ( *Archetype) () string { return fmt.Sprintf( "Archetype -- Tables: %4d, Comps: %2d, Entities: %6d, Cap: %6d, Mem: %7.1f kB, Per entity: %4d B\n Components: %s\n", len(.Tables), len(.ComponentIDs), .Size, .Capacity, float64(.Memory)/1024.0, .MemoryPerEntity, strings.Join(.ComponentTypeNames, ", "), ) } func ( *Table) () string { return fmt.Sprintf("Table -- Entities: %6d, Cap: %6d, Mem: %7.1f kB\n", .Size, .Capacity, float64(.Memory)/1024.0) }