Class: System<AspectT>

Abstract base class for entity sub-systems.

Type parameters

Name
AspectT

Hierarchy

Constructors

constructor

new System<AspectT>(name): System<AspectT>

Create a new entity sub-system.

Type parameters

Name
AspectT

Parameters

Name Type Description
name string Name of the system for debugging purposes

Returns

System<AspectT>

Properties

aspects

Protected aspects: Map<string, AspectT>


name

Readonly name: string

Name of the system for debugging purposes.

Methods

beginFrame

beginFrame(dt, engine, steps): void

Overridable method called in the beginning of each frame.

Parameters

Name Type Description
dt number Time elapsed since last frame
engine Engine Engine instance
steps number Total number of steps for this frame

Returns

void


destroy

destroy(): void

Overridable method called when the engine is destroyed. Call super to clear the protected aspects map.

Returns

void


endFrame

endFrame(dt, engine, steps): void

Overridable method called in the end of each frame.

Parameters

Name Type Description
dt number Time elapsed since last frame
engine Engine Engine instance
steps number Total number of steps for this frame

Returns

void


getAspect

getAspect<T>(type, entity): undefined | T

Get typed aspect bound to the entity. If the entity has an aspect in the system but it is not of the specified type the return value will be undefined.

Type parameters

Name
T

Parameters

Name Type Description
type Type<T> Type of the aspect
entity string Entity to get the aspect from

Returns

undefined | T

getAspect(entity): undefined | AspectT

Get the aspect bound to the entity.

Parameters

Name Type Description
entity string Entity to get the aspect from

Returns

undefined | AspectT


getAspects

getAspects(): Map<string, AspectT>

Get access to the aspect map for iterating entities.

Do not modify the returned map directly!

Always use setAspect and removeAspect to modify the aspect map to ensure that the overloaded versions of these functions are called properly. Same warning applies for direct access to the protected this.aspects in the derived sub-systems.

Returns

Map<string, AspectT>


getEntities

getEntities(): string[]

Get a list of all entities that have aspects in this system.

Returns

string[]

Deprecated

This is a very unoptimal way to access the aspects. You should use getAspects (or this.aspects inside System scope) to access the entities.


removeAspect

removeAspect(entity): void

Remove the aspect bound to the entity.

Parameters

Name Type Description
entity string Entity to remove the aspect from

Returns

void


requireAspect

requireAspect<T>(type, entity): T

Get typed aspect bound to the entity. If the aspect is not found or if the entity has an aspect in the system but it is not of the specified type an exception is thrown.

Type parameters

Name
T

Parameters

Name Type Description
type Type<T> Type of the aspect
entity string Entity to get the aspect from

Returns

T

requireAspect(entity): AspectT

Get the aspect bound to the entity. If the aspect is not found an exception is thrown.

Parameters

Name Type Description
entity string Entity to get the aspect from

Returns

AspectT


setAspect

setAspect(entity, aspect): void

Set the entity’s aspect in this sub-system. Usually the aspect is created with new AspectT(...) and then passed to setAspect.

Parameters

Name Type Description
entity string Entity to set the aspect for
aspect AspectT The aspect to set

Returns

void


step

step(dt, engine, step, steps): void

Overridable method called n times each frame depending on how much time has elapsed since the last frame.

Parameters

Name Type Description
dt number The fixed time step
engine Engine Engine instance
step number Step counter for the frame
steps number Total number of steps for this frame

Returns

void