Entitas Redux
JCMG.EntitasRedux.Context< TEntity > Class Template Reference

A context manages the lifecycle of entities and groups. You can create and destroy entities and get groups of entities. The preferred way to create a context is to use the generated methods from the code generator, e.g. var context = new GameContext(); More...

Inheritance diagram for JCMG.EntitasRedux.Context< TEntity >:
JCMG.EntitasRedux.IContext< TEntity >

Public Member Functions

 Context (int totalComponents, Func< TEntity > entityFactory)
 The preferred way to create a context is to use the generated methods from the code generator, e.g. var context = new GameContext(); More...
 
 Context (int totalComponents, int startCreationIndex, ContextInfo contextInfo, Func< IEntity, IAERC > aercFactory, Func< TEntity > entityFactory)
 The preferred way to create a context is to use the generated methods from the code generator, e.g. var context = new GameContext(); More...
 
override string ToString ()
 
TEntity CreateEntity ()
 Creates a new entity or gets a reusable entity from the internal ObjectPool for entities. More...
 
void DestroyAllEntities ()
 Destroys all entities in the context. Throws an exception if there are still retained entities. More...
 
bool HasEntity (TEntity entity)
 Determines whether the context has the specified entity. More...
 
TEntity[] GetEntities ()
 Returns all entities which are currently in the context. More...
 
IGroup< TEntity > GetGroup (IMatcher< TEntity > matcher)
 Returns a group for the specified matcher. Calling context.GetGroup(matcher) with the same matcher will always return the same instance of the group. More...
 
void AddEntityIndex (IEntityIndex entityIndex)
 Adds the IEntityIndex for the specified name. There can only be one IEntityIndex per name. More...
 
IEntityIndex GetEntityIndex (string name)
 Gets the IEntityIndex for the specified name. More...
 
void ResetCreationIndex ()
 Resets the creationIndex back to 0. More...
 
void ClearComponentPool (int index)
 Clears the componentPool at the specified index. More...
 
void ClearComponentPools ()
 Clears all componentPools. More...
 
void Reset ()
 Resets the context (destroys all entities and resets creationIndex back to 0). More...
 
void RemoveAllEventHandlers ()
 Removes all event handlers OnEntityCreated, OnEntityWillBeDestroyed, OnEntityDestroyed and OnGroupCreated More...
 

Public Attributes

int TotalComponents => _totalComponents
 The total amount of components an entity can possibly have. This value is generated by the code generator, e.g ComponentLookup.TotalComponents. More...
 
Stack< IComponent >[] ComponentPools => _componentPools
 Returns all componentPools. componentPools is used to reuse removed components. Removed components will be pushed to the componentPool. Use entity.CreateComponent(index, type) to get a new or reusable component from the componentPool. More...
 
ContextInfo ContextInfo => _contextInfo
 The contextInfo contains information about the context. It's used to provide better error messages. More...
 
int Count => _entities.Count
 Returns the number of entities in the context. More...
 
int ReusableEntitiesCount => _reusableEntities.Count
 Returns the number of entities in the internal ObjectPool for entities which can be reused. More...
 
int RetainedEntitiesCount => _retainedEntities.Count
 Returns the number of entities that are currently retained by other objects (e.g. Group, Collector, ReactiveSystem). More...
 

Events

ContextEntityChanged OnEntityCreated
 Occurs when an entity gets created. More...
 
ContextEntityChanged OnEntityWillBeDestroyed
 Occurs when an entity will be destroyed. More...
 
ContextEntityChanged OnEntityDestroyed
 Occurs when an entity got destroyed. More...
 
ContextGroupChanged OnGroupCreated
 Occurs when a group gets created for the first time. More...
 

Detailed Description

A context manages the lifecycle of entities and groups. You can create and destroy entities and get groups of entities. The preferred way to create a context is to use the generated methods from the code generator, e.g. var context = new GameContext();

Template Parameters
TEntity
Type Constraints
TEntity :class 
TEntity :IEntity 

Definition at line 39 of file Context.cs.

Constructor & Destructor Documentation

◆ Context() [1/2]

JCMG.EntitasRedux.Context< TEntity >.Context ( int  totalComponents,
Func< TEntity >  entityFactory 
)

The preferred way to create a context is to use the generated methods from the code generator, e.g. var context = new GameContext();

Parameters
totalComponents
entityFactory

Definition at line 78 of file Context.cs.

◆ Context() [2/2]

JCMG.EntitasRedux.Context< TEntity >.Context ( int  totalComponents,
int  startCreationIndex,
ContextInfo  contextInfo,
Func< IEntity, IAERC aercFactory,
Func< TEntity >  entityFactory 
)

The preferred way to create a context is to use the generated methods from the code generator, e.g. var context = new GameContext();

Parameters
totalComponents
startCreationIndex
contextInfo
aercFactory
entityFactory

Definition at line 96 of file Context.cs.

Member Function Documentation

◆ AddEntityIndex()

void JCMG.EntitasRedux.Context< TEntity >.AddEntityIndex ( IEntityIndex  entityIndex)

Adds the IEntityIndex for the specified name. There can only be one IEntityIndex per name.

Parameters
entityIndex

Definition at line 431 of file Context.cs.

◆ ClearComponentPool()

void JCMG.EntitasRedux.Context< TEntity >.ClearComponentPool ( int  index)

Clears the componentPool at the specified index.

Parameters
index

Definition at line 469 of file Context.cs.

◆ ClearComponentPools()

void JCMG.EntitasRedux.Context< TEntity >.ClearComponentPools ( )

Clears all componentPools.

Definition at line 478 of file Context.cs.

◆ CreateEntity()

TEntity JCMG.EntitasRedux.Context< TEntity >.CreateEntity ( )

Creates a new entity or gets a reusable entity from the internal ObjectPool for entities.

Returns

Definition at line 308 of file Context.cs.

◆ DestroyAllEntities()

void JCMG.EntitasRedux.Context< TEntity >.DestroyAllEntities ( )

Destroys all entities in the context. Throws an exception if there are still retained entities.

Definition at line 347 of file Context.cs.

◆ GetEntities()

TEntity [] JCMG.EntitasRedux.Context< TEntity >.GetEntities ( )

Returns all entities which are currently in the context.

Returns

Definition at line 377 of file Context.cs.

◆ GetEntityIndex()

IEntityIndex JCMG.EntitasRedux.Context< TEntity >.GetEntityIndex ( string  name)

Gets the IEntityIndex for the specified name.

Parameters
name
Returns

Definition at line 446 of file Context.cs.

◆ GetGroup()

IGroup<TEntity> JCMG.EntitasRedux.Context< TEntity >.GetGroup ( IMatcher< TEntity >  matcher)

Returns a group for the specified matcher. Calling context.GetGroup(matcher) with the same matcher will always return the same instance of the group.

Parameters
matcher
Returns

Definition at line 395 of file Context.cs.

◆ HasEntity()

bool JCMG.EntitasRedux.Context< TEntity >.HasEntity ( TEntity  entity)

Determines whether the context has the specified entity.

Parameters
entity
Returns

Definition at line 368 of file Context.cs.

◆ RemoveAllEventHandlers()

void JCMG.EntitasRedux.Context< TEntity >.RemoveAllEventHandlers ( )

Removes all event handlers OnEntityCreated, OnEntityWillBeDestroyed, OnEntityDestroyed and OnGroupCreated

Definition at line 501 of file Context.cs.

◆ Reset()

void JCMG.EntitasRedux.Context< TEntity >.Reset ( )

Resets the context (destroys all entities and resets creationIndex back to 0).

Definition at line 490 of file Context.cs.

◆ ResetCreationIndex()

void JCMG.EntitasRedux.Context< TEntity >.ResetCreationIndex ( )

Resets the creationIndex back to 0.

Definition at line 460 of file Context.cs.

◆ ToString()

override string JCMG.EntitasRedux.Context< TEntity >.ToString ( )

Definition at line 144 of file Context.cs.

Member Data Documentation

◆ ComponentPools

Stack<IComponent> [] JCMG.EntitasRedux.Context< TEntity >.ComponentPools => _componentPools

Returns all componentPools. componentPools is used to reuse removed components. Removed components will be pushed to the componentPool. Use entity.CreateComponent(index, type) to get a new or reusable component from the componentPool.

Definition at line 278 of file Context.cs.

◆ ContextInfo

The contextInfo contains information about the context. It's used to provide better error messages.

Definition at line 284 of file Context.cs.

◆ Count

int JCMG.EntitasRedux.Context< TEntity >.Count => _entities.Count

Returns the number of entities in the context.

Definition at line 289 of file Context.cs.

◆ RetainedEntitiesCount

int JCMG.EntitasRedux.Context< TEntity >.RetainedEntitiesCount => _retainedEntities.Count

Returns the number of entities that are currently retained by other objects (e.g. Group, Collector, ReactiveSystem).

Definition at line 301 of file Context.cs.

◆ ReusableEntitiesCount

int JCMG.EntitasRedux.Context< TEntity >.ReusableEntitiesCount => _reusableEntities.Count

Returns the number of entities in the internal ObjectPool for entities which can be reused.

Definition at line 295 of file Context.cs.

◆ TotalComponents

int JCMG.EntitasRedux.Context< TEntity >.TotalComponents => _totalComponents

The total amount of components an entity can possibly have. This value is generated by the code generator, e.g ComponentLookup.TotalComponents.

Definition at line 269 of file Context.cs.

Event Documentation

◆ OnEntityCreated

ContextEntityChanged JCMG.EntitasRedux.Context< TEntity >.OnEntityCreated

Occurs when an entity gets created.

Definition at line 248 of file Context.cs.

◆ OnEntityDestroyed

ContextEntityChanged JCMG.EntitasRedux.Context< TEntity >.OnEntityDestroyed

Occurs when an entity got destroyed.

Definition at line 258 of file Context.cs.

◆ OnEntityWillBeDestroyed

ContextEntityChanged JCMG.EntitasRedux.Context< TEntity >.OnEntityWillBeDestroyed

Occurs when an entity will be destroyed.

Definition at line 253 of file Context.cs.

◆ OnGroupCreated

Occurs when a group gets created for the first time.

Definition at line 263 of file Context.cs.


The documentation for this class was generated from the following file: