Skip to content

Class: StatefulSystem

StatefulSystem defines a system that tracks the state of entities and components by listening for register and deregister messages.

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

+ new StatefulSystem(messageBus: IMessageBus, scene?: IScene, subscriberID?: number): StatefulSystem

Parameters:

Name Type
messageBus IMessageBus
scene? IScene
subscriberID? number

Returns: StatefulSystem

Inherited from: System

Properties

messageBus

Protected messageBus: IMessageBus

Reference to the message bus, the fundamental piece of JamJar for communicating with other parts of the engine.

Inherited from: System.messageBus


scene

Protected Optional scene: undefined | IScene

Any scene this system is part of, will change the lifecycle of the system to be part of the scene's lifecycle - it will be destroyed when the scene is destroyed.

Inherited from: System.scene


subscriberID

subscriberID: number

Inherited from: System.subscriberID


MESSAGE_DEREGISTER

Readonly Static MESSAGE_DEREGISTER: stateful_system_deregister= "stateful_system_deregister"

Message to deregister an entity + components with a system so it is no longer tracked.


MESSAGE_REGISTER

Readonly Static MESSAGE_REGISTER: stateful_system_register= "stateful_system_register"

Message to register an entity + components with a system so it can be tracked.


MESSAGE_UPDATE

Readonly Static MESSAGE_UPDATE: system_update= "system_update"

Inherited from: System.MESSAGE_UPDATE

Methods

Destroy

Destroy(): void

Destroy destroys the System and unsubscribes it from all messages. The System should be garbage collected after this, unless a direct reference to it exists somewhere. Therefore direct references to systems are discouraged; communication should all be through the message bus.

Returns: void

Inherited from: System


OnDestroy

ProtectedOnDestroy(): void

Custom Destroy logic should go here to facilitate garbage collection, for example removing listeners.

Returns: void

Inherited from: System


OnMessage

OnMessage(message: IMessage): void

Parameters:

Name Type
message IMessage

Returns: void

Overrides: System


Update

ProtectedUpdate(dt: number): void

General update method, default empty. Override with custom logic.

Parameters:

Name Type Description
dt number DeltaTime

Returns: void

Inherited from: System


register

Protected Abstractregister(entity: IEntity, components: Component[]): void

register is used when a new entity is created with components, or an existing entity's components are changed; register calls the evaluator to check if the system should track this entity. If the evaluator returns true, the entity is added to the System's internal entity array.

Parameters:

Name Type Description
entity IEntity The entity to register
components Component[] The components of the registering entity.

Returns: void


remove

Protected Abstractremove(entity: IEntity): void

remove removes an entity from being tracked by the system

Parameters:

Name Type Description
entity IEntity The entity to remove

Returns: void