wecqs

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package wecqs provides the ECS (Entity-Component-System) structure for E2, built around Ebiten.

Index

Constants

View Source
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

View Source
var (
	ErrWorldAdded       = errors.New("world already added")
	ErrWorldUnavailable = errors.New("world not available")
	ErrWorldInUse       = errors.New("world is currently in use")

	ErrSystemAdded       = errors.New("system already added")
	ErrSystemUnavailable = errors.New("system not available")

	ErrSceneAdded       = errors.New("scene already added")
	ErrSceneUnavailable = errors.New("scene not available")
	ErrSceneInUse       = errors.New("scene is currently in use")
)

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 DrawSystem interface {
	Draw(w *World, canvas *ebiten.Image, dt float64)
	System
}

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 NewEntity

func NewEntity(name string, cs ...Component) *Entity

NewEntity creates a new Entity with the given components.

func (*Entity) AddComponent

func (e *Entity) AddComponent(c Component)

AddComponent to this Entity.

func (*Entity) Component

func (e *Entity) Component(mask uint64) Component

Component gets a component from this Entity with the given mask.

func (*Entity) Components

func (e *Entity) Components() []Component

Components returns a list of all components currently assigned to this Entity.

func (*Entity) HasComponent

func (e *Entity) HasComponent(mask uint64) bool

HasComponent returns true if this Entity has a component with the given mask.

func (*Entity) RemoveComponent

func (e *Entity) RemoveComponent(mask uint64)

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 NewScene

func NewScene(name string) *Scene

func (*Scene) AddEntity

func (s *Scene) AddEntity(es ...*Entity)

AddEntity is a wrapper around (*Scene).Entities.Add.

func (*Scene) FilterEntitiesByComponent

func (s *Scene) FilterEntitiesByComponent(c Component) []*Entity

FilterEntitiesByComponent is a wrapper around (*Scene).Entities.FilterByComponent.

func (*Scene) FilterEntitiesByMask

func (s *Scene) FilterEntitiesByMask(mask uint64) []*Entity

FilterEntitiesByMask is a wrapper around (*Scene).Entities.FilterByMask.

func (*Scene) FilterEntityByID

func (s *Scene) FilterEntityByID(id ulid.ULID) *Entity

FilterEntityByID is a wrapper around (*Scene).Entities.FilterByID.

func (*Scene) NewEntity

func (s *Scene) NewEntity(name string, cs ...Component) *Entity

NewEntity is a wrapper around (*Scene).Entities.New.

func (*Scene) RemoveEntitiesByComponent

func (s *Scene) RemoveEntitiesByComponent(c Component) int

RemoveEntitiesByComponent is a wrapper around (*Scene).Entities.RemoveByComponent.

func (*Scene) RemoveEntitiesByMask

func (s *Scene) RemoveEntitiesByMask(mask uint64) int

RemoveEntitiesByMask is a wrapper around (*Scene).Entities.RemoveByMask.

func (*Scene) RemoveEntityByID

func (s *Scene) RemoveEntityByID(id ulid.ULID) bool

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 System

type System interface {
	Init(w *World) error
	Stop(w *World) error
}

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 TransitionSystem interface {
	Transition(w *World) (string, string)
	System
}

type UpdateSystem

type UpdateSystem interface {
	Update(w *World, dt float64) error
	System
}

type World

type World struct {
	Name string

	Scenes  *SceneManager
	Systems *SystemManager
}

func NewWorld

func NewWorld(name string) *World

NewWorld creates a new World with the given name.

func (*World) ActiveScene

func (w *World) ActiveScene() *Scene

ActiveScene is a wrapper around (*World).Systems.Active.

func (*World) AddScene

func (w *World) AddScene(ss ...*Scene) error

AddScene is a wrapper around (*World).Scenes.Add.

func (*World) AddSystem

func (w *World) AddSystem(s System) error

AddSystem is a wrapper around (*World).Systems.Add.

func (*World) DisableSystem

func (w *World) DisableSystem(s System) error

DisableSystem is a wrapper around (*World).Systems.Disable.

func (*World) EnableSystem

func (w *World) EnableSystem(s System) error

EnableSystem is a wrapper around (*World).Systems.Enable.

func (*World) NewScene

func (w *World) NewScene(name string) (*Scene, error)

NewScene is a wrapper around (*World).Scenes.New.

func (*World) RemoveScene

func (w *World) RemoveScene(name string) error

RemoveScene is a wrapper around (*World).Scenes.Remove.

func (*World) RemoveSystem

func (w *World) RemoveSystem(s System) error

RemoveSystem is a wrapper around (*World).Systems.Remove.

func (*World) Scene

func (w *World) Scene(name string) *Scene

Scene is a wrapper around (*World).Scenes.Scene.id ulid.ULID

func (*World) SwitchScene

func (w *World) SwitchScene(name string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL