Documentation
¶
Overview ¶
Package collide is the engine behind the public collide contract: it finds the overlapping items of one grid, separates them and reports as it goes.
Engine ¶
An Engine is built by New over a Grid and its Surface, reporting to a Handler. Each Engine.Tick takes the grid's items as they are, asks the grid for every pair within reach, hands the pairs to a Solver, and afterwards reports each pushed item once — as Moved, or as Left, with the box it came to rest at, when the push took it wholly out through an open edge. It then tells the grid its cells are behind, so the next Query sees the pushed boxes. A still item a pair meets joins the batch past the moving ones, Static, the first time.
Solver ¶
The Solver holds a batch of Pair values — two positions among the items and flags saying which side is StaticA or StaticB and whether the pair is a Sensor pair that is only ever reported. Solver.Solve sweeps the batch for up to a number of passes: each overlapping pair is put to the Touch callback once, and a confirmed pair is pushed apart along its penetration, the whole way by the non-static side or shared as Touch said, half each without one. A pair is measured again only when one of its boxes has moved since, so a settled batch costs one pass. Solver.VisitMoved then names every item a pass shifted.
Handler ¶
Handler mirrors the public collide.Handler method for method. It is declared again here because an internal package does not import the public one; the public Space passes its handler straight through.
Index ¶
Constants ¶
const ( StaticA uint8 = 1 << iota StaticB Sensor )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶ added in v1.5.0
type Engine struct {
// contains filtered or unexported fields
}
Engine finds and separates the overlapping items of one grid; one Engine serves one goroutine.
func New ¶ added in v1.5.0
func New(grid *spatial.Grid, surface *iplane.Surface, handler Handler, reach float32, iterations int, field pcollide.SolidField) *Engine
New builds an Engine over the CanCollide items of grid, reporting to handler; field, when not nil, is solid ground the movable items are pushed out of.
type Field ¶ added in v1.9.0
type Field struct {
Solid pcollide.SolidField
Walls pcollide.WallField // the Solid's walls, when it has any
Touch func(item int32, cell uint64, pen geom.Vec) (geom.Vec, bool)
Contact func(item int32, cell uint64, pen geom.Vec)
}
Field is how a solve meets the solid ground: the boxes round an item, and whom to tell of them.
type Handler ¶ added in v1.5.0
type Handler interface {
Touch(a, b uid.UID64, pen geom.Vec) (geom.Vec, float32, bool)
Contact(a, b uid.UID64, pen geom.Vec)
Moved(id uid.UID64, box plane.AABB)
}
Handler is told what an Engine finds: each overlapping pair once, and every box it pushed.
type Pair ¶
Pair is two items of a batch that may be in contact, with the flags the solver separates them by.
type Solver ¶
type Solver struct {
// contains filtered or unexported fields
}
Solver is the state and the algorithm behind collide.Engine, working on the items of a Grid.
func (*Solver) Fit ¶ added in v1.21.0
Fit widens the batch to items entries, for entries added since Reset.
func (*Solver) Reset ¶
Reset empties the Solver for a new batch of at most items entries, keeping the memory.
func (*Solver) Solve ¶
func (s *Solver) Solve( items []spatial.Entry, surface *iplane.Surface, iterations int, touch Touch, onContact func(i int, pen geom.Vec), field *Field, )
Solve reports each overlapping pair once and pushes it apart, and every movable item out of the field's solid ground when there is one, in up to iterations passes.
func (*Solver) VisitMoved ¶
VisitMoved calls fn for every item the solver pushed, once per pair it was pushed in.