Documentation
¶
Index ¶
- Variables
- func RunBroadPhaseOn(q Quad, now stime.Time) (cgroups []*CollisionGroup, solved, unsolved CollisionGroupIndex)
- type Chunk
- type Collision
- type CollisionGroup
- type CollisionGroupIndex
- type CollisionIndex
- type Corner
- type InputPhaseHandler
- type InputPhaseHandlerFn
- type NarrowPhaseHandler
- type NarrowPhaseHandlerFn
- type Quad
- func New(bounds coord.Bounds, maxSize int, entities []entity.Entity) (Quad, error)
- func RunInputPhaseOn(q Quad, inputPhase InputPhaseHandler, now stime.Time) (Quad, []entity.Entity)
- func RunNarrowPhaseOn(q Quad, cgroups []*CollisionGroup, narrowPhase NarrowPhaseHandler, ...) (Quad, []entity.Entity)
- func RunPhasesOn(q Quad, updatePhase UpdatePhaseHandler, inputPhase InputPhaseHandler, ...) Quad
- func RunUpdatePhaseOn(q Quad, updatePhase UpdatePhaseHandler, now stime.Time) (Quad, []entity.Entity, []entity.Entity)
- type UpdatePhaseHandler
- type UpdatePhaseHandlerFn
Constants ¶
This section is empty.
Variables ¶
var ErrBoundsHeightMustBePowerOf2 = errors.New("bounds height must be a power of 2")
var ErrBoundsWidthMustBePowerOf2 = errors.New("bounds width must be a power of 2")
var ErrMaxSizeTooSmall = errors.New("max size must be > 1")
Guards against unspecified behavior if the maxSize is 1
Functions ¶
func RunBroadPhaseOn ¶
func RunBroadPhaseOn( q Quad, now stime.Time) (cgroups []*CollisionGroup, solved, unsolved CollisionGroupIndex)
Types ¶
type Chunk ¶
A group of entities within a bounding rectangle. A chunk is sent to the collision function that is implemented by the user of engine.
type Collision ¶
A collision between 2 entities because the entities bounds are overlapping. Intended to be solved by the user defined NarrowPhaseHandler.
type CollisionGroup ¶
type CollisionGroup struct { // A slice of the all the entities that are in // the collisions of the group. Entities []entity.Entity // A slice of all the collisions in the group. Collisions []Collision }
A group of collisions where each collision may have an effect on the others. A dependency tree should be created by the user to resolve the collisions in the correct order.
func (CollisionGroup) AddCollision ¶
func (cg CollisionGroup) AddCollision(c Collision) CollisionGroup
Adds a collision to the group. Also adds the entities from the collision to the entities slice. Filters out collisions it already has and entities that are already in the entities slice.
func (CollisionGroup) Bounds ¶
func (cg CollisionGroup) Bounds() coord.Bounds
func (CollisionGroup) CollisionIndex ¶
func (cg CollisionGroup) CollisionIndex() CollisionIndex
type CollisionGroupIndex ¶
type CollisionGroupIndex map[entity.Entity]*CollisionGroup
An entity may ONLY be assigned to 1 collision group. If an entity has collisions that are in separate collision groups, those groups must be merged. This rules make the collision group index possible.
type CollisionIndex ¶
A collision index stores all the collisions an entity is involved in.
type InputPhaseHandler ¶
2. Input Application Phase - User Defined
The input phase takes the user input and applies it. This application can modify the entities movement state or create new entities. The input phase should return a slice of entities that includes the entity that it was applying input to. This slice of entities can also include any entities that may have been created by the actor's input (using skills and spells, chat messages, etc). These new entities will be inserted into the quad tree.
type InputPhaseHandlerFn ¶
Convenience type so input phase handlers can be written as closures or as functions.
func (InputPhaseHandlerFn) ApplyInputsTo ¶
type NarrowPhaseHandler ¶
type NarrowPhaseHandler interface {
ResolveCollisions(*CollisionGroup, stime.Time) (entities []entity.Entity, removed []entity.Entity)
}
4. Narrow Phase - User Defined
The narrow phase resolves all the collisions in a collision group. The phase handler should return 2 slices of entities. The first is the entities that still exist or have been created. The second is any entities that have been destroyed. The user implementation should also be where movement actions are accepted and an entities position is modified.
type NarrowPhaseHandlerFn ¶
Convenience type so narrow phase handlers can be written as closures or as functions.
func (NarrowPhaseHandlerFn) ResolveCollisions ¶
func (f NarrowPhaseHandlerFn) ResolveCollisions(cgrp *CollisionGroup, now stime.Time) ([]entity.Entity, []entity.Entity)
type Quad ¶
type Quad interface { Parent() Quad Child(Corner) Quad Children() []Quad Bounds() coord.Bounds // Mutators Insert(entity.Entity) Quad Remove(entity.Entity) Quad QueryCell(coord.Cell) []entity.Entity QueryBounds(coord.Bounds) []entity.Entity Chunk() Chunk // contains filtered or unexported methods }
An interface used to abstract the implementation differences of a node and a leaf.
func RunInputPhaseOn ¶
func RunNarrowPhaseOn ¶
func RunNarrowPhaseOn( q Quad, cgroups []*CollisionGroup, narrowPhase NarrowPhaseHandler, now stime.Time) (Quad, []entity.Entity)
func RunPhasesOn ¶
func RunPhasesOn( q Quad, updatePhase UpdatePhaseHandler, inputPhase InputPhaseHandler, narrowPhase NarrowPhaseHandler, now stime.Time) Quad
type UpdatePhaseHandler ¶
1. Update Position Phase - User Defined
This phase is for updating an entity's position if their previous movement has be completed on this tick. This must happen before the input application phase so the quad tree can be queried during that phase and the information won't be racy depending on the order that the input hase been applied. If update returns nil instead of the entity, it will be removed.
type UpdatePhaseHandlerFn ¶
Convenience type so input phase handlers can be written as closures or as functions.