ecs

package module
v0.0.0-...-28bfceb Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2019 License: MIT Imports: 3 Imported by: 0

README

ECS

Entity Component System in Go

Based on: github.com/alinz/ecs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Destroy

func Destroy(o interface{})

Destroy calls the Destroy function (if it exist) on a entity and all it's components. If o is a component it will call Destroy if it exist.

func NewEntity

func NewEntity() *entity

Types

type Component

type Component interface {
	ComponentType() uint32
}

Component represents the abstract version of data. each component will associate with a meaningful data. because of underneath structure, we can have upto 32 components in total per game. hope that enough...

type Destructible

type Destructible interface {
	Destroy()
}

Destructible defines a component or entity that needs cleanup.

type Entity

type Entity interface {
	ID() uint64
	Component(typ uint32) Component
	Components() []Component
	AddComponent(component Component)
	RemoveComponent(componentType uint32) Component
	HasComponentTypes(componentTypes uint32) bool
}

Entity is a shell around multiple components. components can be added or removed from entity either at runtime or compile time.

type Manager

type Manager interface {
	AddSystem(system System)
	RemoveSystem(systemType uint32) System
	Update(stage int, delta time.Duration)
}

Manager is a simple abstraction of minimum requirement of method which needed for any game.

type Query

type Query interface {
	Entities(componentTypes uint32) []Entity
	ForAllEntities(componentTypes uint32, f func(e Entity) bool)
	EntityByID(id uint64) Entity
	EntitiesByID(ids ...uint64) []Entity
	AddEntity(Entity)
	RemoveEntity(Entity) Entity
	RemoveEntityByID(id uint64) Entity
	System(systemType uint32) System
}

Query is a bridge between System and Entity. query can be used to fetch array of entities based on the data that they have or accessing an already exist system.

type System

type System interface {
	SystemType() uint32
	Active(stage int) bool
	Update(delta time.Duration, query Query)
}

System contains all the methods which will needed for hopfully all the scenarioes. There is an Update method that is being called by World and was given a Query object for manipulating entities.

type World

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

func (*World) AddEntity

func (w *World) AddEntity(entity Entity)

func (*World) AddSystem

func (w *World) AddSystem(system System)

func (*World) Entities

func (w *World) Entities(componentTypes uint32) []Entity

func (*World) EntitiesByID

func (w *World) EntitiesByID(ids ...uint64) []Entity

func (*World) EntityByID

func (w *World) EntityByID(id uint64) Entity

func (*World) ForAllEntities

func (w *World) ForAllEntities(componentTypes uint32, f func(e Entity) bool)

func (*World) RemoveEntity

func (w *World) RemoveEntity(target Entity) Entity

func (*World) RemoveEntityByID

func (w *World) RemoveEntityByID(id uint64) Entity

func (*World) RemoveSystem

func (w *World) RemoveSystem(systemType uint32) System

func (*World) System

func (w *World) System(systemType uint32) System

func (*World) Update

func (w *World) Update(stage int, delta time.Duration)

Jump to

Keyboard shortcuts

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