Documentation ¶
Overview ¶
Package wecqs provides the ECS (Entity-Component-System) structure for E2, built around Ebiten.
Index ¶
- Constants
- Variables
- type Component
- type DrawSystem
- type Entity
- type EntityManager
- func (em *EntityManager) Add(es ...*Entity)
- func (em *EntityManager) FilterByComponent(c Component) []*Entity
- func (em *EntityManager) FilterByID(id ulid.ULID) *Entity
- func (em *EntityManager) FilterByMask(mask uint64) []*Entity
- func (em *EntityManager) New(name string, cs ...Component) *Entity
- func (em *EntityManager) RemoveByComponent(c Component) int
- func (em *EntityManager) RemoveByID(id ulid.ULID) bool
- func (em *EntityManager) RemoveByMask(mask uint64) int
- type Scene
- func (s *Scene) AddEntity(es ...*Entity)
- func (s *Scene) FilterEntitiesByComponent(c Component) []*Entity
- func (s *Scene) FilterEntitiesByMask(mask uint64) []*Entity
- func (s *Scene) FilterEntityByID(id ulid.ULID) *Entity
- func (s *Scene) NewEntity(name string, cs ...Component) *Entity
- func (s *Scene) RemoveEntitiesByComponent(c Component) int
- func (s *Scene) RemoveEntitiesByMask(mask uint64) int
- func (s *Scene) RemoveEntityByID(id ulid.ULID) bool
- type SceneManager
- func (sm *SceneManager) Add(ss ...*Scene) error
- func (sm *SceneManager) New(name string) (*Scene, error)
- func (sm *SceneManager) Remove(name string) error
- func (sm *SceneManager) Scene(name string) *Scene
- func (sm *SceneManager) Scenes(sorted bool) []*Scene
- func (sm *SceneManager) Switch(name string) error
- type System
- type SystemManager
- func (sm *SystemManager) Add(s System) error
- func (sm *SystemManager) Count() int
- func (sm *SystemManager) Disable(s System) error
- func (sm *SystemManager) Draw(w *World, canvas *ebiten.Image)
- func (sm *SystemManager) Enable(s System) error
- func (sm *SystemManager) Init(w *World) error
- func (sm *SystemManager) Remove(s System) error
- func (sm *SystemManager) Stop(w *World) error
- func (sm *SystemManager) Systems() []System
- func (sm *SystemManager) Transition(w *World) (string, string)
- func (sm *SystemManager) Update(w *World) error
- type TransitionSystem
- type UpdateSystem
- type World
- func (w *World) ActiveScene() *Scene
- func (w *World) AddScene(ss ...*Scene) error
- func (w *World) AddSystem(s System) error
- func (w *World) DisableSystem(s System) error
- func (w *World) EnableSystem(s System) error
- func (w *World) NewScene(name string) (*Scene, error)
- func (w *World) RemoveScene(name string) error
- func (w *World) RemoveSystem(s System) error
- func (w *World) Scene(name string) *Scene
- func (w *World) SwitchScene(name string) error
- type WorldManager
- func (wm *WorldManager) Add(ws ...*World) error
- func (wm *WorldManager) Names(sorted bool) []string
- func (wm *WorldManager) New(name string) (*World, error)
- func (wm *WorldManager) Remove(name string) error
- func (wm *WorldManager) Switch(name string) error
- func (wm *WorldManager) World(name string) *World
- func (wm *WorldManager) Worlds(sorted bool) []*World
Constants ¶
const ( Component0 uint64 = 1 << iota Component1 Component2 Component3 Component4 Component5 Component6 Component7 Component8 Component9 Component10 Component11 Component12 Component13 Component14 Component15 Component16 Component17 Component18 Component19 Component20 Component21 Component22 Component23 Component24 Component25 Component26 Component27 Component28 Component29 Component30 Component31 Component32 Component33 Component34 Component35 Component36 Component37 Component38 Component39 Component40 Component41 Component42 Component43 Component44 Component45 Component46 Component47 Component48 Component49 Component50 Component51 Component52 Component53 Component54 Component55 Component56 Component57 Component58 Component59 Component60 Component61 Component62 Component63 )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component interface {
Mask() uint64
}
Component is a general-purpose data object for entities. TODO: add Get and Set when generic interfaces are allowed (Go 1.19 probably).
type DrawSystem ¶
type Entity ¶
type Entity struct { ID ulid.ULID Name string Mask uint64 // contains filtered or unexported fields }
Entity is a unique collection of components.
func (*Entity) AddComponent ¶
AddComponent to this Entity.
func (*Entity) Components ¶
Components returns a list of all components currently assigned to this Entity.
func (*Entity) HasComponent ¶
HasComponent returns true if this Entity has a component with the given mask.
func (*Entity) RemoveComponent ¶
RemoveComponent from this Entity which has the given mask.
type EntityManager ¶
type EntityManager struct {
// contains filtered or unexported fields
}
func NewEntityManager ¶
func NewEntityManager() *EntityManager
func (*EntityManager) Add ¶
func (em *EntityManager) Add(es ...*Entity)
Add appends the given entities to this EntityManager.
func (*EntityManager) FilterByComponent ¶
func (em *EntityManager) FilterByComponent(c Component) []*Entity
FilterByComponent filters for only entities which have an identical component to the one provided.
func (*EntityManager) FilterByID ¶
func (em *EntityManager) FilterByID(id ulid.ULID) *Entity
FilterByID returns an entity with the given ID if it exists, else it returns nil.
func (*EntityManager) FilterByMask ¶
func (em *EntityManager) FilterByMask(mask uint64) []*Entity
FilterByMask filters for only entities which match the given component mask.
func (*EntityManager) New ¶
func (em *EntityManager) New(name string, cs ...Component) *Entity
New creates a new Entity with the given components and adds it to this EntityManager.
func (*EntityManager) RemoveByComponent ¶
func (em *EntityManager) RemoveByComponent(c Component) int
RemoveByComponent removes all entities which have an identical component to the one provided.
func (*EntityManager) RemoveByID ¶
func (em *EntityManager) RemoveByID(id ulid.ULID) bool
RemoveByID removes an entity with the given ID and returns true if it was, else it returns false.
func (*EntityManager) RemoveByMask ¶
func (em *EntityManager) RemoveByMask(mask uint64) int
RemoveByMask removes all entities which match the given component mask.
type Scene ¶
type Scene struct { Name string Entities *EntityManager }
func (*Scene) FilterEntitiesByComponent ¶
FilterEntitiesByComponent is a wrapper around (*Scene).Entities.FilterByComponent.
func (*Scene) FilterEntitiesByMask ¶
FilterEntitiesByMask is a wrapper around (*Scene).Entities.FilterByMask.
func (*Scene) FilterEntityByID ¶
FilterEntityByID is a wrapper around (*Scene).Entities.FilterByID.
func (*Scene) RemoveEntitiesByComponent ¶
RemoveEntitiesByComponent is a wrapper around (*Scene).Entities.RemoveByComponent.
func (*Scene) RemoveEntitiesByMask ¶
RemoveEntitiesByMask is a wrapper around (*Scene).Entities.RemoveByMask.
func (*Scene) RemoveEntityByID ¶
RemoveEntityByID is a wrapper around (*Scene).Entities.RemoveByID.
type SceneManager ¶
type SceneManager struct { Active *Scene // contains filtered or unexported fields }
func NewSceneManager ¶
func NewSceneManager() *SceneManager
func (*SceneManager) Add ¶
func (sm *SceneManager) Add(ss ...*Scene) error
Add appends the given scenes to this SceneManager.
func (*SceneManager) New ¶
func (sm *SceneManager) New(name string) (*Scene, error)
New creates a new scene with the given name and adds to this SceneManager.
func (*SceneManager) Remove ¶
func (sm *SceneManager) Remove(name string) error
Remove removes the Scene with the given name.
func (*SceneManager) Scene ¶
func (sm *SceneManager) Scene(name string) *Scene
Scene returns a scene with the given name.
func (*SceneManager) Scenes ¶
func (sm *SceneManager) Scenes(sorted bool) []*Scene
Scenes returns a slice of all the scenes in this SceneManager, optionally sorting them alphabetically.
func (*SceneManager) Switch ¶
func (sm *SceneManager) Switch(name string) error
Switch switches which Scene is currently active.
type SystemManager ¶
type SystemManager struct {
// contains filtered or unexported fields
}
func NewSystemManager ¶
func NewSystemManager() *SystemManager
func (*SystemManager) Add ¶
func (sm *SystemManager) Add(s System) error
Add adds the given System to this SystemManager.
func (*SystemManager) Count ¶ added in v0.2.0
func (sm *SystemManager) Count() int
Count returns the number of available systems.
func (*SystemManager) Disable ¶
func (sm *SystemManager) Disable(s System) error
Disable disables the given System.
func (*SystemManager) Draw ¶
func (sm *SystemManager) Draw(w *World, canvas *ebiten.Image)
Draw runs every DrawSystem in this SystemManager.
func (*SystemManager) Enable ¶
func (sm *SystemManager) Enable(s System) error
Enable enables the given System.
func (*SystemManager) Init ¶
func (sm *SystemManager) Init(w *World) error
Init initialises all the systems in this SystemManager.
func (*SystemManager) Remove ¶
func (sm *SystemManager) Remove(s System) error
Remove removes the given System from this SystemManager.
func (*SystemManager) Stop ¶
func (sm *SystemManager) Stop(w *World) error
Stop stops all the systems in this SystemManager.
func (*SystemManager) Systems ¶
func (sm *SystemManager) Systems() []System
Systems returns a slice of all the available systems in this SystemManager.
func (*SystemManager) Transition ¶ added in v0.2.0
func (sm *SystemManager) Transition(w *World) (string, string)
Transition runs every TransitionSystem in this SystemManager.
func (*SystemManager) Update ¶
func (sm *SystemManager) Update(w *World) error
Update runs every UpdateSystem in this SystemManager.
type TransitionSystem ¶ added in v0.2.0
type World ¶
type World struct { Name string Scenes *SceneManager Systems *SystemManager }
func (*World) ActiveScene ¶
ActiveScene is a wrapper around (*World).Systems.Active.
func (*World) DisableSystem ¶
DisableSystem is a wrapper around (*World).Systems.Disable.
func (*World) EnableSystem ¶
EnableSystem is a wrapper around (*World).Systems.Enable.
func (*World) RemoveScene ¶
RemoveScene is a wrapper around (*World).Scenes.Remove.
func (*World) RemoveSystem ¶
RemoveSystem is a wrapper around (*World).Systems.Remove.
func (*World) SwitchScene ¶
SwitchScene is a wrapper around (*World).Scenes.Switch.
type WorldManager ¶
type WorldManager struct { Active *World // contains filtered or unexported fields }
func NewWorldManager ¶
func NewWorldManager() *WorldManager
func (*WorldManager) Add ¶
func (wm *WorldManager) Add(ws ...*World) error
Add appends the given worlds to this WorldManager.
func (*WorldManager) Names ¶
func (wm *WorldManager) Names(sorted bool) []string
Names returns the names of all the worlds in this WorldManager.
func (*WorldManager) New ¶
func (wm *WorldManager) New(name string) (*World, error)
New creates a new World with the given name and adds to this WorldManager.
func (*WorldManager) Remove ¶
func (wm *WorldManager) Remove(name string) error
Remove removes the World with the given name.
func (*WorldManager) Switch ¶
func (wm *WorldManager) Switch(name string) error
Switch switches which World is currently active.
func (*WorldManager) World ¶
func (wm *WorldManager) World(name string) *World
World returns a World with the given name.
func (*WorldManager) Worlds ¶
func (wm *WorldManager) Worlds(sorted bool) []*World
Worlds returns a slice of all the worlds in this WorldManager.