Documentation ¶
Index ¶
- Variables
- type BaseSystem
- func (s *BaseSystem) Activate()
- func (s *BaseSystem) Active() bool
- func (s *BaseSystem) Deactivate()
- func (s *BaseSystem) Init(world *World, tickFunc func())
- func (s *BaseSystem) InjectComponent(c Component, dst **ComponentFactory)
- func (s *BaseSystem) IsInitialized() bool
- func (s *BaseSystem) Name() string
- func (s *BaseSystem) SetPostTickCallback(fn func())
- func (s *BaseSystem) SetPreTickCallback(fn func())
- func (s *BaseSystem) SetTickFrequency(rate float64)
- func (s *BaseSystem) Tick()
- func (s *BaseSystem) TickCount() uint
- func (s *BaseSystem) TickFrequency() float64
- func (s *BaseSystem) TickPeriod() time.Duration
- func (s *BaseSystem) Uptime() time.Duration
- type C
- type CID
- type Component
- type ComponentFactory
- type ComponentFilter
- type ComponentFilterBuilder
- func (cfb *ComponentFilterBuilder) Build() *ComponentFilter
- func (cfb *ComponentFilterBuilder) Forbid(components ...Component) *ComponentFilterBuilder
- func (cfb *ComponentFilterBuilder) Require(components ...Component) *ComponentFilterBuilder
- func (cfb *ComponentFilterBuilder) RequireOne(components ...Component) *ComponentFilterBuilder
- type ComponentID
- type E
- type EID
- type EntityID
- type Initializer
- type S
- type Subscription
- type System
- type W
- type World
- func (w *World) AddSubscription(input interface{}) *Subscription
- func (w *World) AddSystem(s System, activate bool) *World
- func (w *World) GetComponentFactory(id ComponentID) *ComponentFactory
- func (w *World) NewComponentFilter() *ComponentFilterBuilder
- func (w *World) NewEntity() EID
- func (w *World) RegisterComponent(c Component) ComponentID
- func (w *World) RemoveEntity(id EID)
- func (w *World) RemoveSystem(s System) *World
- func (w *World) Update() error
- func (w *World) UpdateEntity(id EID)
- type WorldConfig
Constants ¶
This section is empty.
Variables ¶
var DefaultTickRate float64 = 100
Functions ¶
This section is empty.
Types ¶
type BaseSystem ¶
type BaseSystem struct { *World // contains filtered or unexported fields }
BaseSystem is the base system type
func (*BaseSystem) Activate ¶
func (s *BaseSystem) Activate()
Activate calls Tick repeatedly at the target TickRate. This method blocks the thread.
func (*BaseSystem) Active ¶
func (s *BaseSystem) Active() bool
Active returns true if the system is active, otherwise false
func (*BaseSystem) Deactivate ¶
func (s *BaseSystem) Deactivate()
Deactivate marks the system inactive and stops it from ticking automatically in the background. The system can be re-activated by calling the Activate method.
func (*BaseSystem) Init ¶
func (s *BaseSystem) Init(world *World, tickFunc func())
func (*BaseSystem) InjectComponent ¶
func (s *BaseSystem) InjectComponent(c Component, dst **ComponentFactory)
InjectComponent is shorthand for registering a component and placing the factory in the given destination
func (*BaseSystem) IsInitialized ¶
func (s *BaseSystem) IsInitialized() bool
func (*BaseSystem) Name ¶
func (s *BaseSystem) Name() string
func (*BaseSystem) SetPostTickCallback ¶
func (s *BaseSystem) SetPostTickCallback(fn func())
func (*BaseSystem) SetPreTickCallback ¶
func (s *BaseSystem) SetPreTickCallback(fn func())
func (*BaseSystem) SetTickFrequency ¶
func (s *BaseSystem) SetTickFrequency(rate float64)
func (*BaseSystem) Tick ¶
func (s *BaseSystem) Tick()
Tick performs a single tick. This is called automatically when the System is Active, but can be called manually to single-step the System, regardless of the System's TickRate.
func (*BaseSystem) TickCount ¶
func (s *BaseSystem) TickCount() uint
func (*BaseSystem) TickFrequency ¶
func (s *BaseSystem) TickFrequency() float64
TickFrequency returns the maximum number of ticks per second this system will perform.
func (*BaseSystem) TickPeriod ¶
func (s *BaseSystem) TickPeriod() time.Duration
TickPeriod returns the length of one tick as a time.Duration
func (*BaseSystem) Uptime ¶
func (s *BaseSystem) Uptime() time.Duration
type Component ¶
type Component interface {
New() Component
}
Component can be anything with a `New` method that creates a new component instance
type ComponentFactory ¶
type ComponentFactory struct {
// contains filtered or unexported fields
}
ComponentFactory is used to manage a one-to-one mapping between entity ID's and component instances. The factory is responsible for creating, retrieving, and deleting components using a given component ID.
Attempting to create more than one component for a given component ID will result in nothing happening (the existing component instance will still exist).
func (*ComponentFactory) Add ¶
func (cf *ComponentFactory) Add(id EID) Component
Add a new component for the given entity ID and yield the component. If a component already exists, yield the existing component.
This operation will update world subscriptions for the given entity.
func (*ComponentFactory) Get ¶
func (cf *ComponentFactory) Get(id EID) (Component, bool)
Get will yield the component and a bool, much like map retrieval. The bool indicates whether a component was found for the given entity ID. The component can be nil.
func (*ComponentFactory) ID ¶
func (cf *ComponentFactory) ID() ComponentID
ID returns the registered component ID for this component type
func (*ComponentFactory) Remove ¶
func (cf *ComponentFactory) Remove(id EID)
Remove will destroy the component instance for the given entity ID. This operation will update world subscriptions for the given entity ID.
type ComponentFilter ¶
type ComponentFilter struct { Required *bitset.BitSet OneRequired *bitset.BitSet Forbidden *bitset.BitSet }
ComponentFilter is a group of 3 BitSets which are used to filter any other given BitSet. A target (fourth, external) BitSet is allowed to "pass" through the filter under the following conditions:
The target bitset contains all "required" bits The target bitset contains at least one of the "one required" bits The target bitset contains none of the "forbidden" bits
If the target bitset invalidates any of these three rules, the target bitset is said to have been "rejected" by the filter.
func NewComponentFilter ¶
func NewComponentFilter(all, oneOf, none *bitset.BitSet) *ComponentFilter
NewComponentFilter creates a component filter using the given BitSets.
The first BitSet declares those bits which are required in order to pass through the filter.
The second BitSet declares those bits of which at least one is required in order to pass through the filter.
The third BitSet declares those bits which none are allowed to pass through the filter.
func (*ComponentFilter) Allow ¶
func (cf *ComponentFilter) Allow(other *bitset.BitSet) bool
Allow returns true if the given bitset is not rejected by the component filter
func (*ComponentFilter) Equals ¶
func (cf *ComponentFilter) Equals(other *ComponentFilter) bool
Equals checks if this component filter is equal to the argument component filter
type ComponentFilterBuilder ¶
type ComponentFilterBuilder struct {
// contains filtered or unexported fields
}
ComponentFilterBuilder creates a component filter config
func NewComponentFilterBuilder ¶
func NewComponentFilterBuilder(w *World) *ComponentFilterBuilder
NewComponentFilterBuilder creates a new builder for a component filter, using the given world.
func (*ComponentFilterBuilder) Build ¶
func (cfb *ComponentFilterBuilder) Build() *ComponentFilter
Build iterates through all components in the filter and registers them in the world, to ensure that all components have a unique Component ID. Then, the bitsets for Required, OneRequired, and Forbidden bits are set in the corresponding bitsets of the filter.
func (*ComponentFilterBuilder) Forbid ¶
func (cfb *ComponentFilterBuilder) Forbid(components ...Component) *ComponentFilterBuilder
Forbid makes all of the given components forbidden by the filter
func (*ComponentFilterBuilder) Require ¶
func (cfb *ComponentFilterBuilder) Require(components ...Component) *ComponentFilterBuilder
Require makes all of the given components required by the filter
func (*ComponentFilterBuilder) RequireOne ¶
func (cfb *ComponentFilterBuilder) RequireOne(components ...Component) *ComponentFilterBuilder
RequireOne makes at least one of the given components required
type Initializer ¶
type Subscription ¶
type Subscription struct { Filter *ComponentFilter // contains filtered or unexported fields }
Subscription is a component filter and a slice of entity ID's for which the filter applies
func NewSubscription ¶
func NewSubscription(cf *ComponentFilter) *Subscription
NewSubscription creates a new subscription with the given component filter
func (*Subscription) AddEntity ¶
func (s *Subscription) AddEntity(id EID)
AddEntity adds an entity to the subscription entity map
func (*Subscription) EntityIsIgnored ¶
func (s *Subscription) EntityIsIgnored(id EID) bool
func (*Subscription) GetEntities ¶
func (s *Subscription) GetEntities() []EID
GetEntities returns the entities for the system
func (*Subscription) IgnoreEntity ¶
func (s *Subscription) IgnoreEntity(id EID)
func (*Subscription) RemoveEntity ¶
func (s *Subscription) RemoveEntity(id EID)
RemoveEntity removes an entity from the subscription entity map
type System ¶
type System interface { Update() // contains filtered or unexported methods }
System describes the bare minimum of what is considered a system
type World ¶
type World struct {
// contains filtered or unexported fields
}
World contains all of the Entities, Components, and Systems
func NewWorld ¶
func NewWorld(optional ...*WorldConfig) *World
NewWorld creates a new world instance from the given world configs
func (*World) AddSubscription ¶
func (w *World) AddSubscription(input interface{}) *Subscription
AddSubscription will look for an identical component filter and return an existing subscription if it can. Otherwise, it creates a new subscription and returns it.
func (*World) AddSystem ¶
AddSystem adds a system to the world. The System will become Active on the next World Update
func (*World) GetComponentFactory ¶
func (w *World) GetComponentFactory(id ComponentID) *ComponentFactory
GetComponentFactory returns the ComponentFactory for the given ComponentID
func (*World) NewComponentFilter ¶
func (w *World) NewComponentFilter() *ComponentFilterBuilder
NewComponentFilter creates a builder for creating
func (*World) RegisterComponent ¶
func (w *World) RegisterComponent(c Component) ComponentID
RegisterComponent registers a component type, assigning and returning its component ID
func (*World) RemoveSystem ¶
RemoveSystem queues the given system for removal
func (*World) Update ¶
Update iterates through all Systems and calls the update method if the system is active
func (*World) UpdateEntity ¶
UpdateEntity updates the entity in the world. This causes the entity manager to update all subscriptions for this entity ID.
type WorldConfig ¶
type WorldConfig struct {
// contains filtered or unexported fields
}
WorldConfig is used to declare Systems and component mappers. This is to be passed to a World factory function.
func NewWorldConfig ¶
func NewWorldConfig() *WorldConfig
NewWorldConfig creates a world config builder instance
func (*WorldConfig) With ¶
func (b *WorldConfig) With(arg interface{}) *WorldConfig
With is used to add either Systems or component maps.
Examples:
builder.With(&system{}) builder.With(&component{}) builder. With(&movementSystem{}). With(&velocity{}). With(&position{})