Documentation
¶
Index ¶
Constants ¶
const ( StateEngineContinue = 0 StateEngineStop = 1 Version = "v0.0.68" )
Variables ¶
This section is empty.
Functions ¶
func Do ¶
func Do(fn func())
Do runs the given function in the main OS thread. This is necessary for non-Go library functions that depend on per-thread state.
func Main ¶
func Main(worker func())
Main prepares Go for running Cgo calls in a separate worker function safely by locking the main OS thread to the current Goroutine.
func Run ¶
func Run(em *EntityManager, sm *SystemManager, tick int)
Run simplifies the engine usage by calling the Setup(), Run() and Teardown() internally.
Types ¶
type Component ¶
type Component interface {
Mask() uint64
}
Component contains only the data (no behaviour at all). The Name() method must be implemented, because the EntityManager uses it to filter the entities by component names.
type Engine ¶ added in v0.7.8
type Engine struct {
// contains filtered or unexported fields
}
engine is simple a composition of an EntityManager and a SystemManager. It handles the stages Setup(), Run() and Teardown() for all the systems.
func NewEngine ¶
func NewEngine(entityManager *EntityManager, systemManager *SystemManager) *Engine
NewEngine creates a new Engine and returns its address.
func (*Engine) Run ¶ added in v0.7.8
Run calls the Process() method for each System until ShouldEngineStop is set to true.
type Entity ¶
type Entity struct { Components []Component `json:"components"` Id string `json:"id"` Masked uint64 `json:"masked"` }
Entity is simply a composition of one or more Components with an Id.
type EntityManager ¶
type EntityManager struct {
// contains filtered or unexported fields
}
EntityManager handles the access to each entity.
func NewEntityManager ¶
func NewEntityManager() *EntityManager
NewEntityManager creates a new EntityManager and returns its address.
func (*EntityManager) Add ¶
func (m *EntityManager) Add(entities ...*Entity)
Add entries to the manager.
func (*EntityManager) Entities ¶
func (m *EntityManager) Entities() (entities []*Entity)
Entities returns all the entities.
func (*EntityManager) FilterByMask ¶
func (m *EntityManager) FilterByMask(mask uint64) (entities []*Entity)
FilterBy returns the mapped entities, which Components name matched.
func (*EntityManager) Get ¶
func (m *EntityManager) Get(id string) (entity *Entity)
Get a specific entity by Id.
func (*EntityManager) Remove ¶
func (m *EntityManager) Remove(entity *Entity)
Remove a specific entity.
type Plugin ¶
type Plugin func(em *EntityManager) (state int)
Plugin is a function which handles a specific kind of functionality by using an EntityManager to gain access to the entities.
type System ¶
type System interface { Setup(entityManager *EntityManager) Process(entityManager *EntityManager, dt float64) (state int) Teardown() }
System implements the behaviour of an entity by modifying the state, which is stored in each component of the entity.
type SystemManager ¶
type SystemManager struct {
// contains filtered or unexported fields
}
SystemManager handles the access to each system.
func NewSystemManager ¶
func NewSystemManager() *SystemManager
NewSystemManager creates a new SystemManager and returns its address.
func (*SystemManager) Add ¶
func (m *SystemManager) Add(systems ...System)
Add systems to the SystemManager.
func (*SystemManager) Systems ¶
func (m *SystemManager) Systems() []System
Systems returns the system, which are internally stored.