Documentation
¶
Overview ¶
Package collide is the contract of a Space's collision engine: what it is told (Config), whom it reports to (Handler), and what a caller drives (Engine). Space.CollideEngine of package aabbworld builds one over a Space's CanCollide boxes.
Handler ¶
One Engine.Tick talks to the Handler in a fixed order. Touch is asked once for every pair of boxes that overlap, with the penetration between them — boxes overlapping by no more than float32's rounding of where they lie touch, and are no pair; the handler may confirm the pair as it is, refine the penetration (a round shape inside a square box touches later than the box does) or veto the pair for this tick, and says what part of the push apart moves the first box, the rest moving the second: ½ shares it evenly, 0 leaves the first where it is; a Static box never moves whatever the share. Contact is told each confirmed pair once, with the penetration it is being separated by. Moved is told every box the engine pushed, once, where it came to rest — already written where the Space reads it, so only a caller whose items are a copy writes it back to whatever owns it. A box pushed out through an open edge is not Moved; it is listed by Engine.Left until the next Tick, as a Leaver with the box it came to rest at, wholly past the edge, written where the Space reads it the same way.
Config ¶
Reach is how far a box may travel in one tick, as a fraction of its shorter side; boxes whose reaches do not touch are never paired, so it bounds the work of a tick. Iterations caps the passes one Tick spends on chained overlaps: separating one pair may push a box into a third, which the next pass resolves.
Field ¶
Config.Field is a SolidField, the solid ground of a world on a grid, which need not be boxes in the Space. In every pass, after the pairs, the engine asks it for the solid boxes around each movable box (CanCollide, not Static) that moved since it last asked, and pushes the box out of each it overlaps through the shallowest side marked open in FieldBox.Open — the shallowest side at all when none is — so a box sliding along a wall of many cells never catches on the seams between them. A field that is also a WallField hands the engine its walls at any angle besides, after the boxes: a FieldWall is a segment Half thick either side, and a box is pushed out of it square to it — pieces joined end to end slide a box along them as one wall — or round a free end (FieldWall.Open) where that is shorter. A Sensor is told but not pushed. A pushed box is Moved like any other. A Handler that is also a FieldHandler is asked TouchField and told ContactField once per entity and cell a tick, boxes and walls of one cell alike; any other Handler hears nothing of the ground.
Engine ¶
An Engine serves one goroutine. Tick reads the boxes of its Space as they are now — the Space need only have been Rebuilt since the items changed — and leaves them pushed apart; the Space answers its next Query with the pushed boxes on its own. A still box (Space.RebuildStill) is paired with the moving boxes alone and never pushed, as though it were Static.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v1.5.0
type Config struct {
// Reach is how far a box may travel in a tick, as a fraction of its shorter side.
Reach float32
// Iterations caps the passes one Tick spends on chained overlaps.
Iterations int
// Field is the solid ground the Engine pushes movable boxes out of in the same passes as the
// pairs; nil is none.
Field SolidField
}
Config is how far an Engine looks for pairs and how long it spends separating them.
type Engine ¶ added in v1.5.0
type Engine interface {
// Tick separates every overlapping pair the Space holds now and reports as it goes; the
// Space answers its next Query with the pushed boxes without another Rebuild.
Tick()
// Left is who the last Tick pushed out through an open edge, and where to; good until the
// next Tick.
Left() []Leaver
}
Engine finds and separates the overlapping CanCollide boxes of its Space, on one goroutine.
type FieldBox ¶ added in v1.9.0
FieldBox is one solid box of a SolidField: where it is, which cell of the ground it is, for the handler, and which of its sides face open ground — the only ways a box inside it is pushed out, so a box sliding along a wall of many cells never catches on the seams between them.
type FieldHandler ¶ added in v1.9.0
type FieldHandler interface {
TouchField(id uid.UID64, cell uint64, pen geom.Vec) (geom.Vec, bool)
ContactField(id uid.UID64, cell uint64, pen geom.Vec)
}
FieldHandler is a Handler also told about the solid ground: once per entity and cell a tick, TouchField asks whether they really touch, and by how much (false: not this tick), and ContactField tells the contact, with the push that separates the entity. A Handler that is not a FieldHandler is told nothing of the ground; the Engine pushes all the same.
type FieldWall ¶ added in v1.12.0
FieldWall is one wall of a WallField: Half thick either side of the segment from A to B, the cell of the ground it is, for the handler, and which of its ends stand free. A box is pushed out of it square to it — so pieces of wall joined end to end slide a box along them as one — and round a free end where that is the shorter way.
type Handler ¶ added in v1.5.0
type Handler interface {
// Touch says whether the shapes in two overlapping boxes really touch, by how much, and what
// part of the push apart moves a, the rest moving b: 0 leaves a, ½ shares it evenly; a Static
// box never moves.
Touch(a, b uid.UID64, pen geom.Vec) (push geom.Vec, shareA float32, ok bool)
// Contact is a pair Touch confirmed, with the penetration it is being separated by.
Contact(a, b uid.UID64, pen geom.Vec)
// Moved is a box the Engine pushed, where it came to rest.
Moved(id uid.UID64, box plane.AABB)
}
Handler is told what an Engine finds: each overlapping pair once, and every box it pushed.
type Leaver ¶ added in v1.10.0
Leaver is a box an Engine pushed out through an open edge, where it came to rest — wholly past the edge. It is not Moved: whoever owns the box writes it back from here.
type SolidField ¶ added in v1.9.0
SolidField is the solid ground of a world laid out on a grid — walls, rock, whatever no one passes — as an Engine asks it, instead of being boxes in the Space. Solid calls visit with every solid box of the ground that box of entity id may overlap, for that entity (a wall may let a flyer over); visit returning false ends the walk. Boxes lie in the frame of the box asked about: across a wrapping seam, shifted to its side.
type WallField ¶ added in v1.12.0
type WallField interface {
SolidField
Walls(id uid.UID64, box geom.AABB, visit func(FieldWall) bool)
}
WallField is a SolidField with walls at any angle besides its boxes: Walls calls visit with every wall that box of entity id may overlap, for that entity, in the frame of the box asked about; visit returning false ends the walk. An Engine asks a SolidField that is one for its walls after its boxes.