39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package gohan
|
|
|
|
import "log"
|
|
|
|
// 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
|
|
|
|
s int // System index.
|
|
c []ComponentID
|
|
w *World
|
|
}
|
|
|
|
// Component gets a Component of the currently handled Entity.
|
|
func (ctx *Context) Component(componentID ComponentID) interface{} {
|
|
if debug != 0 {
|
|
var found bool
|
|
for _, id := range ctx.c {
|
|
if id == componentID {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
log.Panicf("illegal component access: component %d is not queried by %s", componentID, ctx.w.systemName(ctx.s))
|
|
}
|
|
}
|
|
return ctx.w.Component(ctx.Entity, 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.w.RemoveEntity(ctx.Entity)
|
|
}
|