entitysys

package
v0.0.0-...-03afc55 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2015 License: Apache-2.0 Imports: 1 Imported by: 4

Documentation

Overview

Package entitysys provides a simple entity component system for handling entities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

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

Container stores multiple systems and their entities.

func NewContainer

func NewContainer() *Container

NewContainer creates a new Container.

func (*Container) AddEntity

func (c *Container) AddEntity(entity interface{})

AddEntity adds the entity to all systems that are compatible with the entity.

func (*Container) AddSystem

func (c *Container) AddSystem(stage Stage, f interface{}, matchers ...Matcher)

AddSystem adds the system to the container, the passed desc values will be used to match when an entity is added. f will called for all matching entities depending on the stage. All parameters to f are automatically added to matchers.

func (*Container) RemoveEntity

func (c *Container) RemoveEntity(e interface{})

RemoveEntity removes the entity from all systems it is attached too.

func (*Container) Tick

func (c *Container) Tick()

Tick ticks all systems and their entities.

type Matcher

type Matcher interface {
	Match(e interface{}) bool
}

Matcher is used to select when an entity is used for a system.

func Not

func Not(d Matcher) Matcher

Not inverts the passed Matcher.

func Type

func Type(t interface{}) Matcher

Type returns a Matcher that matches when the type of element of the passed to this is implemented by the entity.

This method should be used as followed for interfaces

Type((*MyInterface)(nil))

type Stage

type Stage int

Stage is used to specify when a system is called.

const (
	// Add marks the system for being called when a entity is
	// added to a container.
	Add Stage = iota
	// Tick marks the system for being called when a entity is
	// ticked.
	Tick
	// Remove marks the system for being called when a entity is
	// removed from a container.
	Remove
)

Jump to

Keyboard shortcuts

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