entity

package
v0.11.10 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRepository = NewInMemoryRepository()

DefaultRepository is initialized by NewInMemoryRepository().

Functions

This section is empty.

Types

type Component

type Component interface {
	Mask() uint64
}

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

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() *Entity

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

func (*Entity) Add

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

Add a component.

func (*Entity) Get

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

Get a component by its bitmask.

func (*Entity) ID

func (a *Entity) ID() string

ID ...

func (*Entity) Mask

func (a *Entity) Mask() uint64

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

func (*Entity) Remove

func (a *Entity) Remove(mask uint64)

Remove a component by using its maskSlice.

func (*Entity) WithComponents

func (a *Entity) WithComponents(components ...Component) *Entity

func (*Entity) WithID

func (a *Entity) WithID(id string) *Entity

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