Documentation
¶
Index ¶
- Variables
- func Add[T any](e *Entry, ctype *component.ComponentType, component *T)
- func Get[T any](e *Entry, ctype *component.ComponentType) *T
- func RegisterInitializer(initializer initializer)
- func Remove(e *Entry, ctype *component.ComponentType)
- func Set[T any](e *Entry, ctype *component.ComponentType, component *T)
- func SetValue[T any](e *Entry, ctype *component.ComponentType, value T)
- func Valid(e *Entry) bool
- type ComponentType
- type Entity
- type Entry
- func (e *Entry) AddComponent(ctype *component.ComponentType, components ...unsafe.Pointer)
- func (e *Entry) Archetype() *storage.Archetype
- func (e *Entry) Component(ctype *component.ComponentType) unsafe.Pointer
- func (e *Entry) Entity() Entity
- func (e *Entry) HasComponent(componentType *component.ComponentType) bool
- func (e *Entry) Id() entity.EntityId
- func (e *Entry) Remove()
- func (e *Entry) RemoveComponent(ctype *component.ComponentType)
- func (e *Entry) SetComponent(ctype *component.ComponentType, component unsafe.Pointer)
- func (e *Entry) String() string
- func (e *Entry) Valid() bool
- type StorageAccessor
- type World
- type WorldId
Constants ¶
This section is empty.
Variables ¶
var Null = entity.Null
Null represents a invalid entity which is zero.
Functions ¶
func Add ¶ added in v1.1.1
func Add[T any](e *Entry, ctype *component.ComponentType, component *T)
Add adds the component to the entry.
func Get ¶ added in v1.1.1
func Get[T any](e *Entry, ctype *component.ComponentType) *T
Get returns the component from the entry
func RegisterInitializer ¶ added in v1.2.21
func RegisterInitializer(initializer initializer)
RegisterInitializer registers an initializer for a world.
func Remove ¶ added in v1.1.1
func Remove(e *Entry, ctype *component.ComponentType)
Remove removes the component from the entry.
func Set ¶ added in v1.1.1
func Set[T any](e *Entry, ctype *component.ComponentType, component *T)
Set sets the comopnent of the entry.
Types ¶
type ComponentType ¶
type ComponentType = component.ComponentType
ComponentType represents a component type. It is used to add components to entities, and to filter entities based on their components. It contains a function that returns a pointer to a new component.
func NewComponentType ¶
func NewComponentType[T any](opts ...interface{}) *ComponentType
NewComponentType creates a new component type. The function is used to create a new component of the type. It receives a function that returns a pointer to a new component. The first argument is a default value of the component.
func NewTag ¶
func NewTag() *ComponentType
NewTag is an utility to create a tag component. Which is just an component that contains no data.
type Entry ¶
type Entry struct {
World *world
// contains filtered or unexported fields
}
Entry is a struct that contains an entity and a location in an archetype.
func (*Entry) AddComponent ¶
func (e *Entry) AddComponent(ctype *component.ComponentType, components ...unsafe.Pointer)
AddComponent adds the component to the entity.
func (*Entry) Component ¶
func (e *Entry) Component(ctype *component.ComponentType) unsafe.Pointer
Component returns the component.
func (*Entry) HasComponent ¶ added in v1.1.0
func (e *Entry) HasComponent(componentType *component.ComponentType) bool
HasComponent returns true if the entity has the given component type.
func (*Entry) Remove ¶ added in v1.2.5
func (e *Entry) Remove()
Remove removes the entity from the world.
func (*Entry) RemoveComponent ¶
func (e *Entry) RemoveComponent(ctype *component.ComponentType)
RemoveComponent removes the component from the entity.
func (*Entry) SetComponent ¶
func (e *Entry) SetComponent(ctype *component.ComponentType, component unsafe.Pointer)
SetComponent sets the component.
type StorageAccessor ¶
type StorageAccessor struct {
// Index is the search index for the world.
Index *storage.Index
// Components is the component storage for the world.
Components *storage.Components
// Archetypes is the archetype storage for the world.
Archetypes []*storage.Archetype
}
StorageAccessor is an accessor for the world's storage.
type World ¶
type World interface {
// Id returns the unique identifier for the world.
Id() WorldId
// Create creates a new entity with the specified components.
Create(components ...*component.ComponentType) Entity
// CreateMany creates a new entity with the specified components.
CreateMany(n int, components ...*component.ComponentType) []Entity
// Entry returns an entry for the specified entity.
Entry(entity Entity) *Entry
// Remove removes the specified entity.
Remove(entity Entity)
// Valid returns true if the specified entity is valid.
Valid(e Entity) bool
// Len returns the number of entities in the world.
Len() int
// StorageAccessor returns an accessor for the world's storage.
// It is used to access components and archetypes by queries.
StorageAccessor() StorageAccessor
}
World is a collection of entities and components.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
bunnymark
command
|
|
|
bunnymark_ecs
command
|
|
|
platformer
module
|
|
|
features
|
|
|
transform
This code is adapted from https://github.com/m110/airplanes (author: m110)
|
This code is adapted from https://github.com/m110/airplanes (author: m110) |
|
internal
|
|

