Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AttachComponent ¶ added in v0.10.0
AttachComponent is a helper generic function that allows one to attach a component to an Entity without dealing with type identifiers.
func FetchComponent ¶ added in v0.10.0
FetchComponent is a helper generic function that allows one to check whether a given Entity has a particular component and if it does, the component will be injected into the specified pointer target.
Types ¶
type Component ¶ added in v0.10.0
type Component interface {
TypeID() ComponentTypeID
}
Component represents an ECS component that can be attached to an Entity.
type ComponentTypeID ¶
type ComponentTypeID uint8
ComponentTypeID is an identifier for a component type. Numbers should be in the range [0..63]. That is, the ECS framework supports at most 64 component types at the moment.
func NewComponentTypeID ¶ added in v0.10.0
func NewComponentTypeID() ComponentTypeID
NewComponentTypeID creates a new unique ComponentTypeID.
type Engine ¶
type Engine struct{}
Engine is the entrypoint to working with an Entity-Component System framework.
func (*Engine) CreateScene ¶
CreateScene creates a new Scene instance. Entities within a scene are isolated from entities in other scenes.
type Entity ¶
type Entity struct {
// contains filtered or unexported fields
}
Entity represents a game entity. It can be a number of things depending on the components that are attached to it.
func (*Entity) Component ¶
func (e *Entity) Component(typeID ComponentTypeID) interface{}
Component returns the component with the specified type that is attached to this entity or nil if there is none.
func (*Entity) DeleteComponent ¶
func (e *Entity) DeleteComponent(typeID ComponentTypeID)
DeleteComponent removes the component with the specified type from this entity.
func (*Entity) HasComponent ¶ added in v0.10.0
func (e *Entity) HasComponent(typeID ComponentTypeID) bool
HasComponent returns whether this Entity has a component of the specified type attached.
func (*Entity) SetComponent ¶
func (e *Entity) SetComponent(typeID ComponentTypeID, value interface{})
SetComponent attaches a component of the specified type to this entity.
type Query ¶
type Query uint64
Query represents a search expression. Currently, only a conjunction of component types is possible.
func Having ¶
func Having(typeID ComponentTypeID) Query
Having creates a new Query that matches entities with the specified component type.
func (Query) And ¶
func (q Query) And(typeID ComponentTypeID) Query
And adds an additional component type as a requirement for an entity to match this query.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result represents the outcome of a search operation. Make sure to call Close on a Result once you are done with it.
func (*Result) Close ¶
func (r *Result) Close()
Close releases the resources allocated for this result.
func (*Result) FetchNext ¶ added in v0.10.0
FetchNext is a helper method that combines HasNext and Next into one single method. It returns whether there is a next Entity and if there is one it will be injected into the specified pointer target.
type Scene ¶
type Scene struct {
// contains filtered or unexported fields
}
Scene represents a collection of ECS entities.
func (*Scene) CreateEntity ¶
CreateEntity creates a new ECS entity in this scene.