gohan/context.go

26 lines
850 B
Go

package gohan
// Context represents the current iteration of a System's matching entities. It
// provides methods for retrieving components for the currently matched Entity,
// and removing the currently matched Entity.
type Context struct {
Entity Entity
allowed []ComponentID
components []interface{}
systemIndex int
world *World
}
// Component gets a Component of the currently handled Entity.
func (ctx *Context) Component(componentID ComponentID) interface{} {
return ctx.components[componentID]
}
// RemoveEntity removes the currently handled Entity's components, causing it
// to no longer be handled by any system. Because Gohan reuses removed Entity
// IDs, applications must also remove any other references to the removed Entity.
func (ctx *Context) RemoveEntity() bool {
return ctx.world.RemoveEntity(ctx.Entity)
}