ecs

package module
v0.0.0-...-d86cfb8 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseComponent

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

func (BaseComponent) GetID

func (b BaseComponent) GetID() EntityID

type BaseSystem

type BaseSystem struct {
	Priority int
	World    *World
}

func (*BaseSystem) GetPriority

func (bs *BaseSystem) GetPriority() int

func (*BaseSystem) Init

func (bs *BaseSystem) Init(world *World)

type Entity

type Entity interface {
	// contains filtered or unexported methods
}

type EntityID

type EntityID = uint

type SimpleSystem

type SimpleSystem[T Entity] struct {
	BaseSystem
}

If a system will only act on one kind of entity, the simple system simplify querying the world for this kind of entities

func (*SimpleSystem[T]) Query

func (ss *SimpleSystem[T]) Query() []Entity

type System

type System interface {
	// Called once on initialisation.
	// Systems will be called by decreasing number of priority. If multiple system
	// have the same priority, the calling order is undefined and shouldn't be
	// relied on.
	// Priority changes after initialisation will not be considered.
	GetPriority() int

	// Called on each world update, arg is milisec since last world update
	Update(dt int64)

	// Called when the system is added to a world
	Init(world *World)
}

type World

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

func NewWorld

func NewWorld() World

func (*World) AddEntity

func (w *World) AddEntity(es ...Entity)

func (*World) AddSystem

func (w *World) AddSystem(ss ...System)

func (*World) GetEntityByID

func (w *World) GetEntityByID(id EntityID) (Entity, bool)

func (*World) GetEntityCount

func (w *World) GetEntityCount() int

func (*World) GetSystemCount

func (w *World) GetSystemCount() int

func (*World) QueryEntity

func (w *World) QueryEntity(i reflect.Type) []Entity

Return every entity in the world that implements the interface 'i'

func (*World) RemoveEntity

func (w *World) RemoveEntity(es ...Entity)

func (*World) RemoveSystem

func (w *World) RemoveSystem(ss ...System)

func (*World) Update

func (w *World) Update()

Update each and every system in the world

Jump to

Keyboard shortcuts

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