host

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 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 to the columns of its query (store.Columns) and runs it over every block of entities (store.Row), 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. Aimed is a command told the subject of the moment it is given on.

Places

A library names the kinds of places its hosts tell for their moments (NewPlacing: those round where an entity stands, those in front of it), each saying which moments have them; Places are some of a kind, whom a rule's cond.At and act.At turn to, told by Tick.Places.

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' runtime, the time, the seed, the places 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

This section is empty.

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 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 pass runs: it reads the tag families the rules name, eight at most, off the entities (Read) 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]) Bind

func (r *PairRules[P]) Bind(queries ...store.Columns)

Bind binds every family the rules name to the columns of each of the pass's queries, one Columns a query, in the order Read takes them. Call it once, as 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]) Read added in v0.2.0

func (r *PairRules[P]) Read(query int, row store.Row, i int) Marks

Read is what the i-th entity of a block of the query-th query carries; in Seek mode i is the cursor's slot.

type Places added in v0.3.0

type Places struct {
	Placing *Placing
	N       int
}

Places are those of a Placing within N of the moment: whom cond.At and act.At turn a rule to, a branch run once a place.

func (Places) String added in v0.3.0

func (p Places) String() string

type Placing added in v0.3.0

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

Placing is a kind of places the hosts of a library tell for their moments (Tick.Places), named for the messages: Takes says of a moment whether it has them.

func NewPlacing added in v0.3.0

func NewPlacing(name string, takes func(moment any) bool) *Placing

NewPlacing is the kind of places name, of the moments takes reports, each a pointer to the moment a rule fires on.

func (*Placing) String added in v0.3.0

func (p *Placing) String() string

func (*Placing) Takes added in v0.3.0

func (p *Placing) Takes(moment any) bool

Takes reports whether moment has places of the kind.

type Rules

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

Rules are the rules of a moment P a pass runs over the entities it walks anyway: Bind them to the columns of its query as it is built, Run them over each block of entities.

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(cols store.Columns)

Bind binds what the rules read to the columns of the pass's query. Call it once, as 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, row store.Row, n int, about func(i int) P)

Run runs every rule over a block of n entities; about(i) is the moment of its i-th entity.

func (*Rules[P]) RunWhere

func (r *Rules[P]) RunWhere(t Tick, row store.Row, n int, keep func(i int) bool, about func(i int) P)

RunWhere is Run over the entities of the block 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 {
	Now      time.Time // read once for the whole pass
	Dt       time.Duration
	Commands *command.Carrier
	Effects  effect.Runtime
	Time     time.Duration // game time at the step's end
	Seed     uint64
	World    uid.UID64 // the world's own entity
	// Places tells each the places p are of the moment, a pointer to it; nil where there are
	// none.
	Places func(moment any, p Places, 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(dt time.Duration) Tick

TickSource builds the Tick of a pass.

func (TickSource) Of

func (f TickSource) Of(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