Documentation ¶
Index ¶
- func Visit(f func(entity Entity)) func(index int) bool
- type AntiComponent
- type DataComponent
- type DenseSliceComponent
- type Entity
- type Manager
- func (manager *Manager) DeleteAllEntities()
- func (manager *Manager) DeleteEntities(entities ...Entity)
- func (manager *Manager) DeleteEntity(entity Entity)
- func (manager *Manager) Join(components ...joinable) *bit.Set
- func (manager *Manager) Maintain(minEntities int, maxFillRatio float64)
- func (manager *Manager) NewDenseSliceComponent() *DenseSliceComponent
- func (manager *Manager) NewEntity() Entity
- func (manager *Manager) NewMapComponent() *MapComponent
- func (manager *Manager) NewNullComponent() *NullComponent
- func (manager *Manager) NewSliceComponent() *SliceComponent
- type MapComponent
- type NullComponent
- type SliceComponent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AntiComponent ¶
type AntiComponent struct {
// contains filtered or unexported fields
}
AntiComponent is an inverted component used for filtering entities that don't have a component
type DataComponent ¶
type DataComponent interface { Get(Entity) interface{} Set(Entity, interface{}) Not() *AntiComponent // contains filtered or unexported methods }
DataComponent is a component with data
type DenseSliceComponent ¶
type DenseSliceComponent struct {
// contains filtered or unexported fields
}
DenseSliceComponent uses a 2-way redirection table between entities and components, allowing to leave no gaps in the data slice. Consumes less memory if component is a big struct.
func (*DenseSliceComponent) Get ¶
func (c *DenseSliceComponent) Get(entity Entity) interface{}
Get returns data corresponding to entity
func (*DenseSliceComponent) Not ¶
func (c *DenseSliceComponent) Not() *AntiComponent
Not returns an inverted component used for filtering entities that don't have the component
func (*DenseSliceComponent) Set ¶
func (c *DenseSliceComponent) Set(entity Entity, data interface{})
Set sets data corresponding to entity, or does nothing if the entity does not have the component
type Entity ¶
type Entity int
Entity is an index
func GetFirst ¶
GetFirst returns a reference to the first entity matching a tag or nil if there are none
func (Entity) AddComponent ¶
func (entity Entity) AddComponent(component DataComponent, data interface{}) Entity
AddComponent adds entity for component
func (Entity) HasComponent ¶
func (entity Entity) HasComponent(component DataComponent) bool
HasComponent checks if component has entity
func (Entity) RemoveComponent ¶
func (entity Entity) RemoveComponent(component DataComponent) Entity
RemoveComponent removes entity for component
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages components and entities
func (*Manager) DeleteAllEntities ¶
func (manager *Manager) DeleteAllEntities()
DeleteAllEntities removes all entities for all components and reset current entity index
func (*Manager) DeleteEntities ¶
DeleteEntities removes entities for all associated components
func (*Manager) DeleteEntity ¶
DeleteEntity removes entity for all associated components
func (*Manager) Maintain ¶
Maintain reorders component storage to eliminate gaps and reduce memory usage. It invalidates all previous entities.
func (*Manager) NewDenseSliceComponent ¶
func (manager *Manager) NewDenseSliceComponent() *DenseSliceComponent
NewDenseSliceComponent creates a new DenseSliceComponent
func (*Manager) NewMapComponent ¶
func (manager *Manager) NewMapComponent() *MapComponent
NewMapComponent creates a new MapComponent
func (*Manager) NewNullComponent ¶
func (manager *Manager) NewNullComponent() *NullComponent
NewNullComponent creates a new NullComponent
func (*Manager) NewSliceComponent ¶
func (manager *Manager) NewSliceComponent() *SliceComponent
NewSliceComponent creates a new SliceComponent
type MapComponent ¶
type MapComponent struct {
// contains filtered or unexported fields
}
MapComponent uses a map for storing data. Useful for rarely used components.
func (*MapComponent) Get ¶
func (c *MapComponent) Get(entity Entity) interface{}
Get returns data corresponding to entity
func (*MapComponent) Not ¶
func (c *MapComponent) Not() *AntiComponent
Not returns an inverted component used for filtering entities that don't have the component
func (*MapComponent) Set ¶
func (c *MapComponent) Set(entity Entity, data interface{})
Set sets data corresponding to entity, or does nothing if the entity does not have the component
type NullComponent ¶
type NullComponent struct {
// contains filtered or unexported fields
}
NullComponent contains no data and works as a simple flag.
func (*NullComponent) Get ¶
func (c *NullComponent) Get(entity Entity) interface{}
Get returns data corresponding to entity
func (*NullComponent) Not ¶
func (c *NullComponent) Not() *AntiComponent
Not returns an inverted component used for filtering entities that don't have the component
func (*NullComponent) Set ¶
func (c *NullComponent) Set(entity Entity, data interface{})
Set sets data corresponding to entity, or does nothing if the entity does not have the component
type SliceComponent ¶
type SliceComponent struct {
// contains filtered or unexported fields
}
SliceComponent uses a slice for storing data. Useful for pointer components, for small struct components or for components mostly present in entities.
func (*SliceComponent) Get ¶
func (c *SliceComponent) Get(entity Entity) interface{}
Get returns data corresponding to entity
func (*SliceComponent) Not ¶
func (c *SliceComponent) Not() *AntiComponent
Not returns an inverted component used for filtering entities that don't have the component
func (*SliceComponent) Set ¶
func (c *SliceComponent) Set(entity Entity, data interface{})
Set sets data corresponding to entity, or does nothing if the entity does not have the component