Documentation ¶
Index ¶
- func Apply[T ComponentType](w *World, e Entity, fn func(*T)) bool
- func Contains[T ComponentType](w *World, e Entity) bool
- func Insert[T any](s []T, k int, vs ...T) []T
- func RegisterGlobalSystem[T ComponentType](info GlobalSystemInfo[T])
- func RegisterGlobalSystem2[T1, T2 ComponentType](info GlobalSystem2Info[T1, T2])
- func RegisterGlobalSystem3[T1, T2, T3 ComponentType](info GlobalSystem3Info[T1, T2, T3])
- func RegisterGlobalSystem4[T1, T2, T3, T4 ComponentType](info GlobalSystem4Info[T1, T2, T3, T4])
- func Remove(w *World, e Entity) bool
- func RemoveComponent[T ComponentType](w *World, e Entity) bool
- func Set[T ComponentType](w *World, e Entity, data T)
- func SortEntities(s []Entity)
- type ComponentData
- type ComponentIndex
- type ComponentIndexEntry
- type ComponentStore
- type ComponentType
- type ComponentWatcher
- type DeserializedComponentData
- type DeserializedEntity
- type DeserializedWorld
- type Encoder
- type Entities
- func (e Entities) MarshalBinary() ([]byte, error)
- func (e Entities) MarshalJSON() ([]byte, error)
- func (e Entities) MarshalText() (text []byte, err error)
- func (e *Entities) UnmarshalBinary(data []byte) error
- func (e *Entities) UnmarshalJSON(b []byte) error
- func (e *Entities) UnmarshalText(text []byte) error
- type Entity
- type Event
- type GlobalSystem2Info
- type GlobalSystem3Info
- type GlobalSystem4Info
- type GlobalSystemInfo
- type IComponentStore
- type ISystem
- type ListenerID
- type Printer
- type SerializedComponentData
- type SerializedEntity
- type SerializedWorld
- type Sortable
- type System
- type System2
- type System3
- type System4
- type View
- type View2
- type View3
- type View4
- type Viewer
- type World
- func (w *World) AllEntities() []Entity
- func (w *World) Data() *container.Dictionary[string, interface{}]
- func (w *World) Enabled() bool
- func (w *World) EntityByUUID(id uuid.UUID) (Entity, bool)
- func (w *World) EntityUUID(e Entity) uuid.UUID
- func (w *World) FireEvent(eventName string, data interface{})
- func (w *World) GetGenericComponent(registryName string) IComponentStore
- func (w *World) IsLoading() bool
- func (w *World) MarshalTo(dw io.Writer) error
- func (w *World) NewEntity() Entity
- func (w *World) OnEvent(eventName string, fn func(e Event)) ListenerID
- func (w *World) Remove(e Entity) bool
- func (w *World) RemoveListener(id ListenerID)
- func (w *World) RemoveSystem(id int) bool
- func (w *World) SetEnabled(v bool)
- func (w *World) Step()
- func (w *World) StepF(flag int)
- func (w *World) UnmarshalFrom(dr io.Reader) error
- func (w *World) UnmarshalFromMeta(md toml.MetaData, prim toml.Primitive) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply[T ComponentType](w *World, e Entity, fn func(*T)) bool
Apply updates the component data for the given entity.
func Contains ¶
func Contains[T ComponentType](w *World, e Entity) bool
Contains returns true if the given entity has the given component.
func Insert ¶
Insert only copies elements in a[i:] once and allocates at most once. But, as of Go toolchain 1.16, due to lacking of optimizations to avoid elements clearing in the "make" call, the verbose way is not always faster.
Future compiler optimizations might implement both in the most efficient ways.
func RegisterGlobalSystem ¶ added in v3.0.2
func RegisterGlobalSystem[T ComponentType](info GlobalSystemInfo[T])
RegisterGlobalSystem registers a system to be included on every new world. All worlds initiated with NewWorld() will have this system included.
func RegisterGlobalSystem2 ¶ added in v3.0.2
func RegisterGlobalSystem2[T1, T2 ComponentType](info GlobalSystem2Info[T1, T2])
RegisterGlobalSystem2 registers a system to be included on every new world. All worlds initiated with NewWorld() will have this system included.
func RegisterGlobalSystem3 ¶ added in v3.0.2
func RegisterGlobalSystem3[T1, T2, T3 ComponentType](info GlobalSystem3Info[T1, T2, T3])
RegisterGlobalSystem3 registers a system to be included on every new world. All worlds initiated with NewWorld() will have this system included.
func RegisterGlobalSystem4 ¶ added in v3.0.2
func RegisterGlobalSystem4[T1, T2, T3, T4 ComponentType](info GlobalSystem4Info[T1, T2, T3, T4])
RegisterGlobalSystem4 registers a system to be included on every new world. All worlds initiated with NewWorld() will have this system included.
func Remove ¶
Remove removes an entity from the world. It will also remove all components attached to the entity. It returns false if the entity was not found.
func RemoveComponent ¶ added in v3.0.1
func RemoveComponent[T ComponentType](w *World, e Entity) bool
RemoveComponent removes the component data for the given entity. It returns false if the component was not found.
func Set ¶
func Set[T ComponentType](w *World, e Entity, data T)
Set replaces or inserts the component data for the given entity. If you junst need to update a value, use Apply() instead.
func SortEntities ¶
func SortEntities(s []Entity)
Types ¶
type ComponentData ¶
type ComponentData[T ComponentType] struct { Entity Entity Data T }
ComponentData holds the data T of an Entity.
type ComponentIndex ¶
type ComponentIndex []ComponentIndexEntry
func (ComponentIndex) ToMap ¶
func (e ComponentIndex) ToMap() map[string]int
type ComponentIndexEntry ¶
type ComponentStore ¶
type ComponentStore[T ComponentType] struct { // contains filtered or unexported fields }
ComponentStore[T ComponentType] is a component data storage. The component data is stored in a slice ordered by the Entity (ID; ascending).
func GetComponentStore ¶
func GetComponentStore[T ComponentType](w *World) *ComponentStore[T]
GetComponentStore returns the component store for the given component type and world instance.
func (*ComponentStore[T]) Apply ¶
func (c *ComponentStore[T]) Apply(e Entity, fn func(*T)) bool
Apply passes a pointer of the component data to the function fn. This is used to read or update data in the component.
func (*ComponentStore[T]) Contains ¶
func (c *ComponentStore[T]) Contains(e Entity) bool
Contains returns true if the entity has data of this component store.
func (*ComponentStore[T]) MergeJSONData ¶
func (c *ComponentStore[T]) MergeJSONData(e Entity, jd []byte) error
MergeJSONData unmarshals the data into the component type of this component store.
func (*ComponentStore[T]) Remove ¶
func (c *ComponentStore[T]) Remove(e Entity) bool
Remove removes the component data from this component store. It returns true if the component data was found (and then removed).
func (*ComponentStore[T]) Replace ¶
func (c *ComponentStore[T]) Replace(e Entity, data T)
Replace adds or replaces the component data for the given entity.
type ComponentType ¶
type ComponentType interface {
Pkg() string
}
ComponentType is a data type that has a Pkg() function. It is used to identify a component type. It must be unique per type in a world.
type ComponentWatcher ¶
type ComponentWatcher[T ComponentType] struct { ComponentAdded func(e Entity) ComponentRemoved func(e Entity) // contains filtered or unexported fields }
func (*ComponentWatcher[T]) Component ¶
func (wa *ComponentWatcher[T]) Component() *ComponentStore[T]
func (*ComponentWatcher[T]) Destroy ¶
func (wa *ComponentWatcher[T]) Destroy()
type DeserializedEntity ¶
type DeserializedEntity struct { UUID uuid.UUID `toml:"uuid"` Components []DeserializedComponentData `toml:"components"` }
type DeserializedWorld ¶
type DeserializedWorld struct { Entities []DeserializedEntity `toml:"entities"` ComponentIndex ComponentIndex `toml:"component_index"` Enabled bool `toml:"enabled"` }
type Entities ¶
type Entities []Entity
func (Entities) MarshalBinary ¶
func (Entities) MarshalJSON ¶
func (Entities) MarshalText ¶
func (*Entities) UnmarshalBinary ¶
func (*Entities) UnmarshalJSON ¶
func (*Entities) UnmarshalText ¶
type Entity ¶
type Entity uint64
func AddEntityUnique ¶
AddEntityUnique adds an entity to a slice if it is not already in the slice.
func RemoveEntityFromSlice ¶
RemoveEntityFromSlice removes an entity from a slice. This func is useful when you don't know if the slice is sorted.
func (Entity) MarshalBinary ¶
func (Entity) MarshalJSON ¶
func (Entity) MarshalText ¶
func (*Entity) UnmarshalBinary ¶
func (*Entity) UnmarshalJSON ¶
func (*Entity) UnmarshalText ¶
type GlobalSystem2Info ¶ added in v3.0.2
type GlobalSystem2Info[T1, T2 ComponentType] struct { ExecPriority int ExecFlag int ExecBuilder func(w *World, s *System2[T1, T2]) func(view *View2[T1, T2]) EntityAddedBuilder func(w *World, s *System2[T1, T2]) func(e Entity) EntityRemovedBuilder func(w *World, s *System2[T1, T2]) func(e Entity) Initializer func(w *World, s *System2[T1, T2]) Finalizer func(w *World, s *System2[T1, T2]) WarmStart bool }
GlobalSystem2Info is the arg of RegisterGlobalSystem2
type GlobalSystem3Info ¶ added in v3.0.2
type GlobalSystem3Info[T1, T2, T3 ComponentType] struct { ExecPriority int ExecFlag int ExecBuilder func(w *World, s *System3[T1, T2, T3]) func(view *View3[T1, T2, T3]) EntityAddedBuilder func(w *World, s *System3[T1, T2, T3]) func(e Entity) EntityRemovedBuilder func(w *World, s *System3[T1, T2, T3]) func(e Entity) Initializer func(w *World, s *System3[T1, T2, T3]) Finalizer func(w *World, s *System3[T1, T2, T3]) WarmStart bool }
GlobalSystem3Info is the arg of RegisterGlobalSystem3
type GlobalSystem4Info ¶ added in v3.0.2
type GlobalSystem4Info[T1, T2, T3, T4 ComponentType] struct { ExecPriority int ExecFlag int ExecBuilder func(w *World, s *System4[T1, T2, T3, T4]) func(view *View4[T1, T2, T3, T4]) EntityAddedBuilder func(w *World, s *System4[T1, T2, T3, T4]) func(e Entity) EntityRemovedBuilder func(w *World, s *System4[T1, T2, T3, T4]) func(e Entity) Initializer func(w *World, s *System4[T1, T2, T3, T4]) Finalizer func(w *World, s *System4[T1, T2, T3, T4]) WarmStart bool }
GlobalSystem4Info is the arg of RegisterGlobalSystem4
type GlobalSystemInfo ¶ added in v3.0.2
type GlobalSystemInfo[T ComponentType] struct { ExecPriority int ExecFlag int ExecBuilder func(w *World, s *System[T]) func(view *View[T]) EntityAddedBuilder func(w *World, s *System[T]) func(e Entity) EntityRemovedBuilder func(w *World, s *System[T]) func(e Entity) Initializer func(w *World, s *System[T]) Finalizer func(w *World, s *System[T]) WarmStart bool }
GlobalSystemInfo is the arg of RegisterGlobalSystem
type IComponentStore ¶
type IComponentStore interface { Contains(e Entity) bool Remove(e Entity) bool MergeJSONData(e Entity, jd []byte) error // contains filtered or unexported methods }
IComponentStore is an interface for component stores.
type ListenerID ¶ added in v3.0.5
type Printer ¶
type Printer interface {
Printf(fmt string, args ...interface{})
}
var (
SerializerLogger Printer
)
type SerializedComponentData ¶
type SerializedComponentData struct { CI int `toml:"ci"` // component index Data interface{} `toml:"data"` }
type SerializedEntity ¶
type SerializedWorld ¶
type SerializedWorld struct { Entities []SerializedEntity `toml:"entities"` ComponentIndex ComponentIndex `toml:"component_index"` Enabled bool `toml:"enabled"` }
type Sortable ¶
type Sortable[TI comparable, TD any] struct { Index TI Data TD }
type System ¶
type System[T ComponentType] struct { Run func(view *View[T]) // contains filtered or unexported fields }
type System2 ¶
type System2[T1 ComponentType, T2 ComponentType] struct { Run func(view *View2[T1, T2]) // contains filtered or unexported fields }
func NewSystem2 ¶
func NewSystem2[T1 ComponentType, T2 ComponentType](priority int, world *World) *System2[T1, T2]
type System3 ¶
type System3[T1 ComponentType, T2 ComponentType, T3 ComponentType] struct { Run func(view *View3[T1, T2, T3]) // contains filtered or unexported fields }
func NewSystem3 ¶
func NewSystem3[T1 ComponentType, T2 ComponentType, T3 ComponentType](priority int, world *World) *System3[T1, T2, T3]
type System4 ¶
type System4[T1, T2, T3, T4 ComponentType] struct { Run func(view *View4[T1, T2, T3, T4]) // contains filtered or unexported fields }
func NewSystem4 ¶
func NewSystem4[T1, T2, T3, T4 ComponentType](priority int, world *World) *System4[T1, T2, T3, T4]
type View ¶
type View[T ComponentType] struct { // contains filtered or unexported fields }
func (*View[T]) Raw ¶
func (v *View[T]) Raw() []ComponentData[T]
Raw returns the raw component data for this view. WARNING: Use this only for fast copying the slice. Altering the original slice will most likely result in undefined behavior.
type View2 ¶
type View2[T1 ComponentType, T2 ComponentType] struct { // contains filtered or unexported fields }
func NewView2 ¶
func NewView2[T1 ComponentType, T2 ComponentType](w *World, onadded, onremoved func(e Entity)) *View2[T1, T2]
type View3 ¶
type View3[T1 ComponentType, T2 ComponentType, T3 ComponentType] struct { // contains filtered or unexported fields }
func NewView3 ¶
func NewView3[T1 ComponentType, T2 ComponentType, T3 ComponentType](w *World, onadded, onremoved func(e Entity)) *View3[T1, T2, T3]
type View4 ¶
type View4[T1 ComponentType, T2 ComponentType, T3 ComponentType, T4 ComponentType] struct { // contains filtered or unexported fields }
func NewView4 ¶
func NewView4[T1 ComponentType, T2 ComponentType, T3 ComponentType, T4 ComponentType](w *World, onadded, onremoved func(e Entity)) *View4[T1, T2, T3, T4]
type World ¶
type World struct {
// contains filtered or unexported fields
}
func NewEmptyWorld ¶ added in v3.0.2
func NewEmptyWorld() *World
NewEmptyWorld creates a new world. A world is not thread safe .I t shouldn't be shared between threads. NewEmptyWorld creates a new world with no systems.
func NewWorld ¶
func NewWorld() *World
NewWorld creates a new world. A world is not thread safe .I t shouldn't be shared between threads. This function also adds the default systems to the world. To create a new world without any systems, use NewEmptyWorld()
func (*World) AllEntities ¶
AllEntities returns all entities in the world
func (*World) Data ¶ added in v3.0.6
func (w *World) Data() *container.Dictionary[string, interface{}]
func (*World) EntityByUUID ¶
EntityByUUID returns the entity with the given UUID If the entity does not exist, an empty entity (0) is returned
func (*World) EntityUUID ¶
EntityUUID returns the UUID of the entity If the entity exists, but no UUID is set, a new UUID is generated and set
func (*World) GetGenericComponent ¶
func (w *World) GetGenericComponent(registryName string) IComponentStore
func (*World) OnEvent ¶ added in v3.0.5
func (w *World) OnEvent(eventName string, fn func(e Event)) ListenerID
func (*World) Remove ¶ added in v3.0.1
Remove removes an Entity. It tries to delete the entity from all the component registries of this world.
func (*World) RemoveListener ¶ added in v3.0.5
func (w *World) RemoveListener(id ListenerID)