Documentation
¶
Index ¶
- type Archetype
- func (archetype *Archetype) Entities() []entity.Entity
- func (archetype *Archetype) Layout() *EntityLayout
- func (archetype *Archetype) MatchesLayout(components []*component.ComponentType) bool
- func (archetype *Archetype) PushEntity(entity entity.Entity)
- func (archetype *Archetype) SwapRemove(entity_index int) entity.Entity
- type ArchetypeIndex
- type ComponentIndex
- type Components
- type EntityLayout
- type EntityListIterator
- type EntityLocation
- type LocationMap
- func (lm *LocationMap) Archetype(id entity.EntityId) ArchetypeIndex
- func (lm *LocationMap) Component(id entity.EntityId) ComponentIndex
- func (lm *LocationMap) Contains(id entity.EntityId) bool
- func (lm *LocationMap) Insert(id entity.EntityId, archetype ArchetypeIndex, component ComponentIndex)
- func (lm *LocationMap) Location(id entity.EntityId) *EntityLocation
- func (lm *LocationMap) Remove(id entity.EntityId)
- func (lm *LocationMap) Set(id entity.EntityId, loc *EntityLocation)
- type SearchIndex
- type SimpleStorage
- func (cs *SimpleStorage) Component(archetypeIndex ArchetypeIndex, componentIndex ComponentIndex) unsafe.Pointer
- func (cs *SimpleStorage) MoveComponent(source ArchetypeIndex, index ComponentIndex, dst ArchetypeIndex)
- func (cs *SimpleStorage) PushComponent(component *component.ComponentType, archetypeIndex ArchetypeIndex)
- func (cs *SimpleStorage) SetComponent(archetypeIndex ArchetypeIndex, componentIndex ComponentIndex, ...)
- func (cs *SimpleStorage) SwapRemove(archetypeIndex ArchetypeIndex, componentIndex ComponentIndex) unsafe.Pointer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Archetype ¶
type Archetype struct {
// contains filtered or unexported fields
}
Archetype is a collection of entities for a specific layout of components. This structure allows to quickly find entities based on their components.
func NewArchetype ¶
func NewArchetype(index ArchetypeIndex, layout *EntityLayout) *Archetype
NewArchetype creates a new archetype.
func (*Archetype) Layout ¶
func (archetype *Archetype) Layout() *EntityLayout
Layout is a collection of archetypes for a specific layout of components.
func (*Archetype) MatchesLayout ¶
func (archetype *Archetype) MatchesLayout(components []*component.ComponentType) bool
Matches returns true if the given components match the archetype.
func (*Archetype) PushEntity ¶
PushEntity adds an entity to the archetype.
type ArchetypeIndex ¶
type ArchetypeIndex int
type ComponentIndex ¶
type ComponentIndex int
ComponentIndex represents the index of component in a archetype.
type Components ¶
type Components struct {
// contains filtered or unexported fields
}
Components is a structure that stores data of components.
func NewComponents ¶
func NewComponents() *Components
NewComponents creates a new empty structure that stores data of components.
func (*Components) PushComponents ¶
func (cs *Components) PushComponents(components []*component.ComponentType, archetypeIndex ArchetypeIndex) ComponentIndex
PUshComponent stores the new data of the component in the archetype.
func (*Components) Storage ¶
func (cs *Components) Storage(c *component.ComponentType) *SimpleStorage
Storage returns the pointer to data of the component in the archetype.
type EntityLayout ¶
type EntityLayout struct {
// contains filtered or unexported fields
}
EntityLayout represents a layout of components.
func NewEntityLayout ¶
func NewEntityLayout(components []*component.ComponentType) *EntityLayout
NewEntityLayout creates a new entity layout.
func (*EntityLayout) Components ¶
func (el *EntityLayout) Components() []*component.ComponentType
Components returns the components of the layout.
func (*EntityLayout) HasComponent ¶
func (el *EntityLayout) HasComponent(componentType *component.ComponentType) bool
HasComponent returns true if the layout has the given component type.
func (*EntityLayout) RegisterComponent ¶
func (el *EntityLayout) RegisterComponent(typeId *component.ComponentType)
RegisterComponent registers a component type to the layout.
type EntityListIterator ¶
type EntityListIterator struct {
// contains filtered or unexported fields
}
EntityListIterator is an iterator for entity lists in archetypes.
func NewEntityListIterator ¶
func NewEntityListIterator(current int, archetypes []*Archetype, indices []ArchetypeIndex) EntityListIterator
EntityIterator is an iterator for entities.
func (*EntityListIterator) HasNext ¶
func (it *EntityListIterator) HasNext() bool
HasNext returns true if there are more entity list to iterate over.
func (*EntityListIterator) Next ¶
func (it *EntityListIterator) Next() []entity.Entity
Next returns the next entity list.
type EntityLocation ¶
type EntityLocation struct { Archetype ArchetypeIndex Component ComponentIndex Valid bool }
EntityLocation is a location of an entity in the storage.
func NewEntityLocation ¶
func NewEntityLocation(archetype ArchetypeIndex, component ComponentIndex) *EntityLocation
NewEntityLocation creates a new EntityLocation.
type LocationMap ¶
type LocationMap struct { LocationMap []*EntityLocation Len int }
LocationMap is a storage of entity locations.
func (*LocationMap) Archetype ¶
func (lm *LocationMap) Archetype(id entity.EntityId) ArchetypeIndex
Archetype returns the archetype of the given entity id.
func (*LocationMap) Component ¶
func (lm *LocationMap) Component(id entity.EntityId) ComponentIndex
Component returns the component of the given entity id.
func (*LocationMap) Contains ¶
func (lm *LocationMap) Contains(id entity.EntityId) bool
Contains returns true if the storage contains the given entity id.
func (*LocationMap) Insert ¶
func (lm *LocationMap) Insert(id entity.EntityId, archetype ArchetypeIndex, component ComponentIndex)
Insert inserts the given entity id and archetype index to the storage.
func (*LocationMap) Location ¶
func (lm *LocationMap) Location(id entity.EntityId) *EntityLocation
Location returns the location of the given entity id.
func (*LocationMap) Remove ¶
func (lm *LocationMap) Remove(id entity.EntityId)
Remove removes the given entity id from the storage.
func (*LocationMap) Set ¶
func (lm *LocationMap) Set(id entity.EntityId, loc *EntityLocation)
Set sets the given entity id and archetype index to the storage.
type SearchIndex ¶
type SearchIndex struct {
// contains filtered or unexported fields
}
SearchIndex is a structure that indexes archetypes by their component types.
func (*SearchIndex) Push ¶
func (si *SearchIndex) Push(archetypeLayout *EntityLayout)
Push adds an archetype to the search index.
func (*SearchIndex) Search ¶
func (si *SearchIndex) Search(filter filter.LayoutFilter) *archetypeIterator
Search searches for archetypes that match the given filter.
func (*SearchIndex) SearchFrom ¶
func (si *SearchIndex) SearchFrom(f filter.LayoutFilter, start int) *archetypeIterator
SearchFrom searches for archetypes that match the given filter from the given index.
type SimpleStorage ¶
type SimpleStorage struct {
// contains filtered or unexported fields
}
SimpleStorage is a structure that stores the pointer to data of each component. It stores the pointers in the two dimensional slice. First dimension is the archetype index. Second dimension is the component index. The component index is used to access the component data in the archetype.
func NewSimpleStorage ¶
func NewSimpleStorage() *SimpleStorage
NewSimpleStorage creates a new empty structure that stores the pointer to data of each component.
func (*SimpleStorage) Component ¶
func (cs *SimpleStorage) Component(archetypeIndex ArchetypeIndex, componentIndex ComponentIndex) unsafe.Pointer
Component returns the pointer to data of the component in the archetype.
func (*SimpleStorage) MoveComponent ¶
func (cs *SimpleStorage) MoveComponent(source ArchetypeIndex, index ComponentIndex, dst ArchetypeIndex)
MoveComponent moves the pointer to data of the component in the archetype.
func (*SimpleStorage) PushComponent ¶
func (cs *SimpleStorage) PushComponent(component *component.ComponentType, archetypeIndex ArchetypeIndex)
PushComponent stores the new data of the component in the archetype.
func (*SimpleStorage) SetComponent ¶
func (cs *SimpleStorage) SetComponent(archetypeIndex ArchetypeIndex, componentIndex ComponentIndex, component unsafe.Pointer)
SetComponent sets the pointer to data of the component in the archetype.
func (*SimpleStorage) SwapRemove ¶
func (cs *SimpleStorage) SwapRemove(archetypeIndex ArchetypeIndex, componentIndex ComponentIndex) unsafe.Pointer
SwapRemove removes the pointer to data of the component in the archetype.