EntityRegistry
in package
implements
EntitiesInterface
Table of Contents
Interfaces
- EntitiesInterface
- An entity is nothing more then just a number on which components are attached indexed to.
Properties
- $components : array<class-string, array<int, object>>
- An array holding the actual components
- $entityComponents : array<int, array<class-string, object>>
- Similar to $components but holds the component references per entity
- $entityPointer : int
- The current entity pointer aka the next entity ID
- $freelist : array<string|int, int>
- An array of entity ids that have been destroyed and can be used again.
- $singletonComponents : array<class-string, object>
- An array singleton components
Methods
- attach() : T
- Attaches the given component to the given entity
- components() : array<class-string, object>
- Returns an array of all components for the given entity
- create() : int
- Creates an entity and returns its ID
- deserialize() : void
- Deserializes the registry from a string
- destroy() : void
- Destroyes an entity by its ID
- detach() : void
- Dettaches a component by class its class name
- detachAll() : void
- Dettaches all components from the given entity
- first() : T|null
- Returns the first component of the given class name
- firstWith() : int|null
- Returns the first entity that has the given component
- get() : T
- Returns a component for the given entity ! Warning: This method does no error checking and assumes you made sure the component needs to actually exist!
- getSingleton() : T
- Returns a singleton component from the entity registry
- has() : bool
- Returns boolean if an entity has a component
- hasSingleton() : bool
- Returns boolean if a singleton component exists
- list() : array<string|int, int>
- listComponents() : array<int, object>
- Returns an array of components for the given component class name.
- listWith() : array<string|int, int>
- registerComponent() : void
- Prepares internal data structures for the given component
- removeSingleton() : void
- Removes a singleton component from the entity registry
- serialize() : string
- Serializes the registry to a string
- setSingleton() : T
- Stores a singleton component in the entity registy
- tryGet() : T|null
- Returns a component for the given entity or null if it does not exist
- valid() : bool
- Returns boolean if the given entity ID is a valid one
- view() : Generator<int, T>
- Iterates over all available components of the given class name
- viewWith() : Generator<int, array<string|int, object>>
- Iterates over all entities having the given components and will pass the components as arguments to the callback
Properties
$components
An array holding the actual components
private
array<class-string, array<int, object>>
$components
= []
$entityComponents
Similar to $components but holds the component references per entity
private
array<int, array<class-string, object>>
$entityComponents
= []
$entityPointer
The current entity pointer aka the next entity ID
private
int
$entityPointer
= 0
$freelist
An array of entity ids that have been destroyed and can be used again.
private
array<string|int, int>
$freelist
= []
$singletonComponents
An array singleton components
private
array<class-string, object>
$singletonComponents
= []
Methods
attach()
Attaches the given component to the given entity
public
attach(int $entity, T $component) : T
Parameters
- $entity : int
-
The entitiy ID of the component to be attached
- $component : T
Tags
Return values
Tcomponents()
Returns an array of all components for the given entity
public
components(int $entity) : array<class-string, object>
Parameters
- $entity : int
-
The entitiy ID of the component
Return values
array<class-string, object>create()
Creates an entity and returns its ID
public
create() : int
Return values
intdeserialize()
Deserializes the registry from a string
public
deserialize(string $buffer) : void
Parameters
- $buffer : string
destroy()
Destroyes an entity by its ID
public
destroy(int $entity) : void
Parameters
- $entity : int
detach()
Dettaches a component by class its class name
public
detach(int $entity, class-string $componentClassName) : void
Parameters
- $entity : int
-
The entitiy ID of the component to be detached
- $componentClassName : class-string
detachAll()
Dettaches all components from the given entity
public
detachAll(int $entity) : void
Parameters
- $entity : int
-
The entitiy ID of the component to be detached
first()
Returns the first component of the given class name
public
first(T> $componentClassName) : T|null
Parameters
- $componentClassName : T>
Tags
Return values
T|nullfirstWith()
Returns the first entity that has the given component
public
firstWith(class-string $componentClassName) : int|null
Parameters
- $componentClassName : class-string
Return values
int|nullget()
Returns a component for the given entity ! Warning: This method does no error checking and assumes you made sure the component needs to actually exist!
public
get(int $entity, T> $componentClassName) : T
Parameters
- $entity : int
-
The entitiy ID of the component to be retrieved
- $componentClassName : T>
Tags
Return values
TgetSingleton()
Returns a singleton component from the entity registry
public
getSingleton(T> $componentClassName) : T
Parameters
- $componentClassName : T>
Tags
Return values
Thas()
Returns boolean if an entity has a component
public
has(int $entity, class-string $componentClassName) : bool
Parameters
- $entity : int
-
The entitiy ID of the component
- $componentClassName : class-string
Return values
boolhasSingleton()
Returns boolean if a singleton component exists
public
hasSingleton(T> $componentClassName) : bool
Parameters
- $componentClassName : T>
Tags
Return values
boollist()
public
list(class-string $componentClassName) : array<string|int, int>
Parameters
- $componentClassName : class-string
Return values
array<string|int, int>listComponents()
Returns an array of components for the given component class name.
public
listComponents(class-string $componentClassName) : array<int, object>
In most cases you want to use the view method instead.
Parameters
- $componentClassName : class-string
Return values
array<int, object>listWith()
public
listWith(class-string ...$componentClassNames) : array<string|int, int>
Parameters
- $componentClassNames : class-string
Return values
array<string|int, int>registerComponent()
Prepares internal data structures for the given component
public
registerComponent(class-string $componentClassName) : void
Parameters
- $componentClassName : class-string
removeSingleton()
Removes a singleton component from the entity registry
public
removeSingleton(T> $componentClassName) : void
Parameters
- $componentClassName : T>
Tags
serialize()
Serializes the registry to a string
public
serialize(array<string|int, class-string> $componentNames[, string|null $requiredComponent = null ]) : string
Parameters
- $componentNames : array<string|int, class-string>
-
The component names to be serialized
- $requiredComponent : string|null = null
-
The component name that is required to be present in the entity to be serialized
Return values
stringsetSingleton()
Stores a singleton component in the entity registy
public
setSingleton(T $component) : T
Parameters
- $component : T
Tags
Return values
TtryGet()
Returns a component for the given entity or null if it does not exist
public
tryGet(int $entity, T> $componentClassName) : T|null
Parameters
- $entity : int
-
The entitiy ID of the component to be retrieved
- $componentClassName : T>
Tags
Return values
T|nullvalid()
Returns boolean if the given entity ID is a valid one
public
valid(int $entity) : bool
Parameters
- $entity : int
Return values
boolview()
Iterates over all available components of the given class name
public
view(T> $componentClassName) : Generator<int, T>
Parameters
- $componentClassName : T>
Tags
Return values
Generator<int, T>viewWith()
Iterates over all entities having the given components and will pass the components as arguments to the callback
public
viewWith(class-string ...$componentClassNames) : Generator<int, array<string|int, object>>
Parameters
- $componentClassNames : class-string