Documentation ¶
Index ¶
- func GetComponentFor[T any](components map[uint64]any, eId uint64) T
- func GetComponentsFor[T any](ecs *ECS) map[uint64]T
- func GetContextFor[T any](ecs *ECS) T
- func GetEntityComponent[T any](ecs *ECS, eId uint64) T
- type BaseEntity
- type Component
- type ComponentStorage
- type ECS
- func (this *ECS) AddContext(c any) *ECS
- func (this *ECS) AddEntity(e any) Entity
- func (this *ECS) AddSystem(s System, types ...any) *ECS
- func (this *ECS) Clear()
- func (this *ECS) CreateEntity(components ...any) Entity
- func (this *ECS) GetComponents(componentType any) map[uint64]interface{}
- func (this *ECS) GetContext(c any) any
- func (this *ECS) GetEntity(id uint64) Entity
- func (this *ECS) RemoveEntity(id uint64)
- func (this *ECS) RemoveEntityNow(id uint64)
- func (this *ECS) RemoveSystem(s System) *ECS
- func (this *ECS) Update(dt time.Duration) *ECS
- type Entity
- type EntitySystem
- type System
- type SystemStorage
- func (this *SystemStorage) AddSystem(system System, types ...any) []reflect.Type
- func (this *SystemStorage) All() []System
- func (this *SystemStorage) AllParallel() [][]System
- func (this *SystemStorage) Clear()
- func (this *SystemStorage) QuerySystems(types ...any) []System
- func (this *SystemStorage) RemoveSystem(system System)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetComponentFor ¶
GetComponentFor is a casting helper to return a typed component by entity id
func GetComponentsFor ¶
GetComponentsFor creates a typed map of the components
func GetContextFor ¶ added in v0.2.0
GetContextFor is a convenience generic call for easier type
func GetEntityComponent ¶
GetEntityComponent is a typed helper to get a cast entity component from the ECS
Types ¶
type BaseEntity ¶
type BaseEntity struct {
// contains filtered or unexported fields
}
func NewEntity ¶
func NewEntity(counter *atomic.Uint64) (this *BaseEntity)
func (*BaseEntity) AddComponent ¶
func (this *BaseEntity) AddComponent(component any)
func (*BaseEntity) AddComponents ¶
func (this *BaseEntity) AddComponents(component ...any)
func (*BaseEntity) GetComponents ¶
func (this *BaseEntity) GetComponents() []any
func (*BaseEntity) Id ¶
func (this *BaseEntity) Id() uint64
func (*BaseEntity) MarshalJSON ¶
func (this *BaseEntity) MarshalJSON() ([]byte, error)
MarshalJSON to expose the id without exporting it, as it may not be altered!
type ComponentStorage ¶
type ComponentStorage struct {
// contains filtered or unexported fields
}
func NewComponentStorage ¶
func NewComponentStorage(ecs *ECS) (this *ComponentStorage)
func (*ComponentStorage) AddComponent ¶
func (this *ComponentStorage) AddComponent(e Entity, components ...any)
AddComponent stores the given components
func (*ComponentStorage) Clear ¶
func (this *ComponentStorage) Clear()
func (*ComponentStorage) GetComponents ¶
func (this *ComponentStorage) GetComponents(componentType any) map[uint64]interface{}
GetComponents by given type
func (*ComponentStorage) RemoveComponent ¶
func (this *ComponentStorage) RemoveComponent(e Entity, components ...any)
RemoveComponent deletes the given components from their respective types and entity
type ECS ¶
type ECS struct {
// contains filtered or unexported fields
}
func NewParallel ¶ added in v0.3.0
func NewParallel() (this *ECS)
NewParallel creates a new asynchronous ecs world (costs, do not use if you don't need it)
func (*ECS) AddContext ¶
AddContext attaches any service, map or other interfaces to this ECS (there can only be one per type)
func (*ECS) CreateEntity ¶
CreateEntity scaffolds a new entity with the given components
func (*ECS) GetComponents ¶
GetComponents by given type
func (*ECS) GetContext ¶
GetContext returns a context from the ECS (there can only be one per type)
func (*ECS) RemoveEntity ¶
RemoveEntity marks an entity for deletion in the next iteration, to not affect the current run
func (*ECS) RemoveEntityNow ¶
RemoveEntityNow detaches the entity now, no matter of more systems are running
func (*ECS) RemoveSystem ¶
RemoveSystem deletes the given system from this ECS
type EntitySystem ¶
type EntitySystem struct {
// contains filtered or unexported fields
}
func (*EntitySystem) AttachEntity ¶
func (this *EntitySystem) AttachEntity(e Entity)
func (*EntitySystem) DetachEntity ¶
func (this *EntitySystem) DetachEntity(e Entity)
func (*EntitySystem) Entities ¶
func (this *EntitySystem) Entities() []uint64
func (*EntitySystem) Priority ¶
func (this *EntitySystem) Priority() int
Priority assigns this system importance - higher=better
type SystemStorage ¶
type SystemStorage struct {
// contains filtered or unexported fields
}
func NewParallelSystemStorage ¶ added in v0.3.0
func NewParallelSystemStorage(ecs *ECS) (this *SystemStorage)
NewParallelSystemStorage creates a parallel-systems tracking storage (costs, do not use if you don't need it)
func NewSystemStorage ¶
func NewSystemStorage(ecs *ECS, parallel bool) (this *SystemStorage)
func (*SystemStorage) AddSystem ¶
func (this *SystemStorage) AddSystem(system System, types ...any) []reflect.Type
AddSystem stores the given system under every type to this storage
func (*SystemStorage) AllParallel ¶ added in v0.3.0
func (this *SystemStorage) AllParallel() [][]System
AllParallel returns all systems grouped by parallelity
func (*SystemStorage) QuerySystems ¶
func (this *SystemStorage) QuerySystems(types ...any) []System
QuerySystems returns all systems matching all given types connotations
func (*SystemStorage) RemoveSystem ¶
func (this *SystemStorage) RemoveSystem(system System)
RemoveSystem slices the given system out of every type from this storage