Documentation
¶
Index ¶
- Constants
- Variables
- type ComponentSet
- type Condition
- type DeleteCallback
- type DeleteSubscription
- type DenseComponentSet
- type Engine
- type EntityID
- type Option
- type Result
- type Scene
- func (s *Scene) CreateEntity() EntityID
- func (s *Scene) Delete()
- func (s *Scene) DeleteEntity(entityID EntityID)
- func (s *Scene) HasEntity(entityID EntityID) bool
- func (s *Scene) MaxEntityCount() int
- func (s *Scene) Purge()
- func (s *Scene) Query(conditions ...Condition) *Result
- func (s *Scene) SubscribeDelete(callback DeleteCallback) *DeleteSubscription
- type SparseComponentSet
- type TinyComponentSet
Constants ¶
const MaxComponentCount = 64
MaxComponentCount returns the maximum number of components that can be created per scene.
Unlike the max entity count, this number is not configurable.
Variables ¶
var NilEntityID = EntityID{}
NilEntityID represents an invalid entity handle.
Functions ¶
This section is empty.
Types ¶
type ComponentSet ¶ added in v0.23.0
type ComponentSet[T any] interface { Set(entityID EntityID, value T) Unset(entityID EntityID) Ref(entityID EntityID) *T Mask() componentMask }
ComponentSet represents a storage for components of the same type.
type Condition ¶ added in v0.23.0
type Condition struct {
// contains filtered or unexported fields
}
Condition represents a query condition that needs to be satisfied for an entity to be returned.
func HasComponent ¶ added in v0.23.0
func HasComponent[T any](set ComponentSet[T]) Condition
HasComponent returns a query condition that requires an entity to have a certain component.
func IsHealthy ¶ added in v0.23.0
func IsHealthy() Condition
IsHealthy returns a query condition that requires an entity to not be pending deletion.
func IsPendingDeletion ¶ added in v0.23.0
func IsPendingDeletion() Condition
IsPendingDeletion returns a query condition that requires an entity to have been marked for deletion.
func LacksComponent ¶ added in v0.23.0
func LacksComponent[T any](set ComponentSet[T]) Condition
LacksComponent returns a query condition that requires an entity to not have a certain component.
type DeleteCallback ¶ added in v0.23.0
type DeleteCallback func(EntityID)
DeleteCallback is a mechanism to receive deletion notifications.
type DeleteSubscription ¶ added in v0.23.0
type DeleteSubscription = observer.Subscription[DeleteCallback]
DeleteSubscription represents a notification subscription for deletions.
type DenseComponentSet ¶ added in v0.23.0
type DenseComponentSet[T any] struct { // contains filtered or unexported fields }
func NewDenseComponentSet ¶ added in v0.23.0
func NewDenseComponentSet[T any](scene *Scene) *DenseComponentSet[T]
NewDenseComponentSet returns a ComponentSet implementation that has pre-allocated storage for the maximum number of entities.
While this implementation is the fastest available, it is also the most memory intensive and should be used only for components that are very common and are likely to be attached to the majority of entities.
func (*DenseComponentSet[T]) Mask ¶ added in v0.23.0
func (s *DenseComponentSet[T]) Mask() componentMask
func (*DenseComponentSet[T]) Ref ¶ added in v0.23.0
func (s *DenseComponentSet[T]) Ref(entityID EntityID) *T
func (*DenseComponentSet[T]) Set ¶ added in v0.23.0
func (s *DenseComponentSet[T]) Set(entityID EntityID, value T)
func (*DenseComponentSet[T]) Unset ¶ added in v0.23.0
func (s *DenseComponentSet[T]) Unset(entityID EntityID)
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the entrypoint to working with an Entity-Component System framework.
func (*Engine) CreateScene ¶
CreateScene creates a new Scene instance. Entities within a scene are isolated from entities in other scenes.
type EntityID ¶ added in v0.23.0
type EntityID struct {
// contains filtered or unexported fields
}
EntityID represents a handle to an ECS entity. The handle may be invalid if the entity has since been deleted.
type Option ¶ added in v0.20.0
type Option func(*config)
Option is a configuration function that can be used to customize the behavior of the ECS engine.
func WithMaxEntityCount ¶ added in v0.23.0
WithMaxEntityCount controls the maximum number of entities that a scene will need to manage.
Keeping this value small could reduce memory usage and increase performance.
By default it is equal to 1048576 (1024x1024), which is also the maximum that this can be set to.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result represents the outcome of a query operation.
Make sure to call Release once you are done with it so that it can be reused in future searches.
func (*Result) Each ¶ added in v0.23.0
Each invokes the callback function for each entity in this result set.
While less elegant than Iter, it does not incur unnecessary allocations.
type Scene ¶
type Scene struct {
// contains filtered or unexported fields
}
Scene represents a collection of ECS entities.
func (*Scene) CreateEntity ¶
CreateEntity creates a new entity in this scene.
func (*Scene) Delete ¶
func (s *Scene) Delete()
Delete removes this scene and releases any associated resources.
func (*Scene) DeleteEntity ¶ added in v0.23.0
DeleteEntity marks an entity for deletion.
func (*Scene) HasEntity ¶ added in v0.23.0
HasEntity returns whether the specified entity is still valid and part of this scene (i.e. it has not been marked for deletion and purged).
func (*Scene) MaxEntityCount ¶ added in v0.23.0
MaxEntityCount returns the maximum number of entities that can be managed by this scene at any given point in time (this includes entities marked for deletion that have not been purged yet).
func (*Scene) Purge ¶ added in v0.23.0
func (s *Scene) Purge()
Purge removes any entities that have been marked for deletion.
All delete subscriptions will be notified at this point in time.
func (*Scene) Query ¶ added in v0.23.0
Query searches for entities that satisfy all specified conditions.
func (*Scene) SubscribeDelete ¶ added in v0.23.0
func (s *Scene) SubscribeDelete(callback DeleteCallback) *DeleteSubscription
SubscribeDelete adds a callback to be executed before an entity is fully deleted.
type SparseComponentSet ¶ added in v0.23.0
type SparseComponentSet[T any] struct { // contains filtered or unexported fields }
func NewSparseComponentSet ¶ added in v0.23.0
func NewSparseComponentSet[T any](scene *Scene) *SparseComponentSet[T]
NewSparseComponentSet returns a ComponentSet implementation that allocates storage as needed.
This implementation is more memory-friendly but this comes at a performance cost. It should be used only for component types that are occasionally attached to an entity.
func (*SparseComponentSet[T]) Mask ¶ added in v0.23.0
func (s *SparseComponentSet[T]) Mask() componentMask
func (*SparseComponentSet[T]) Ref ¶ added in v0.23.0
func (s *SparseComponentSet[T]) Ref(entityID EntityID) *T
func (*SparseComponentSet[T]) Set ¶ added in v0.23.0
func (s *SparseComponentSet[T]) Set(entityID EntityID, value T)
func (*SparseComponentSet[T]) Unset ¶ added in v0.23.0
func (s *SparseComponentSet[T]) Unset(entityID EntityID)
type TinyComponentSet ¶ added in v0.23.0
type TinyComponentSet[T any] struct { // contains filtered or unexported fields }
func NewTinyComponentSet ¶ added in v0.23.0
func NewTinyComponentSet[T any](scene *Scene) *TinyComponentSet[T]
NewTinyComponentSet returns a ComponentSet implementation that allocates very little storage for components.
This implementation is the most memory-friendly but this comes at a huge performance cost. It should be used only for component types that are rerely ever attached to an entity.
func (*TinyComponentSet[T]) Mask ¶ added in v0.23.0
func (s *TinyComponentSet[T]) Mask() componentMask
func (*TinyComponentSet[T]) Ref ¶ added in v0.23.0
func (s *TinyComponentSet[T]) Ref(entityID EntityID) *T
func (*TinyComponentSet[T]) Set ¶ added in v0.23.0
func (s *TinyComponentSet[T]) Set(entityID EntityID, value T)
func (*TinyComponentSet[T]) Unset ¶ added in v0.23.0
func (s *TinyComponentSet[T]) Unset(entityID EntityID)