entity

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GenerationShiftBits = 64 - 8
	FlagsShiftBits      = 64 - 16
	IndexBitMask        = 0x00_00_FFFF_FFFF_FFFF
)

Variables

View Source
var (
	// The number of slots required to be in the free list before the free list
	// is used for creating new entries
	FreeListUsageThreshold uint32 = 20
)

Functions

func AddComp

func AddComp[T Comp](e *Entity, c T)

func DestroyComp added in v0.14.0

func DestroyComp[T Comp](e *Entity)

DestroyComp calls Destroy on the component and then removes it from the entities component list

func GetComp

func GetComp[T Comp](e *Entity) (out T)

func GetGeneration

func GetGeneration(id EntityHandle) byte

func GetIndex

func GetIndex(id EntityHandle) uint64

func HasComp added in v0.14.0

func HasComp[T Comp](e *Entity) bool

Types

type BaseComp added in v0.14.0

type BaseComp struct {
	Entity *Entity
}

func (*BaseComp) Destroy added in v0.14.0

func (b *BaseComp) Destroy()

func (*BaseComp) Init added in v0.14.0

func (b *BaseComp) Init(parent *Entity)

func (*BaseComp) Name added in v0.14.0

func (b *BaseComp) Name() string

func (*BaseComp) Update added in v0.14.0

func (b *BaseComp) Update()

type Comp

type Comp interface {
	Name() string
	Init(parent *Entity)
	Update()
	Destroy()
	// contains filtered or unexported methods
}

type Entity

type Entity struct {

	// Byte 1: Generation; Byte 2: Flags; Bytes 3-8: Index
	ID    EntityHandle
	Comps []Comp
}

func (*Entity) HasFlag

func (e *Entity) HasFlag(ef EntityFlag) bool

func (*Entity) UpdateAllComps added in v0.14.0

func (e *Entity) UpdateAllComps()

type EntityFlag

type EntityFlag byte
const (
	EntityFlag_None  EntityFlag = 0
	EntityFlag_Alive EntityFlag = 1 << (iota - 1)
)

func GetFlags

func GetFlags(id EntityHandle) EntityFlag

type EntityHandle added in v0.14.0

type EntityHandle uint64

func NewEntityId

func NewEntityId(generation byte, flags EntityFlag, index uint64) EntityHandle

type Registry

type Registry struct {
	EntityCount uint64
	Entities    []Entity

	FreeList     *freeListitem
	FreeListSize uint32
}

func NewRegistry

func NewRegistry(size uint32) *Registry

func (*Registry) FreeEntity

func (r *Registry) FreeEntity(id EntityHandle)

FreeEntity calls Destroy on all the entities components, resets the component list, resets the entity flags, then ads this entity to the free list

func (*Registry) GetEntity

func (r *Registry) GetEntity(id EntityHandle) *Entity

func (*Registry) NewEntity

func (r *Registry) NewEntity() *Entity

Jump to

Keyboard shortcuts

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