System

System

Creates a new System

Base class for all entity systems


  • interests = null -> listen to all entities
  • interests = [] -> don't listen to any entities
  • interests = ['coolComponent', 'testComponent'] -> listen to entities that contains at minimum 'coolComponent' and 'testComponent'

Constructor

new System(type, interestsopt)

Initialize a new System object.

Parameters:
Name Type Attributes Description
type string

System type name as a string

interests Array.<String> <optional>

Array of component types in which
this system is interested. Entities with all of these components will
automatically be associated with the system. The default is [], which
will prevent any entities from being automatically associated with the
system. A value of null causes all entities to be associated with the
system.

Properties:
Name Type Description
type string

System type

interests Array.<String>

Array of component types this system is interested in

Members

(static) PRIORITY_AFTER_DEFAULT :number

A System#priority value that causes the system to run after the
default priority system on each update.

(static) PRIORITY_AFTER_MACHINES :number

A System#priority value that causes the system to run after the
state machine system on each update.

(static) PRIORITY_AFTER_PHYSICS :number

A System#priority value that causes the system to run after the
physics system on each update.

(static) PRIORITY_AFTER_SCRIPTS :number

A System#priority value that causes the system to run after the
script system on each update.

(static) PRIORITY_AFTER_TRANSFORM :number

A System#priority value that causes the system to run after the
transform system on each update.

(static) PRIORITY_BEFORE_DEFAULT :number

A System#priority value that causes the system to run before the
default priority systems on each update.

(static) PRIORITY_BEFORE_MACHINES :number

A System#priority value that causes the system to run before the
state machine system on each update.

(static) PRIORITY_BEFORE_PHYSICS :number

A System#priority value that causes the system to run before the
physics system on each update.

(static) PRIORITY_BEFORE_SCRIPTS :number

A System#priority value that causes the system to run before the
script system on each update.

(static) PRIORITY_BEFORE_TANSFORM :number

A System#priority value that causes the system to run before the
transform system on each update.

(static) PRIORITY_DEFAULT :number

The System#priority used for most systems. These systems run after the
transform system on each update.

(static) PRIORITY_FIRST :number

The System#priority used for any system that needs to run before
all other systems. Note that there is no way to control the order in which
systems with this priority are run.

(static) PRIORITY_LAST

The System#priority used for any system that needs to run after
all other systems. Note that there is no way to control the order in which
systems with this priority are run.

(static) PRIORITY_MACHINES :number

The System#priority used for the state machine system. The state machine
system runs after the script system on each update.

(static) PRIORITY_PHYSICS :number

The System#priority used for the physics system. The physics system runs
first on each update.

(static) PRIORITY_SCRIPTS :number

The System#priority used for the script system. The script system
runs after the default priority systems on each update.

(static) PRIORITY_TRANSFORM :number

The System#priority used for the transform system. The transform system
runs after the physics system on each update.

(protected) _activeEntities :Array.<Entity>

The list of entities associated with this system.

passive :boolean

When false, System#process and System#fixedUpdate are
called for this system. Note that System#onPreRender and {@link
System#onPostRender} are called even when the system is passive.

priority :number

Priority of a system. The lower the number the higher the priority is.
The default is System.PRIORITY_DEFAULT.

type :string

world :World

The world to which the system is attached.

Methods

(protected) _insertEntityIfInterested(entity)

Checks if a system is interested in an entity based on its interests list
and adds or removes the entity from the system's list. System#inserted
or System#deleted will be called as needed.

Parameters:
Name Type Description
entity Entity

The entity to check.

(protected) _isInterestedInInsertedEntity(entity)

Called to determine if the system is interested in the entity. The default
implementation causes the system to be interested in entities that have
all of the components in interest array passed to the System constructor.

Parameters:
Name Type Description
entity Entity

The entity to check.

(protected) added(entity)

Called when an entity is added to the world. The entity will be added to
the list of entities associated with this system based on the presence of
component(s) of the type(s) in which the system is interested. {@link
System#inserted} will be called if the entity is associated with the
system.

Parameters:
Name Type Description
entity Entity

The added entity.

(protected) addedComponent(entity, component)

Called by World when an entity gains a component. The entity
will be added to the system's System#_activeEntities list and
System#inserted will be called if System#inserted
returns true for the entity.

Parameters:
Name Type Description
entity Entity

The entity that has changed.

component Component

The component that was added.

cleanup()

Called when the system is removed from the world. The default
implementation calls System#deleted on all of the entities
entities associated with the system.

Systems can be removed from the world only while the world is stopped.

clear()

Clears this system. The default implementation clears the list of entities
associated with the system. Once this method is called this instance of
the system is unusable.

(protected) deleted(entity)

Called when an entity associated with this system is removed from the
world. The default implementation does nothing.

Parameters:
Name Type Description
entity Entity

The removed entity.

fixedUpdate(entities, fixedTpf)

Called on each physics tick, if the system is not passive.

Parameters:
Name Type Description
entities array

The list of entities associated with this system.

fixedTpf number

The amount of time taken for this frame.

(protected) inserted(entity)

Called when an entity associated with this system is added to the world.
The default implementation does nothing.

Parameters:
Name Type Description
entity Entity

The added entity.

onPostRender()

Called after the scene is being rendered. The default implementation does
nothing.

onPreRender()

Called before the scene is being rendered. The default implementation does
notihing.

pause()

Called when the world's execution is paused. The default implementation
does nothing.

process(entities, tpf)

Called on each render frame, if the system is not passive.

Parameters:
Name Type Description
entities array

The list of entities associated with this system.

tpf number

The amount of time taken for this frame.

(protected) removed(entity)

Called by World when an entity is removed from the world. If the
entity is in the list of entities associated with this system, it is
removed from the list and System#deleted is called.

Parameters:
Name Type Description
entity Entity

The entity that has been removed.

(protected) removedComponent(entity, component)

Called by World when an entity loses a component. The entity
will be removed from the system's System#_activeEntities list and
System#deleted will be called if System#inserted
does not return true for the entity.

Parameters:
Name Type Description
entity Entity

The entity that has changed.

component Component

The component that was added.

render(renderer, occlusionGraph)

Called by SumerianRunner on registered rendering systems during
the render process. The default implementation does nothing.

Note that render systems are registered using SumerianRunner#setRenderSystem
instead of World#setSystem.

Parameters:
Name Type Description
renderer Renderer

Provides access to rendering apis can be used to for
rendering.

occlusionGraph Object

resume()

Called when the world's execution is resumed. The default implementation
does nothing.

setup(world)

Called when the system is added to the world. The default implementation
adds all of the entities in the world that have components in which this
system is interested.

Systems can be added to the world only while the world is stopped.

Parameters:
Name Type Description
world World

start()

Called when the world's execution is started. The default implementation
does nothing.

Systems can override this and the System#pause, System@resume,
and System#stop functions to update System#passive so that
the system isn't executed when the world is paused or stopped. In this case
the system should set System#passive to false in the constructor
and override System@setup to update the property to reflect the
state of the world when the system was added to the world (which can
happen while the world is stopped, running, or paused).

stop()

Called when the world's execution is stopped. The default implementation
does nothing.