Documentation
¶
Overview ¶
Package kind is how a game says what its entities are. A Spec lists the components a kind carries, each made in package comp (the same for all, comp.Const, or read from the entity's own row, comp.Load); Define registers it with a world, and the kind's Entry puts one entity on the roster.
Define, Named and Of ¶
Define registers a Spec under a name with a Registry, a world's; Named is the kind as Of, typed by its row: Entry builds one Entry for world.Write.Seed with the row checked by the compiler, ID is the ID every entity of the kind carries, SpriteID the atlas slot its entities are drawn from. A world.Position and a world.Velocity must each appear once in a Spec, or Define panics by name; so does a Load over a row type other than the kind's.
Roster ¶
A Template is a sort of kind a plugin brings in by name (NewTemplate: what the world spawns, what moves, a board's cell), under a parent whose asks come with its own; the package knows none. A Roster is what the plugins of a world ask of the kinds of each template: what they require (Require: the game must supply a component of that type) and what they bring themselves (Roster.Default, which the game may override or leave out with comp.Without). It is written once, as it is first read, by every plugin's KindTemplates in the order made, and refuses a write anywhere else; Roster.Spec builds a kind's Spec of a template and panics naming every requirement left unmet.
Registry ¶
Registry is where kinds are kept, behind an interface because kind never imports world. One Registry holds at most MaxKinds kinds.
Index ¶
Constants ¶
const MaxKinds = 1 << 8
MaxKinds is how many kinds one Registry can hold, bounded by ID.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry is one entity to spawn: its kind and its row — built by Of.Entry or EntryOf.
func EntryOf ¶
EntryOf is one entity of the kind defined as name, described by row, for whoever knows the row's type only as the program runs. The world refuses a row of another type.
func (Entry) InGroup ¶
InGroup is the entry of an entity in group, with any number of others: what ceremony.Group finds it by.
type Of ¶
type Of[P any] struct { // contains filtered or unexported fields }
Of is one defined kind, whose entities are each described by a row of type P.
func Named ¶
Named is the kind defined as name, whose rows are P; an unknown name, or a kind of other rows, panics.
type Registry ¶
type Registry interface {
Register(name string, row reflect.Type, spec Spec) (ID, render.SpriteID)
// Lookup is the kind registered as name: its ID, its sprite and the type of its rows.
Lookup(name string) (id ID, sprite render.SpriteID, row reflect.Type, ok bool)
}
Registry is where kinds are kept — a world's, reached through world.Plugin.Kinds.
type Roster ¶
type Roster struct {
// contains filtered or unexported fields
}
Roster is what the plugins of a world ask of the kinds a game defines, by template: written by every plugin's KindTemplates as it is first read, never after.
func NewRoster ¶
NewRoster is a roster fill writes as it is first read, the plugins' asks in the order made.
func (*Roster) Default ¶
Default is a component every entity of a kind of template t carries unless the game gives its own of that type or leaves it out with comp.Without.
type Spec ¶
Spec is the definition of one kind: the components every entity of it carries — see package comp.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a sort of kind a plugin brings in by name — what the world spawns, what moves, a board's cell — the asks of its parent coming with its own.
func NewTemplate ¶
NewTemplate is a template named name under parent, nil for none: a handle, its asks a world's Roster's.