eps

package
v0.0.0-...-e2c65c2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MaxMoveTypeBit is where extension types may pick up within Moves's
	// ComponentType space. Use it like:
	// 	const (
	// 		myMoveType ecs.ComponentType = 1 << iota + eps.MaxMoveTypeBit
	// 		myOtherMoveType // etc...
	// 	)
	MaxMoveTypeBit = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EPS

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

EPS is an Entity Positioning System; (technically it's not an ecs.System, it just has a reference to an ecs.Core).

func (*EPS) At

func (eps *EPS) At(pt image.Point) []ecs.Entity

At returns a slice of entities at a given point; NOTE the slice is not safe to retain long term, and MAY be re-used by the next call to EPS.At.

TODO provide a struct that localizes that sharing.

func (*EPS) Bounds

func (eps *EPS) Bounds() (box image.Rectangle)

Bounds returns the bounding box containing all defined points.

func (*EPS) Get

func (eps *EPS) Get(ent ecs.Entity) (image.Point, bool)

Get the position of an entity; the bool argument is true only if the entity actually has a position.

func (*EPS) Init

func (eps *EPS) Init(core *ecs.Core, t ecs.ComponentType)

Init ialize the EPS wrt a given core and component type that represents "has a position".

func (*EPS) Iter

func (eps *EPS) Iter() ecs.Iterator

Iter returns an entity iterator that iterates in postition-local order: entities that have the same position will be contiguous, and entities that are near will be near in iteration order.

Iteration stops if the EPS is invalidated during iteration (by changing a position, or creating a new position component). After such a halt, the iterator may be reset, re-indexing the EPS and starting iteration over again with the update position data.

func (*EPS) Set

func (eps *EPS) Set(ent ecs.Entity, pt image.Point)

Set the position of an entity, adding the eps's component if necessary.

type Moves

type Moves struct {
	// PreCheck is a hook that may modify a pending move just before
	// application; e.g. to discount move magnitude due to inability of the
	// entity. The function may also return a limit that will cap how much mag
	// may be spent on the move; any remaining mag passes on in the subsequent
	// collision or pending relation.
	PreCheck func(uc *ecs.UpsertCursor, dir image.Point, mag int) (_ image.Point, _, limit int)

	ecs.Relation
	// contains filtered or unexported fields
}

Moves is a movement system around an EPS.

Movement works by registering a pending movement intent, expressed as a direction and magnitude. Pending moves are then processed, updating entity positions (modulo collisions).

After processing, collision relations are available to build further mechanics upon. Collision relations carry the moved direction, and any remaining magnitude not spent on the move.

Collisions only occur if more than one entity share any bits under the type mask given to Init().

Pending moves are expressed as a self-relation (a == b == ent), while collisions have a == movingEntity and b == hitEntity.

func (*Moves) AddPendingMove

func (mov *Moves) AddPendingMove(ent ecs.Entity, dir image.Point, mag, maxMag int) ecs.Entity

AddPendingMove adds the given magnitude to any pending move for the given entity, overwriting the direction. Ensures that at most one pending move is definded for the given entity.

func (*Moves) Collisions

func (mov *Moves) Collisions(opts ...ecs.CursorOpt) ecs.Cursor

Collisions returns a relation cursor over all collisions from the last processing round.

func (*Moves) DeleteDir

func (mov *Moves) DeleteDir(move ecs.Entity)

DeleteDir deletes any direction associated with the given move relation, destroying it if it's now reduced to a magnitude-less pending move.

func (*Moves) Dir

func (mov *Moves) Dir(move ecs.Entity) (image.Point, bool)

Dir returns any direction associated with the given move relation; the bool return is true only if the move has a defined direction.

func (*Moves) GetPendingMove

func (mov *Moves) GetPendingMove(ent ecs.Entity) ecs.Entity

GetPendingMove returns the associated pending move relation for the given entity.

func (*Moves) Init

func (mov *Moves) Init(eps *EPS, collMask ecs.ComponentType)

Init ialize the movement system, attached to the given positioning system, and using the given bits collision mask.

func (*Moves) Mag

func (mov *Moves) Mag(move ecs.Entity) int

Mag returns any magnitude associated with the given move relation; 0 means no magnitude defined.

func (*Moves) Pending

func (mov *Moves) Pending(opts ...ecs.CursorOpt) ecs.Cursor

Pending returns a relation cursor over all pending moves; thse are either unprocessed moves, or leftover/unused magnitudes.

func (*Moves) Process

func (mov *Moves) Process()

Process applies pending moves, generating any consequesnt collisons; any prior collisions are first deleted.

func (*Moves) SetDir

func (mov *Moves) SetDir(move ecs.Entity, dir image.Point)

SetDir sets the direction associated with the given move relation.

func (*Moves) SetMag

func (mov *Moves) SetMag(move ecs.Entity, mag int)

SetMag sets the magnitude associated with the given move relation; 0 removes the magnitude component (and destroys the move if it is pending).

func (*Moves) SetPendingMove

func (mov *Moves) SetPendingMove(ent ecs.Entity, dir image.Point, mag int) ecs.Entity

SetPendingMove sets both magnitude and direction on an existing or new pending move for the given entity. Ensures that at most one pending move is defined for the given entity.

Jump to

Keyboard shortcuts

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