Documentation
¶
Overview ¶
Package ecs is the implementation of the Entity Component System design used by github.com/paked/engi. It is predominately used by games, however will find use in other applications.
Copyright 2014-2015 Harrison Shoebridge and other contributors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Index ¶
- type Component
- type Entity
- type System
- type Systemer
- type Systemers
- type World
- func (w *World) AddEntity(entity *Entity)
- func (w *World) AddSystem(system Systemer)
- func (w *World) Entities() []*Entity
- func (w *World) HasSystem(systemType string) bool
- func (w *World) New()
- func (w *World) RemoveEntity(entity *Entity)
- func (w *World) Systems() []Systemer
- func (w *World) Update(dt float32)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component interface {
Type() string
}
Component is a piece of data which belongs to an Entity
type Entity ¶
type Entity struct { Pattern string // contains filtered or unexported fields }
Entity is the E in Entity Component System. It belongs to any amount of Systems, and has a number of Components
func (*Entity) AddComponent ¶
AddComponent adds a new Component to the Entity
func (*Entity) Component ¶
Component takes a double pointer to a Component, and populates it with the value of the right type.
func (*Entity) ComponentFast ¶
ComponentFast returns the same object as Component but without using reflect (and thus faster). Be sure to define the .Type() such that it takes a pointer receiver
func (*Entity) DoesRequire ¶
DoesRequire checks if the Entity requires a system
func (*Entity) RemoveComponent ¶
RemoveComponent removes a Component from the Entity
type System ¶
System is the default implementation of the Systemer interface.
func (*System) RemoveEntity ¶
func (System) RunInParallel ¶
type Systemer ¶
type Systemer interface { // Type returns an individual string identifier, usually the struct name // eg. "RenderSystem", "CollisionSystem"... Type() string // Priority is used to create the order in which Systemers are processed Priority() int // RunInParallel checks whether the System can run in parallel. This is ran every update, // so it is possible to run serial when the system has < 10 entities, and then run in parallel // when not RunInParallel() bool // New is the initialisation of the System New(*World) // Pre is ran just before the System updates, every frame Pre() // Post is ran just after the System updates, every frame Post() // Update is ran every frame, and for each Entity which belongs to the // System Update(entity *Entity, dt float32) // Entities returns a slice of all Entities Entities() []*Entity // AddEntity adds a new Entity to the System AddEntity(entity *Entity) // AddEntity removes an Entity from the System RemoveEntity(entity *Entity) }
Systemer is an interface which implements a System. A System iterates over the Entitys it is required by, and can process their Components
type Systemers ¶
type Systemers []Systemer
Systemers implements a sortable list of System. It is indexed on System.Priority().
type World ¶
type World struct {
// contains filtered or unexported fields
}
World contains a bunch of Entitys, and a bunch of Systems. It is the recommended way to run ecs
func (*World) AddSystem ¶
AddSystem adds a new System to the World, and then sorts them based on Priority
func (*World) RemoveEntity ¶
RemoveEntity removes an Entity from the World and its required Systems