Documentation
¶
Overview ¶
donburi is an Entity Component System library for Go/Ebitengine inspired by legion.
It aims to be a feature rich and high-performance ECS Library.
Index ¶
- Variables
- func Add[T any](e *Entry, c component.IComponentType, component *T)
- func Get[T any](e *Entry, c component.IComponentType) *T
- func GetComponents(e *Entry) []any
- func GetValue[T any](e *Entry, c component.IComponentType) T
- func RegisterInitializer(initializer initializer)
- func Remove[T any](e *Entry, ctype component.IComponentType)
- func Set[T any](e *Entry, c component.IComponentType, component *T)
- func SetValue[T any](e *Entry, c 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]) GetValue(entry *Entry) T
- func (c *ComponentType[T]) Id() component.ComponentTypeId
- func (c *ComponentType[T]) Iter(w World) iter.Seq[*Entry]
- 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, component *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
- func (c *ComponentType[T]) Typ() reflect.Type
- type Entity
- type Entry
- func (e *Entry) AddComponent(c component.IComponentType, components ...unsafe.Pointer)
- func (e *Entry) Archetype() *storage.Archetype
- func (e *Entry) Component(c component.IComponentType) unsafe.Pointer
- func (e *Entry) Entity() Entity
- func (e *Entry) HasComponent(c component.IComponentType) bool
- func (e *Entry) Id() storage.EntityId
- func (e *Entry) Remove()
- func (e *Entry) RemoveComponent(c component.IComponentType)
- func (e *Entry) SetComponent(c component.IComponentType, component unsafe.Pointer)
- func (e *Entry) String() string
- func (e *Entry) Valid() bool
- type IComponentType
- type IOrderable
- type OrderedEntryIterator
- type OrderedQuery
- type Query
- func (q *Query) Count(w World) int
- func (q *Query) Each(w World, callback func(*Entry))
- func (q *Query) EachEntity(w World, callback func(*Entry))
- func (q *Query) First(w World) (entry *Entry, ok bool)
- func (q *Query) FirstEntity(w World) (entry *Entry, ok bool)
- func (q *Query) Iter(w World) iter.Seq[*Entry]
- type StorageAccessor
- type Tag
- type World
- type WorldId
Constants ¶
This section is empty.
Variables ¶
var Null = storage.Null
Null represents a invalid entity which is zero.
Functions ¶
func Add ¶ added in v1.1.1
func Add[T any](e *Entry, c component.IComponentType, component *T)
Add adds the component to the entry.
func Get ¶ added in v1.1.1
func Get[T any](e *Entry, c component.IComponentType) *T
Get returns the component from the entry
func GetComponents ¶ added in v1.3.14
GetComponents uses reflection to convert the unsafe.Pointers of an entry into its component data instances. Note that this is likely to be slow and should not be used in hot paths or if not necessary.
func GetValue ¶ added in v1.3.14
func GetValue[T any](e *Entry, c component.IComponentType) T
GetValue gets the value of the component.
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, c 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(opts ...any) *ComponentType[Tag]
NewTag is an utility to create a tag component. Which is just an component that contains no data. Specify a string as the first and only parameter if you wish to name the component.
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]) GetValue ¶ added in v1.4.2
func (c *ComponentType[T]) GetValue(entry *Entry) T
GetValue returns value of the component 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]) Iter ¶ added in v1.5.0
func (c *ComponentType[T]) Iter(w World) iter.Seq[*Entry]
Iter returns an iterator for the entities that have the component.
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, component *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.
func (*ComponentType[T]) Typ ¶ added in v1.3.14
func (c *ComponentType[T]) Typ() reflect.Type
Typ returns the reflect.Type of the ComponentType.
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(c component.IComponentType, components ...unsafe.Pointer)
AddComponent adds the component to the entity.
func (*Entry) Component ¶
func (e *Entry) Component(c component.IComponentType) unsafe.Pointer
Component returns the component.
func (*Entry) HasComponent ¶ added in v1.1.0
func (e *Entry) HasComponent(c 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(c component.IComponentType)
RemoveComponent removes the component from the entity.
func (*Entry) SetComponent ¶
func (e *Entry) SetComponent(c 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.
func AllComponentTypes ¶ added in v1.4.4
func AllComponentTypes() []IComponentType
AllComponentTypes returns all IComponentTypes created at that point in time. All types created using `donburi.NewComponentType()` will be in this list. This is useful if you want to use introspection on the ECS, such as when doing (de)serialization. This includes components which are not in any archetypes or on any entity.
type IOrderable ¶ added in v1.4.3
type IOrderable interface {
Order() int
}
type OrderedEntryIterator ¶ added in v1.4.3
type OrderedEntryIterator[T IOrderable] struct { // contains filtered or unexported fields }
OrderedEntryIterator is an iterator for entries from a list of `[]Entity`.
func NewOrderedEntryIterator ¶ added in v1.4.3
func NewOrderedEntryIterator[T IOrderable](current int, w World, entities []Entity, orderedBy *ComponentType[T]) OrderedEntryIterator[T]
OrderedEntryIterator is an iterator for entries based on a list of `[]Entity`.
func (*OrderedEntryIterator[T]) HasNext ¶ added in v1.4.3
func (it *OrderedEntryIterator[T]) HasNext() bool
HasNext returns true if there are more entries to iterate over.
func (*OrderedEntryIterator[T]) Next ¶ added in v1.4.3
func (it *OrderedEntryIterator[T]) Next() *Entry
Next returns the next entry.
type OrderedQuery ¶ added in v1.4.3
type OrderedQuery[T IOrderable] struct { Query // contains filtered or unexported fields }
OrderedQuery is a special extension of Query which has a type parameter used when running ordered queries using `EachOrdered`.
func NewOrderedQuery ¶ added in v1.4.3
func NewOrderedQuery[T IOrderable](filter filter.LayoutFilter) *OrderedQuery[T]
NewOrderedQuery creates a new ordered query. It takes a filter parameter that is used when evaluating the query. Use `OrderedQuery.EachOrdered` to run a Each query in ordered mode.
func (*OrderedQuery[T]) EachOrdered ¶ added in v1.4.3
func (q *OrderedQuery[T]) EachOrdered(w World, orderBy *ComponentType[T], callback func(*Entry))
EachOrdered iterates over all entities within the query filter, and uses the `orderBy` parameter to figure out which property to order using. `T` must implement `IOrderable`
func (*OrderedQuery[T]) IterOrdered ¶ added in v1.5.0
func (q *OrderedQuery[T]) IterOrdered(w World, orderBy *ComponentType[T]) iter.Seq[*Entry]
IterOrdered returns an iterator over all entities within the query filter, ordered by the specified component.
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
func (*Query) FirstEntity ¶ added in v1.3.1
deprecated: use First 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 // OnCreate registers a callback function that gets triggered when an entity is created. OnCreate(callback func(world World, entity Entity)) // OnRemove registers a callback function that gets triggered when an entity is removed. // Note that it is called before the entity is removed from the ECS. OnRemove(callback func(world World, entity Entity)) }
World is a collection of entities and components.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
bunnymark
Module
|
|
bunnymark_ecs
Module
|
|
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
|
|