entitas

package
v0.0.0-...-2824937 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: MIT Imports: 4 Imported by: 0

README

Entitas

Implementation of the Entitas entity framework in Go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrComponentExists       = errors.New("component exists")
	ErrComponentDoesNotExist = errors.New("component does not exist")
)

提示消息

Functions

func NewGroupObserver

func NewGroupObserver(group Group, event ObserverEvent) *groupObserver

Types

type AllMatcher

type AllMatcher struct{ BaseMatcher }

func (*AllMatcher) Equals

func (a *AllMatcher) Equals(m Matcher) bool

func (*AllMatcher) Matches

func (a *AllMatcher) Matches(e Entity) bool

func (*AllMatcher) String

func (a *AllMatcher) String() string

type AnyMatcher

type AnyMatcher struct{ BaseMatcher }

func (*AnyMatcher) Equals

func (a *AnyMatcher) Equals(m Matcher) bool

func (*AnyMatcher) Matches

func (a *AnyMatcher) Matches(e Entity) bool

func (*AnyMatcher) String

func (a *AnyMatcher) String() string

type BaseMatcher

type BaseMatcher struct {
	// contains filtered or unexported fields
}

func (*BaseMatcher) ComponentTypes

func (b *BaseMatcher) ComponentTypes() []ComponentType

func (*BaseMatcher) Hash

func (b *BaseMatcher) Hash() MatcherHash

type Component

type Component interface {
	Type() ComponentType
}

func NewComponentA

func NewComponentA(value int) Component

func NewComponentB

func NewComponentB(value float32) Component

type ComponentCallback

type ComponentCallback func(Entity, Component)

type ComponentEvent

type ComponentEvent uint
const (
	ComponentAdded ComponentEvent = iota
	ComponentReplaced
	ComponentWillBeRemoved
	ComponentRemoved
)

type ComponentType

type ComponentType uint16
const (
	ComponentA ComponentType = iota
	ComponentB
	ComponentC
	ComponentD
	ComponentE
	ComponentF
	NumComponents
)

Component index 组件--也就相当于数据块 会根据类型经行操作

func (ComponentType) ComponentTypes

func (c ComponentType) ComponentTypes() []ComponentType

func (ComponentType) Equals

func (c ComponentType) Equals(m Matcher) bool

func (ComponentType) Hash

func (c ComponentType) Hash() MatcherHash

func (ComponentType) Matches

func (c ComponentType) Matches(e Entity) bool

func (ComponentType) String

func (c ComponentType) String() string

type ComponentsByType

type ComponentsByType []Component

func (ComponentsByType) Len

func (t ComponentsByType) Len() int

func (ComponentsByType) Less

func (t ComponentsByType) Less(i, j int) bool

func (ComponentsByType) Swap

func (t ComponentsByType) Swap(i, j int)

type Entity

type Entity interface {
	AddComponent(cs ...Component) error
	ReplaceComponent(cs ...Component)
	WillRemoveComponent(ts ...ComponentType) error
	RemoveComponent(ts ...ComponentType) error
	RemoveAllComponents()
	RemoveAllCallbacks()
	AddCallback(ev ComponentEvent, cb ComponentCallback)
	HasCallbacks() bool

	ID() EntityID
	HasComponent(ts ...ComponentType) bool
	HasAnyComponent(ts ...ComponentType) bool
	Component(t ComponentType) (Component, error)
	Components() []Component
	ComponentIndices() []ComponentType
}

实体的接口数据

func NewEntity

func NewEntity(id int) Entity

申请一个实体

type EntityID

type EntityID uint

实体的ID信息

type Group

type Group interface {
	Entities() []Entity
	HandleEntity(e Entity)
	UpdateEntity(e Entity)
	WillRemoveEntity(e Entity)
	Matches(e Entity) bool
	ContainsEntity(e Entity) bool
	AddCallback(e GroupEvent, c GroupCallback)
}

func NewGroup

func NewGroup(matcher Matcher) Group

type GroupCallback

type GroupCallback func(Group, Entity)

type GroupEvent

type GroupEvent uint
const (
	EntityAdded GroupEvent = iota
	EntityWillBeRemoved
	EntityRemoved
)

type GroupObserver

type GroupObserver interface {
	CollectedEntities() []Entity
	Activate()
	Deactivate()
	ClearCollectedEntities()
}

type Matcher

type Matcher interface {
	Matches(entity Entity) bool
	Hash() MatcherHash
	ComponentTypes() []ComponentType
	Equals(m Matcher) bool
	String() string
}

func AllOf

func AllOf(ms ...Matcher) Matcher

func AnyOf

func AnyOf(ms ...Matcher) Matcher

func NoneOf

func NoneOf(ms ...Matcher) Matcher

type MatcherHash

type MatcherHash uint

func Hash

func Hash(factor uint, ms ...Matcher) MatcherHash

type NoneMatcher

type NoneMatcher struct{ BaseMatcher }

func (*NoneMatcher) Equals

func (n *NoneMatcher) Equals(m Matcher) bool

func (*NoneMatcher) Matches

func (n *NoneMatcher) Matches(e Entity) bool

func (*NoneMatcher) String

func (n *NoneMatcher) String() string

type ObserverEvent

type ObserverEvent uint
const (
	ObserverEntityAdded ObserverEvent = iota
	ObserverEntityRemoved
	ObserverEntityAddedOrRemoved
)

type Pool

type Pool interface {
	CreateEntity(cs ...Component) Entity
	Entities() []Entity
	Count() int
	HasEntity(e Entity) bool
	DestroyEntity(e Entity)
	DestroyAllEntities()
	Group(m Matcher) Group
}

func NewPool

func NewPool(componentsLength ComponentType, index int) Pool

type TypesByType

type TypesByType []ComponentType

func (TypesByType) Len

func (ts TypesByType) Len() int

func (TypesByType) Less

func (ts TypesByType) Less(i, j int) bool

func (TypesByType) Swap

func (ts TypesByType) Swap(i, j int)

Jump to

Keyboard shortcuts

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