Skip to main content

System

Classes

Base class to extend ECS systems from. A System defines some behavior over a tuple of components. Override base methods as needed to achieve desired behavior. The system already offers update and fixedUpdate methods for time-based simulation. If you have event-driven requirements - make use of link and unlink methods, as well as messaging facilities of EntityComponentDataset.

System

Base class to extend ECS systems from. A System defines some behavior over a tuple of components. Override base methods as needed to achieve desired behavior. The system already offers update and fixedUpdate methods for time-based simulation. If you have event-driven requirements - make use of link and unlink methods, as well as messaging facilities of EntityComponentDataset.

Kind: global class
Author: Alex Goldring
Copyright: Company Named Limited (c) 2025

new exports.System()

Example

class FallDamageSystem{
dependencies = [Health, Physics]

listeners = []; // internal storage

link(health: Health, physics: Physics, entity: number){
const listener = () => health.value -= 10; // receive damage on fall
physics.onContact.add(listener);
this.listeners[entity] = listener; // remember for later
}

unlink(health: Health, physics: Physics, entity: number){
const listener = this.listeners[entity];
physics.onContact.remove(listener);
delete this.listeners[entity]; // cleanup
}
}

system.entityManager : EntityManager

Reference to the attached EntityManager, usually set during startup Useful for gaining access to other Systems, via EntityManager.getSystem as well as the associated dataset via EntityManager.dataset

Kind: instance property of System
Access: protected

system.state : ObservedValue.<SystemState>

Managed internally by EntityManager, do not modify manually

Kind: instance property of System
Read only: true

system.dependencies : Array

Component classes which have to be present before the system links an entity. NOTE: do not modify this while the system is running.

Kind: instance property of System
Read only: true
See

  • link
  • unlink

system.components_used : Array.<ResourceAccessSpecification>

Component types that are used internally by the system and how they are used Main benefit of doing so is twofold:

  • Helps the engine figure out the best execution order for system to make sure that updates propagate as quickly as possible
  • Declaring this helps EntityManager to ensure that all relevant component types are properly registered for the system

NOTE: specifying this is optional. The engine will still work. NOTE: do not modify this while the system is running

Kind: instance property of System
Read only: true

system.referenced_components ⇒ Array

Kind: instance property of System
Returns: Array - Component classes

system.isSystem : boolean

Kind: instance property of System
Read only: true

system.fixedUpdate

Fixed update function, every step happens with the same exact time increment useful for systems that must have a fixed time step to be predictable and stable, such as physics

Kind: instance property of System

ParamTypeDescription
timeDeltanumberin seconds, will always be the same value, controlled via EntityManager.fixedUpdateStepSize

system.update

This update is generally synchronized with the render loop. Note that this time step can vary depending on system conditions and hardware we are running on. It is generally safe to assume that this update will happen once per frame, but it is not guaranteed. Also, note that when the application window/tab is suspended, the next update step can have a very large value.

Kind: instance property of System

ParamTypeDescription
timeDeltanumberin seconds

system.getAccessForComponent(Klass) ⇒ number

Does not check if the component is present, will return 0 if not present.

Kind: instance method of System
Returns: number - bitmask of ResourceAccessKind

ParamType
KlassT

system.startup(entityManager) ⇒ Promise.<void>

Invoked before System is used for the first time. Managed by EntityManager's lifecycle. Do not call this manually.

Kind: instance method of System
See: shutdown

ParamType
entityManagerEntityManager

system.shutdown(entityManager) ⇒ Promise.<void>

Invoked when System is no longer needed. Good place to clean up any held resourced and terminate owned processes. Managed by EntityManager's lifecycle. Do not call this manually.

Kind: instance method of System
See: startup

ParamType
entityManagerEntityManager

Called automatically when an entity gets a complete component tuple this.dependencies. Inputs are the same as dependencies, only instances instead of classes, plus there is an extra argument at the end, which is the entity ID. see EntityObserver for more implementation detail

Kind: instance method of System

Called automatically when an entity breaks component tuple this.dependencies. Inputs are the same as dependencies, only instances instead of classes, plus there is an extra argument at the end, which is the entity ID. see EntityObserver for more implementation detail

Kind: instance method of System

system.handleDatasetAttached(dataset)

Invoked when a dataset is attached to the system, this happens before any entities are linked. Happens as a result of EntityManager.attachDataset. It is generally advised NOT to modify the dataset here. Managed by EntityManager's lifecycle. Do not call this manually.

This method is entirely optional, it provides advanced functionality for situations where datasets are being switched on the fly.

see handleDatasetDetached for the reverse.

Kind: instance method of System

ParamType
datasetEntityComponentDataset

system.handleDatasetDetached(dataset)

Invoked when dataset is about to be detached from the system, this happens after all entities have been unlinked. Happens as a result of EntityManager.detachDataset. It is generally advised NOT to modify the dataset here. Managed by EntityManager's lifecycle. Do not call this manually.

This method is entirely optional, it provides advanced functionality for situations where datasets are being switched on the fly.

see handleDatasetAttached for the reverse.

Kind: instance method of System

ParamType
datasetEntityComponentDataset

SystemState : enum

Kind: global enum
Read only: true