Documentation ¶
Overview ¶
Package ecs provides interfaces for the Entity Component System (ECS) paradigm used by engo.io/engo. It is predominately used by games, however will find use in other applications.
The ECS paradigm aims to decouple distinct domains (e.g. rendering, input handling, AI) from one another, through a composition of independent components. The core concepts of ECS are described below.
Entities ¶
An entity is simply a set of components with a unique ID attached to it, nothing more. In particular, an entity has no logic attached to it and stores no data explicitly (except for the ID).
Each entity corresponds to a specific entity within the game, such as a character, an item, or a spell.
Components ¶
A component stores the raw data related to a specific aspect of an entity, nothing more. In particular, a component has no logic attached to it.
Different aspects may include the position, animation graphics, or input actions of an entity.
Systems ¶
A system implements logic for processing entities possessing components of the same aspects as the system.
For instance, an animation system may render entities possessing animation components.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BasicEntity ¶
type BasicEntity struct {
// contains filtered or unexported fields
}
A BasicEntity is simply a set of components with a unique ID attached to it, nothing more. It belongs to any amount of Systems, and has a number of Components
func NewBasic ¶
func NewBasic() BasicEntity
NewBasic creates a new Entity with a new unique identifier. It is safe for concurrent use.
func NewBasics ¶
func NewBasics(amount int) []BasicEntity
NewBasics creates an amount of new entities with a new unique identifiers. It is safe for concurrent use, and performs better than NewBasic for large numbers of entities.
func (*BasicEntity) GetBasicEntity ¶
func (e *BasicEntity) GetBasicEntity() *BasicEntity
GetBasicEntity returns a Pointer to the BasicEntity itself By having this method, All Entities containing a BasicEntity now automatically have a GetBasicEntity Method This allows system.Add functions to recieve a single interface EG: s.AddByInterface(a interface{GetBasicEntity()*BasicEntity, GetSpaceComponent()*SpaceComponent){ s.Add(a.GetBasicEntity(),a.GetSpaceComponent()) }
func (BasicEntity) ID ¶
func (e BasicEntity) ID() uint64
ID returns the unique identifier of the entity.
type Identifier ¶
type Identifier interface {
ID() uint64
}
Identifier is an interface for anything that implements the basic ID() uint64, as the BasicEntity does. It is useful as more specific interface for an entity registry than just the interface{} interface
type IdentifierSlice ¶
type IdentifierSlice []Identifier
IdentifierSlice implements the sort.Interface, so you can use the store entites in slices, and use the P=n*log n lookup for them
func (IdentifierSlice) Len ¶
func (is IdentifierSlice) Len() int
Len returns the length of the underlying slice part of the sort.Interface
func (IdentifierSlice) Less ¶
func (is IdentifierSlice) Less(i, j int) bool
Less will return true if the ID of element at i is less than j; part of the sort.Interface
func (IdentifierSlice) Swap ¶
func (is IdentifierSlice) Swap(i, j int)
Swap the elements at positions i and j part of the sort.Interface
type Initializer ¶
type Initializer interface { // New initializes the given System, and may be used to initialize some // values beforehand, like storing a reference to the World. New(*World) }
Initializer provides initialization of systems.
type Prioritizer ¶
type Prioritizer interface { // Priority indicates the order in which Systems should be executed per // iteration, higher meaning sooner. The default priority is 0. Priority() int }
Prioritizer specifies the priority of systems.
type System ¶
type System interface { // Update updates the system. It is invoked by the engine once every frame, // with dt being the duration since the previous update. Update(dt float32) // Remove removes the given entity from the system. Remove(e BasicEntity) }
A System implements logic for processing entities possessing components of the same aspects as the system. A System should iterate over its Entities on `Update`, in any way suitable for the current implementation.
By convention, systems provide an Add method for adding entities and their associated components to the system; e.g.
Add(basic *ecs.BasicEntity, collision *CollisionComponent, space *SpaceComponent)
type World ¶
type World struct {
// contains filtered or unexported fields
}
World contains a bunch of Entities, and a bunch of Systems. It is the recommended way to run ecs.
func (*World) RemoveEntity ¶
func (w *World) RemoveEntity(e BasicEntity)
RemoveEntity removes the entity across all systems.