core

package
v0.0.0-...-3cc1577 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddComp

func AddComp(w *World, e Entity, c Component)

AddComp adds the Component to Entity as a tag, without underlying content

func DelComp

func DelComp(w *World, e Entity, c Component)

DelComp removes the Component of an Entity. If the Entity doesn't have the Component, nothing will happen.

func DelEntity

func DelEntity(w *World, e Entity)

func GetComp

func GetComp[C any](w *World, e Entity, c Component) (data *C)

GetComp gets the data of a Component of an Entity. If the Entity doesn't have the Component, nil will be returned.

func HasComp

func HasComp(w *World, e Entity, c Component) bool

HasComp reports whether the Entity has the Component.

func SetComp

func SetComp[C any](w *World, e Entity, c Component, data C)

SetComp adds the Component and its content to Entity.

If the Entity already has the Component, the content will be overridden. If the Entity doesn't have the Component, the Component will be added.

This function panics if the type of data doesn't match others of the same Component.

func Type

func Type(w *World, e Entity, nameComp Component) string

Types

type Archetype

type Archetype struct {
	Types

	Comps []Storage
	// contains filtered or unexported fields
}

type ArchetypeEdge

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

type CachedQuery

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

CachedQuery is cached filter

func (*CachedQuery) Free

func (q *CachedQuery) Free(w *World)

func (*CachedQuery) Run

func (q *CachedQuery) Run(h func(entities []Entity, data []any))

type Component

type Component struct{ Entity }

A Component is a type of which instances can be added and removed to entities. Each component can be added only once to an entity.

--flecs.dev

func NewComponent

func NewComponent(w *World) (c Component)

NewComponent creates a new Component in the World. The data type associated with the Component will be bind when the first data is set.

type ComponentMeta

type ComponentMeta struct {
	Component
	// If the component's corresponding data has type T,
	// this stores the reflect.Type of Table[T].
	// We need this because, when creating new archetypes,
	// we need to create new Storage for the Components.
	TableType reflect.Type
}

type Entity

type Entity uint64

An Entity is a unique thing in the world, and is represented by a 64-bit id. Entities can be created and deleted. If an entity is deleted, it is no longer considered "alive".

A world can contain up to 4 billion alive entities. Entity identifiers contain a few bits that make it possible to check whether an entity is alive or not.

--flecs.dev

func NewEntity

func NewEntity(w *World) (e Entity)

NewEntity creates a new Entity in the World, without any Components.

type EntityRecord

type EntityRecord struct {
	AT  *Archetype
	Row int
}

type Filter

type Filter func(*World, *Archetype, *[]int) bool

func QueryAll

func QueryAll(comps ...Component) Filter

func QueryAny

func QueryAny(comps ...Component) Filter

func (Filter) Cache

func (f Filter) Cache(w *World) (q *CachedQuery)

func (Filter) Run

func (f Filter) Run(w *World, h func(entities []Entity, data []any))

type IDManager

type IDManager struct {
	NextID   uint64
	Freelist []uint64
}

type Storage

type Storage interface {
	Get(i int) any
	// contains filtered or unexported methods
}

type Table

type Table[C any] []C

func (*Table[C]) Get

func (c *Table[C]) Get(i int) any

type Types

type Types []ComponentMeta

Types is list of Components. It's sorted and able to be hashed. Allowing us to find the archetype by the hash of its type.

type World

type World struct {
	IDManager

	// The default archetype for newly created entities, which contains no Components.
	Zero *Archetype

	// All entities in the World, including Components.
	// Records their archetype's pointer and the index of the Comps belonging to the entity.
	Entities map[Entity]*EntityRecord

	// All archetypes in the World.
	// The key of the map is the hash of the archetype's Types.
	// And the value is the archetype's pointer.
	Archetypes map[uint64]*Archetype

	// This field stores maps for each component.
	// Each map contains a list of archetypes that have the component.
	// And the component's corresponding Storage index in the archetype.
	//
	// We can check if an archetype has a component by looking up the map.
	//
	// For any Component c and archetype a:
	//	col, ok := Components[c][a]
	// If ok == true, then archetype a has component c, otherwise it doesn't.
	// And if col == -1, archetype a has component c but doesn't contain any data,
	// otherwise the col is the index of the component's Storage in the archetype.
	Components map[Component]map[*Archetype]int

	// For high performance, we cache the queries.
	// But these caches will get outdated when new archetypes are created.
	// We register all queries created here, and update them when new archetypes are created.
	Queries Table[*CachedQuery]
	// contains filtered or unexported fields
}

The World is the container for all ECS data. It stores the entities and their Components, does queries and runs systems.

--flecs.dev

func NewWorld

func NewWorld() (w *World)

NewWorld creates a new empty World, with the default Components.

Jump to

Keyboard shortcuts

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