ecs

package
v0.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachComponent added in v0.10.0

func AttachComponent[T Component](entity *Entity, component T)

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

func FetchComponent[T Component](entity *Entity, target *T) bool

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 NewEngine

func NewEngine() *Engine

NewEngine creates a new ECS engine.

func (*Engine) CreateScene

func (e *Engine) CreateScene() *Scene

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) Delete

func (e *Entity) Delete()

Delete removes this entity from the scene.

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

func (r *Result) FetchNext(target **Entity) bool

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.

func (*Result) HasNext

func (r *Result) HasNext() bool

HasNext returns whether there are any more entities in this result set.

func (*Result) Next

func (r *Result) Next() *Entity

Next returns the next available entity in this result set. Make sure to first use HasNext before calling this method.

type Scene

type Scene struct {
	// contains filtered or unexported fields
}

Scene represents a collection of ECS entities.

func (*Scene) CreateEntity

func (s *Scene) CreateEntity() *Entity

CreateEntity creates a new ECS entity in this scene.

func (*Scene) Delete

func (s *Scene) Delete()

Delete removes this scene and releases any allocated resources.

func (*Scene) Find

func (s *Scene) Find(query Query) *Result

Find performs a search over the entities in this scene.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL