Documentation
¶
Index ¶
- Variables
- func Add[T any](e *Entry, ctype component.IComponentType, component *T)
- func Get[T any](e *Entry, ctype component.IComponentType) *T
- func RegisterInitializer(initializer initializer)
- func Remove[T any](e *Entry, ctype component.IComponentType)
- func Set[T any](e *Entry, ctype component.IComponentType, component *T)
- func SetValue[T any](e *Entry, ctype component.IComponentType, value T)
- func Valid(e *Entry) bool
- type ComponentType
- func (c *ComponentType[T]) Each(w World, callback func(*Entry))
- func (c *ComponentType[T]) EachEntity(w World, callback func(*Entry))
- func (c *ComponentType[T]) First(w World) (*Entry, bool)
- func (c *ComponentType[T]) FirstEntity(w World) (*Entry, bool)
- func (c *ComponentType[T]) Get(entry *Entry) *T
- func (c *ComponentType[T]) Id() component.ComponentTypeId
- func (c *ComponentType[T]) MustFirst(w World) *Entry
- func (c *ComponentType[T]) MustFirstEntity(w World) *Entry
- func (c *ComponentType[T]) Name() string
- func (c *ComponentType[T]) New() unsafe.Pointer
- func (c *ComponentType[T]) Set(entry *Entry, compoennt *T)
- func (c *ComponentType[T]) SetName(name string) *ComponentType[T]
- func (c *ComponentType[T]) SetValue(entry *Entry, value T)
- func (c *ComponentType[T]) String() string
- type Entity
- type Entry
- func (e *Entry) AddComponent(ctype component.IComponentType, components ...unsafe.Pointer)
- func (e *Entry) Archetype() *storage.Archetype
- func (e *Entry) Component(ctype component.IComponentType) unsafe.Pointer
- func (e *Entry) Entity() Entity
- func (e *Entry) HasComponent(componentType component.IComponentType) bool
- func (e *Entry) Id() entity.EntityId
- func (e *Entry) Remove()
- func (e *Entry) RemoveComponent(ctype component.IComponentType)
- func (e *Entry) SetComponent(ctype component.IComponentType, component unsafe.Pointer)
- func (e *Entry) String() string
- func (e *Entry) Valid() bool
- type IComponentType
- type Query
- 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.IComponentType, component *T)
Add adds the component to the entry.
func Get ¶ added in v1.1.1
func Get[T any](e *Entry, ctype component.IComponentType) *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[T any](e *Entry, ctype component.IComponentType)
Remove removes the component from the entry.
func Set ¶ added in v1.1.1
func Set[T any](e *Entry, ctype component.IComponentType, component *T)
Set sets the comopnent of the entry.
Types ¶
type ComponentType ¶
type ComponentType[T any] struct { // contains filtered or unexported fields }
CompnentType represents a type of component. It is used to identify a component when getting or setting components of an entity.
func NewComponentType ¶
func NewComponentType[T any](opts ...interface{}) *ComponentType[T]
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[struct{}]
NewTag is an utility to create a tag component. Which is just an component that contains no data.
func (*ComponentType[T]) Each ¶ added in v1.3.2
func (c *ComponentType[T]) Each(w World, callback func(*Entry))
Each iterates over the entities that have the component.
func (*ComponentType[T]) EachEntity ¶ added in v1.3.1
func (c *ComponentType[T]) EachEntity(w World, callback func(*Entry))
deprecated: use Each instead
func (*ComponentType[T]) First ¶ added in v1.3.2
func (c *ComponentType[T]) First(w World) (*Entry, bool)
First returns the first entity that has the component.
func (*ComponentType[T]) FirstEntity ¶ added in v1.3.1
func (c *ComponentType[T]) FirstEntity(w World) (*Entry, bool)
deprecated: use First instead
func (*ComponentType[T]) Get ¶ added in v1.3.0
func (c *ComponentType[T]) Get(entry *Entry) *T
Get returns component data from the entry.
func (*ComponentType[T]) Id ¶ added in v1.3.0
func (c *ComponentType[T]) Id() component.ComponentTypeId
Id returns the component type id.
func (*ComponentType[T]) MustFirst ¶ added in v1.3.2
func (c *ComponentType[T]) MustFirst(w World) *Entry
MustFirst returns the first entity that has the component or panics.
func (*ComponentType[T]) MustFirstEntity ¶ added in v1.3.2
func (c *ComponentType[T]) MustFirstEntity(w World) *Entry
deprecated: use MustFirst instead
func (*ComponentType[T]) Name ¶ added in v1.3.0
func (c *ComponentType[T]) Name() string
Name returns the component type name.
func (*ComponentType[T]) New ¶ added in v1.3.0
func (c *ComponentType[T]) New() unsafe.Pointer
func (*ComponentType[T]) Set ¶ added in v1.3.0
func (c *ComponentType[T]) Set(entry *Entry, compoennt *T)
Set sets component data to the entry.
func (*ComponentType[T]) SetName ¶ added in v1.3.0
func (c *ComponentType[T]) SetName(name string) *ComponentType[T]
SetName sets the component type name.
func (*ComponentType[T]) SetValue ¶ added in v1.3.0
func (c *ComponentType[T]) SetValue(entry *Entry, value T)
SetValue sets the value of the component.
func (*ComponentType[T]) String ¶ added in v1.3.0
func (c *ComponentType[T]) String() string
String returns the component type name.
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.IComponentType, components ...unsafe.Pointer)
AddComponent adds the component to the entity.
func (*Entry) Component ¶
func (e *Entry) Component(ctype component.IComponentType) unsafe.Pointer
Component returns the component.
func (*Entry) HasComponent ¶ added in v1.1.0
func (e *Entry) HasComponent(componentType component.IComponentType) 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.IComponentType)
RemoveComponent removes the component from the entity.
func (*Entry) SetComponent ¶
func (e *Entry) SetComponent(ctype component.IComponentType, component unsafe.Pointer)
SetComponent sets the component.
type IComponentType ¶ added in v1.3.0
type IComponentType = component.IComponentType
IComponentType is an interface for component types.
type Query ¶ added in v1.3.1
type Query struct {
// contains filtered or unexported fields
}
Query represents a query for entities. It is used to filter entities based on their components. It receives arbitrary filters that are used to filter entities. It contains a cache that is used to avoid re-evaluating the query. So it is not recommended to create a new query every time you want to filter entities with the same query.
func NewQuery ¶ added in v1.3.1
func NewQuery(filter filter.LayoutFilter) *Query
NewQuery creates a new query. It receives arbitrary filters that are used to filter entities.
func (*Query) EachEntity ¶ added in v1.3.1
deprecated: use Each instead
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.IComponentType) Entity
// CreateMany creates a new entity with the specified components.
CreateMany(n int, components ...component.IComponentType) []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
// ArcheTypes returns the archetypes in the world.
Archetypes() []*storage.Archetype
}
World is a collection of entities and components.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
bunnymark
command
|
|
|
bunnymark_ecs
command
|
|
|
platformer
command
|
|
|
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
|
|


