Documentation
¶
Index ¶
Constants ¶
const ( StateEngineContinue = 0 StateEngineStop = 1 )
Variables ¶
This section is empty.
Functions ¶
func NewEntityManager ¶
func NewEntityManager() *defaultEntityManager
NewEntityManager creates a new defaultEntityManager and returns its address.
Types ¶
type Component ¶
type Component interface {
Mask() uint64
}
Component contains only the data (no behaviour at all).
type ComponentWithName ¶ added in v0.0.71
ComponentWithName is used by FilterByNames to enable more than 64 Components (if needed).
type Engine ¶ added in v0.1.1
type Engine interface {
// Run calls the Process() method for each System
// until ShouldEngineStop is set to true.
Run()
// Setup calls the Setup() method for each System
// and initializes ShouldEngineStop and ShouldEnginePause with false.
Setup()
// Teardown calls the Teardown() method for each System.
Teardown()
// Tick calls the Process() method for each System exactly once
Tick()
}
Engine handles the stages Setup(), Run() and Teardown() for all the systems.
func NewDefaultEngine ¶ added in v0.1.1
func NewDefaultEngine(entityManager EntityManager, systemManager SystemManager) Engine
NewDefaultEngine creates a new Engine and returns its address.
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.
func NewEntity ¶ added in v0.0.54
NewEntity creates a new entity and pre-calculates the component maskSlice.
type EntityManager ¶
type EntityManager interface {
// Add entries to the manager.
Add(entities ...*Entity)
// Entities returns all the entities.
Entities() (entities []*Entity)
// FilterByMask returns the mapped entities, which Components mask matched.
FilterByMask(mask uint64) (entities []*Entity)
// FilterByNames returns the mapped entities, which Components names matched.
FilterByNames(names ...string) (entities []*Entity)
// Get a specific entity by Id.
Get(id string) (entity *Entity)
// Remove a specific entity.
Remove(entity *Entity)
}
EntityManager handles the access to each entity.
type System ¶
type System interface {
// Setup is called once before the first call to Process.
// It is used to initialize the state of the system.
Setup()
// Process is called for each entity in the system.
// It is used to modify the state of the entity.
Process(entityManager EntityManager) (state int)
// Teardown is called once after the last call to Process.
// It is used to clean up the state of the system.
Teardown()
}
System implements the behaviour of an entity by modifying the state, which is stored in each component of the entity.
type SystemManager ¶ added in v0.0.2
type SystemManager interface {
// Add systems to the this SystemManager.
Add(systems ...System)
// Systems returns internally stored systems.
Systems() []System
}
SystemManager handles the access to each system.
func NewSystemManager ¶ added in v0.0.2
func NewSystemManager() SystemManager
NewSystemManager creates a new defaultSystemManager and returns its address.