host

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package host is the pass's side of the rules: a pass that perceives a moment of its entities keeps a host of that moment, binds it into its query and runs it over every chunk, and the host runs the rules given to it. A rule of a moment no host in use catches is an error, never a silent no-op.

Moments

A moment is what a pass perceives of an entity, handed to rules and forgotten: a value that is About (Who, the entity it is of), Met for one entity with others, Placed for one standing on places that are entities of their own. Aimed is a command told the subject of the moment it is given on.

Hosts

Rules runs the rules of a moment over the entities of a pass; PairRules matches pairs by the tag families the rules name (Side, Marks); StepRules runs rules of a moment of the whole once a step. Each is a Host: Add takes a rule or refuses it with ErrUnhosted, and after Bind with ErrHostBuilt. Tick is what a host tells its rules of the pass: the commands' carrier, the effects, the time, the seed, the places round and the roles played.

Index

Constants

This section is empty.

Variables

View Source
var ErrHostBuilt = errors.New("plugin: rule handed over after its system was built")

ErrHostBuilt is what a Host reports for a rule handed over once the system running it is built.

View Source
var ErrUnhosted = errors.New("plugin: rule cannot be hosted here")

ErrUnhosted is what a Host reports for a rule of a moment it does not catch.

Functions

func Own

func Own[T, P any](r *Rules[P], col *goke.OptComp[T])

Own has the system read the component T itself through col, shared with the rules over T. Call it before Bind.

Types

type About

type About interface{ Who() uid.UID64 }

About is a moment of one entity, whom a rule's steps act for.

type Aimed

type Aimed interface{ Aim(who uid.UID64) }

Aimed is a command told the Subject of the moment or the fact it is given on as it is issued.

type Columns

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

Columns are the optional columns of a host's query, by component, shared by the rules over one component and the system's own reading of it (Own).

func (*Columns) Of

func (c *Columns) Of[T any]() *goke.OptComp[T]

Of is the column of T, made optional in the query at its first.

type Host

type Host interface {
	Add(rule any) error
}

Host takes rules of the moment it catches: a Rules, a PairRules or a StepRules.

type Hosted

type Hosted interface{ Hosted() any }

Hosted is a rule that builds itself for its host, as an act.Branch does.

type Marks

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

Marks is which tags of a host's families one entity carries, as PairRules reads them.

type Met

type Met interface {
	About
	Whom(each func(uid.UID64))
}

Met is a moment of one entity with others, which PairRules matches in pairs.

type PairRules

type PairRules[P any] struct {
	// contains filtered or unexported fields
}

PairRules are the rules of a moment P of two entities a plugin runs in its pass: it reads the tag families the rules name, eight at most, off the entities (InChunk, At) and dispatches each pair to the rules whose sides it carries.

func (*PairRules[P]) Add

func (r *PairRules[P]) Add(rule any) error

Add takes a pair rule of P; ErrUnhosted for another, ErrHostBuilt after Bind.

func (*PairRules[P]) At

func (r *PairRules[P]) At(query int, cursor *goke.Cursor) Marks

At is what the entity just sought on query carries.

func (*PairRules[P]) Bind

func (r *PairRules[P]) Bind(queries ...*goke.QueryBuilder)

Bind adds every family the rules name to each of the system's queries. Call it once, before they are built.

func (*PairRules[P]) Dispatch

func (r *PairRules[P]) Dispatch(t Tick, self, other Marks, pair P)

Dispatch runs every rule whose first side self carries and second side other carries.

func (*PairRules[P]) DispatchEitherWay

func (r *PairRules[P]) DispatchEitherWay(t Tick, a, b Marks, forward, backward P)

DispatchEitherWay is Dispatch for a pair with no direction, run whichever way the sides fit.

func (*PairRules[P]) DispatchGrouped

func (r *PairRules[P]) DispatchGrouped(t Tick, self Marks, others []Marks, build func(matched []int) P)

DispatchGrouped is Dispatch for one entity against many others, run with none matched too unless the rule names the other's side; build makes the moment of the others matched, by their places in others.

func (*PairRules[P]) Empty

func (r *PairRules[P]) Empty() bool

Empty reports whether no rule was added.

func (*PairRules[P]) InChunk

func (r *PairRules[P]) InChunk(query int, cursor *goke.Cursor, i int) Marks

InChunk is what the i-th entity of the chunk being walked on query carries.

type Placed

type Placed interface {
	About
	Placed()
}

Placed is a moment of an entity standing on places that are entities of their own, which Tick.Around tells and act.Around turns a step on.

type Rules

type Rules[P any] struct {
	// contains filtered or unexported fields
}

Rules are the rules of a moment P a plugin runs in the pass over its entities it makes anyway: Bind them into its query in Init, Run them over each chunk in Update.

func (*Rules[P]) Add

func (r *Rules[P]) Add(rule any) error

Add takes a rule of P; ErrUnhosted for another, ErrHostBuilt after Bind.

func (*Rules[P]) Bind

func (r *Rules[P]) Bind(qb *goke.QueryBuilder)

Bind adds what the rules read to the system's query. Call it once, before the query is built.

func (*Rules[P]) Empty

func (r *Rules[P]) Empty() bool

Empty reports whether no rule was added.

func (*Rules[P]) Run

func (r *Rules[P]) Run(t Tick, cursor *goke.Cursor, about func(i int) P)

Run runs every rule over the chunk being walked; about(i) is the moment of its i-th entity.

func (*Rules[P]) RunWhere

func (r *Rules[P]) RunWhere(t Tick, cursor *goke.Cursor, keep func(i int) bool, about func(i int) P)

RunWhere is Run over the entities of the chunk keep lets through: a moment only some have.

type Side

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

Side is one side of a pair rule: a tag of a family, or anybody.

func SideOf

func SideOf[F any](t tag.Tag[F]) Side

SideOf is t as a side of a pair rule; tag.Any is anybody.

func (Side) Anybody

func (s Side) Anybody() bool

Anybody reports a side of no tag, which anybody is.

type StepRules

type StepRules[P any] struct {
	// contains filtered or unexported fields
}

StepRules are the rules of a moment P of the world as a whole, run once a step and walking no entities. A role's fire while the entity the moment is About plays the role (Tick.Roles).

func (*StepRules[P]) Add

func (r *StepRules[P]) Add(rule any) error

Add takes a rule of P asking nothing of the entity; ErrUnhosted for another, ErrHostBuilt after Bind.

func (*StepRules[P]) Bind

func (r *StepRules[P]) Bind()

Bind marks the system running the rules built, so no rule is taken after. Call it in its Init.

func (*StepRules[P]) Empty

func (r *StepRules[P]) Empty() bool

Empty reports whether no rule was added.

func (*StepRules[P]) Run

func (r *StepRules[P]) Run(t Tick, about P)

Run runs every rule on about.

type Tick

type Tick struct {
	CmdBuf   *goke.CmdBuf
	Now      time.Time // read once for the whole pass
	Dt       time.Duration
	Commands *command.Carrier
	Effects  *effect.Effects
	Time     time.Duration // game time at the step's end
	Seed     uint64
	World    uid.UID64 // the world's own entity
	// Around tells each the places within rings of where the moment stands, those it stands on
	// first; nil where there are none.
	Around func(moment any, rings int, each func(uid.UID64))
	// Roles tells the roles an entity plays, a bit each; nil where there are none.
	Roles func(id uid.UID64) uint64
}

Tick is what a host tells the rules it runs about its pass.

type TickSource

type TickSource func(cb *goke.CmdBuf, dt time.Duration) Tick

TickSource builds the Tick of a pass.

func (TickSource) Of

func (f TickSource) Of(cb *goke.CmdBuf, dt time.Duration) Tick

Of is the Tick of a pass over dt; with no source, one of no world.

Jump to

Keyboard shortcuts

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