entity

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultManager = NewInMemoryRepository()

DefaultManager ...

Functions

This section is empty.

Types

type Component

type Component interface {
	Mask() uint64
}

Component contains only the data (no behaviour at all). The Name() method must be implemented, because the inMemoryRepository uses it to filter the entities by component names.

type ComponentWithName

type ComponentWithName interface {
	Component
	Name() string
}

ComponentWithName is used by FilterByNames to enable more than 64 Components (if needed).

type Entity

type Entity struct {
	Components []Component `json:"components"`
	Id         string      `json:"id"`
	Masked     uint64      `json:"masked"`
}

Entity is simply a composition of one or more Components with an Id.

func NewEntity

func NewEntity(id string, components []Component) *Entity

NewEntity creates a new entity and pre-calculates the component maskSlice.

func (*Entity) Add

func (e *Entity) Add(cn ...Component)

Add a component.

func (*Entity) Get

func (e *Entity) Get(mask uint64) Component

Get a component by its bitmask.

func (*Entity) ID

func (e *Entity) ID() string

ID ...

func (*Entity) Mask

func (e *Entity) Mask() uint64

Mask returns a pre-calculated maskSlice to identify the Components.

func (*Entity) Remove

func (e *Entity) Remove(mask uint64)

Remove a component by using its maskSlice.

type Repository

type Repository interface {
	Add(entities ...*Entity)
	Entities() (entities []*Entity)
	FilterByMask(mask uint64) (entities []*Entity)
	FilterByNames(names ...string) (entities []*Entity)
	Get(id string) (entity *Entity)
	Remove(entity *Entity)
}

Repository handles the access to each entity.

func NewInMemoryRepository

func NewInMemoryRepository() Repository

NewInMemoryRepository creates a new inMemoryRepository and returns its address.

Jump to

Keyboard shortcuts

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