entity

package
v0.0.0-...-73b4bbd Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2021 License: MIT Imports: 3 Imported by: 3

Documentation

Index

Constants

View Source
const (
	FlagNew = 1 << iota
	FlagNoCollide
	FlagRemoved
	FlagUserDefined
)

Variables

This section is empty.

Functions

func NewIdGenerator

func NewIdGenerator() func() Id

Returns a function to generate consecutive entity Id's that is safe to call concurrently.

Types

type CanChange

type CanChange interface {
	HasChanged(nextState State, now stime.Time) bool
}

type Entity

type Entity interface {
	// Unique ID
	Id() Id

	// Location in the world
	Cell() coord.Cell

	// Returns a bounding object incorporating
	// the entities potential interaction with
	// the other entities in the world.
	Bounds() coord.Bounds

	// Returns the set of entity flags that can
	// set whether something collides or whether
	// an entity has been changed or not.
	Flags() Flag

	// Returns a state value that represents
	// the entity in its current state.
	ToState() State
}

A basic entity in the world.

type Flag

type Flag uint64

func (Flag) Set

func (f Flag) Set(bits Flag) Flag

func (Flag) Unset

func (f Flag) Unset(bits Flag) Flag

type Id

type Id int64

A unique Id for an entity

type Removed

type Removed struct {
	Entity
	RemovedAt stime.Time
}

func (Removed) Flags

func (e Removed) Flags() Flag

func (Removed) ToState

func (e Removed) ToState() State

type RemovedState

type RemovedState struct {
	Id           Id
	EntityBounds coord.Bounds
}

func (RemovedState) Bounds

func (e RemovedState) Bounds() coord.Bounds

func (RemovedState) EntityId

func (e RemovedState) EntityId() Id

func (RemovedState) IsDifferentFrom

func (e RemovedState) IsDifferentFrom(other State) bool

type State

type State interface {
	// Unique ID
	EntityId() Id

	// Bounds of the entity
	Bounds() coord.Bounds

	// Compare to another entity
	IsDifferentFrom(State) bool
}

Used by the world state to calculate differences between world states. An object that implements this interface should also be friendly to the Json marshaller and expect to be sent to the client over the wire.

type StateById

type StateById map[Id]State

type StateSlice

type StateSlice []State

func (StateSlice) FilterByBounds

func (s StateSlice) FilterByBounds(result StateSlice, bounds coord.Bounds) StateSlice

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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