ecs

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: MIT Imports: 4 Imported by: 77

Documentation

Index

Constants

View Source
const MaskTotalBits = 64

MaskTotalBits is the size of Mask in bits

Variables

This section is empty.

Functions

This section is empty.

Types

type Entity

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

Entity identifier TODO: Store ID and generation in a single uint64?

type ID

type ID uint32

ID defines the format for the components identifier

func ComponentID

func ComponentID[T any](w *World) ID

ComponentID provides a way to get a component's ID via generics

type Mask

type Mask uint64

Mask is a bitmask

func NewMask

func NewMask(ids ...ID) Mask

NewMask creates a new bitmask from a list of IDs If any ID is bigger or equal MaskTotalBits, it'll not be added to the mask Implementation taken from https://github.com/marioolofo/go-gameengine-ecs

func (Mask) Contains

func (e Mask) Contains(other Mask) bool

Contains reports if other mask is a subset of this mask

func (Mask) Get

func (e Mask) Get(bit ID) bool

Get reports if bit index defined by ID is true or false The return will be always false for bit >= MaskTotalBits

func (*Mask) Reset

func (e *Mask) Reset()

Reset change the state of all bits to false

func (*Mask) Set

func (e *Mask) Set(bit ID, value bool)

Set sets the state of bit index to true or false This function has no effect for bit >= MaskTotalBits

func (Mask) TotalBitsSet

func (e Mask) TotalBitsSet() uint

TotalBitsSet returns how many bits are set in this mask

type Query

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

Query is an iterator to iterate entities

func (*Query) Entity

func (q *Query) Entity() Entity

Entity returns the entity at the iterator's position

func (*Query) Get

func (q *Query) Get(comp ID) unsafe.Pointer

Get returns the pointer to the given component at the iterator's position

func (*Query) Has

func (q *Query) Has(comp ID) bool

Has returns whether the current entity has the given component

func (*Query) Next

func (q *Query) Next() bool

Next proceeds to the next entity

type World

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

World holds all ECS data

func NewWorld

func NewWorld() World

NewWorld creates a new World

func (*World) Add

func (w *World) Add(entity Entity, comps ...ID)

Add adds components to an entity.

Do not use during Query iteration!

func (*World) Alive

func (w *World) Alive(entity Entity) bool

Alive reports whether an entity is still alive

func (*World) ComponentID

func (w *World) ComponentID(tp reflect.Type) ID

ComponentID returns the ID for a component type, and registers it if not already registered

func (*World) Get

func (w *World) Get(entity Entity, comp ID) unsafe.Pointer

Get returns a component for an entity

func (*World) Has

func (w *World) Has(entity Entity, comp ID) bool

Has returns whether an entity has a component

func (*World) NewEntity

func (w *World) NewEntity() Entity

NewEntity creates a new or recycled entity.

Do not use during Query iteration!

func (*World) Query

func (w *World) Query(comps ...ID) Query

Query creates a query iterator for the given components

func (*World) RemEntity

func (w *World) RemEntity(entity Entity) bool

RemEntity recycles an entity.

Do not use during Query iteration!

func (*World) Remove

func (w *World) Remove(entity Entity, comps ...ID)

Remove removes components from an entity.

Do not use during Query iteration!

Jump to

Keyboard shortcuts

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