ecs

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: Zlib Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EntityWithComponents

func EntityWithComponents(components ...Component) func(e *BaseEntity)

EntityWithComponents is option to initialize entity with components.

Types

type BaseEntity

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

BaseEntity is basically implemented entity.

func NewBaseEntity

func NewBaseEntity(options ...func(e *BaseEntity)) *BaseEntity

NewBaseEntity returns generated base entity with given options.

func (*BaseEntity) AddComponents

func (e *BaseEntity) AddComponents(c ...Component)

func (*BaseEntity) Clone

func (e *BaseEntity) Clone() Entity

func (*BaseEntity) Components

func (e *BaseEntity) Components(ids []ComponentID) (components []Component, isAll bool)

func (*BaseEntity) RemoveComponent

func (e *BaseEntity) RemoveComponent(component Component) (removed bool)

func (*BaseEntity) String

func (e *BaseEntity) String() string

type Component

type Component interface {
	ID() ComponentID
	Clone() Component
}

type ComponentID

type ComponentID uint64

type Entity

type Entity interface {
	// AddComponents adds components to entity.
	AddComponents(c ...Component)
	// Components returns components that matching with argument.
	// if all components has found, isAll will be true.
	Components(ids []ComponentID) (components []Component, isAll bool)
	// RemoveComponent removes component from entity.
	RemoveComponent(component Component) (removed bool)
	// Clone clones entity with all component, values.
	Clone() Entity
	String() string
}

Entity is identified object that can have components.

type Priority added in v0.1.2

type Priority interface {
	Priority() int
}

type System

type System interface {
	Init(w *World) error
	Update(w *World, dt float64) error
}

type World

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

World is game scene that contains entities and systems.

func NewWorld

func NewWorld() *World

NewWorld returns new world with default capacity.

func (*World) AddEntities

func (w *World) AddEntities(entity ...Entity)

AddEntities adds entities to world.

func (*World) AddSystem

func (w *World) AddSystem(systems ...System) error

AddSystem adds system to world.

func (*World) Init

func (w *World) Init() error

Init should be called in initialization step.

func (*World) RemoveEntity

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

RemoveEntity removes entity from world.

func (*World) Update

func (w *World) Update(dt float64) error

Update should be called in every game loop.

func (*World) WithComponents

func (w *World) WithComponents(ids []ComponentID, f func(components []Component, all bool))

WithComponents finds all components that matching with given ids, and callback with its array.

Jump to

Keyboard shortcuts

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