Documentation ¶
Index ¶
- Constants
- type EPS
- type Moves
- func (mov *Moves) AddPendingMove(ent ecs.Entity, dir image.Point, mag, maxMag int) ecs.Entity
- func (mov *Moves) Collisions(opts ...ecs.CursorOpt) ecs.Cursor
- func (mov *Moves) DeleteDir(move ecs.Entity)
- func (mov *Moves) Dir(move ecs.Entity) (image.Point, bool)
- func (mov *Moves) GetPendingMove(ent ecs.Entity) ecs.Entity
- func (mov *Moves) Init(eps *EPS, collMask ecs.ComponentType)
- func (mov *Moves) Mag(move ecs.Entity) int
- func (mov *Moves) Pending(opts ...ecs.CursorOpt) ecs.Cursor
- func (mov *Moves) Process()
- func (mov *Moves) SetDir(move ecs.Entity, dir image.Point)
- func (mov *Moves) SetMag(move ecs.Entity, mag int)
- func (mov *Moves) SetPendingMove(ent ecs.Entity, dir image.Point, mag int) ecs.Entity
Constants ¶
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 ¶
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) Get ¶
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 ¶
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.
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 ¶
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 ¶
Collisions returns a relation cursor over all collisions from the last processing round.
func (*Moves) DeleteDir ¶
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 ¶
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 ¶
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 ¶
Mag returns any magnitude associated with the given move relation; 0 means no magnitude defined.
func (*Moves) Pending ¶
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.