Documentation
¶
Index ¶
- func Get[T any](e *ECS, entityId int) (*T, bool)
- func Get2[A, B any](e *ECS, entityId int) (*A, *B, bool)
- func Get3[A, B, C any](e *ECS, entityId int) (*A, *B, *C, bool)
- func Init[A any](e *ECS, entityId int, a A)
- func Init2[A, B any](e *ECS, entityId int, a A, b B)
- func Init3[A, B, C any](e *ECS, entityId int, a A, b B, c C)
- func Init4[A, B, C, D any](e *ECS, entityId int, a A, b B, c C, d D)
- func Init5[A, B, C, D, E any](ecs *ECS, entityId int, a A, b B, c C, d D, e E)
- func Init6[A, B, C, D, E, F any](ecs *ECS, entityId int, a A, b B, c C, d D, e E, f F)
- func Init7[A, B, C, D, E, F, G any](ecs *ECS, entityId int, a A, b B, c C, d D, e E, f F, g G)
- func Init8[A, B, C, D, E, F, G, H any](ecs *ECS, entityId int, a A, b B, c C, d D, e E, f F, g G, h H)
- func Iterate[A any](e *ECS) *sparseset.Iterator[A]
- func IterateAny[T any](e *ECS) (int, *T, bool)
- func Join[A, B any](e *ECS) *sparseset.JoinIterator[A, B]
- func Join3[A, B, C any](e *ECS) *sparseset.Join3Iterator[A, B, C]
- func Join3Any[A, B, C any](e *ECS) (int, *A, *B, *C, bool)
- func Join4[A, B, C, D any](e *ECS) *sparseset.Join4Iterator[A, B, C, D]
- func JoinAny[A, B any](e *ECS) (int, *A, *B, bool)
- func Set[A any](e *ECS, entityId int, a A)
- func Set2[A, B any](ecs *ECS, entityId int, a A, b B)
- func Set3[A, B, C any](ecs *ECS, entityId int, a A, b B, c C)
- func Set4[A, B, C, D any](ecs *ECS, entityId int, a A, b B, c C, d D)
- func Set5[A, B, C, D, E any](ecs *ECS, entityId int, a A, b B, c C, d D, e E)
- func Set6[A, B, C, D, E, F any](ecs *ECS, entityId int, a A, b B, c C, d D, e E, f F)
- func Set7[A, B, C, D, E, F, G any](ecs *ECS, entityId int, a A, b B, c C, d D, e E, f F, g G)
- func Set8[A, B, C, D, E, F, G, H any](ecs *ECS, entityId int, a A, b B, c C, d D, e E, f F, g G, h H)
- func SortStableFunc[T any](e *ECS, compare func(int, *T, int, *T) int)
- func Unset[T any](e *ECS, entityId int)
- type ECS
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Returns a component of the given type for an entity given its ID. Returns a pointer to the component and true if said entity exists, otherwise it returns false.
The pointer is valid as long as the ECS is not modified (see ECS type)
func Get2 ¶
Same as 'Get' for 2 component types. Returns true only if the entity has all types.
The pointers are valid as long as the ECS is not modified (see ECS type)
func Get3 ¶
Same as 'Get' for 3 component types. Returns true only if the entity has all types.
The pointers are valid as long as the ECS is not modified (see ECS type)
func Init ¶
Initializes an entity and its component. If the entity already exists, it is first removed and then re-added. If the intention is not to initialize the entity, then use 'Set' instead.
func Iterate ¶
Returns an iterator that iterates all entities that have the given component type.
for iterator := ecs.Iterate[MyComponent](e); ; { c, ok := e.Next() if !ok { break } // Do something with 'c'. }
The pointer returned by the iterator is valid as long as the ECS is not modified (see ECS type)
func IterateAny ¶
Returns any entity that has the given component. Returns the entity ID, the pointer to the component and true if said entity exists, otherwise it returns false.
The pointer is valid as long as the ECS is not modified (see ECS type)
func Join ¶
Returns an iterator that iterates all entities that have all component types.
for iterator := ecs.Join[MyComponent, OtherComponent](e); ; { c1, c2, ok := e.Next() if !ok { break } // Do something with 'c1' and 'c2'. }
The pointers returned by the iterator are valid as long as the ECS is not modified (see ECS type)
func JoinAny ¶
Returns any entity that has all the given components. Returns the entity ID, the pointers to the components and true if said entitiy exists, otherwise it returns false. The pointers are valid as long as the ECS is not modified.
The pointers are valid as long as the ECS is not modified (see ECS type)
func Set8 ¶
func Set8[A, B, C, D, E, F, G, H any](ecs *ECS, entityId int, a A, b B, c C, d D, e E, f F, g G, h H)
Same as 'Set' for 8 component types.
func SortStableFunc ¶
Sorts the components using a stable sort function according to the given comparator function. The comparator function uses the same semantics are 'cmp.Compare' from the http://pkg.go.dev/cmp package.
Types ¶
type ECS ¶
type ECS struct {
// contains filtered or unexported fields
}
ECS is the Entity Component System.
Several functions / methods return pointers to components. These pointers are only valid as long as the ECS is not modified by adding or removing entities. If adding or removing entities, the ECS's internal memory may reallocated, thus invaliding those pointers. For this reason, pointers to components obtained prior to adding or removing entities should not be accessed if the ECS is modified in this way. Also, it's recommended not to store pointers to components inside data types for later use because if they become invalidated it's easy to forget and access them later.