MessageDispatcher()

This class is the core of the messaging system for game entities and used by the EntityManager. The implementation can directly dispatch messages or use a delayed delivery for deferred communication. This can be useful if a game entity wants to inform itself about a particular event in the future.

new MessageDispatcher()

Constructs a new message dispatcher.

Author:

Members

readonly delayedTelegrams :Array.<Telegram>

A list of delayed telegrams.

Methods

clear() → {MessageDispatcher}

Clears the internal state of this message dispatcher.

Returns:
MessageDispatcher -

A reference to this message dispatcher.

deliver(telegram) → {MessageDispatcher}

Delivers the message to the receiver.

Parameters:
Name Type Description
telegram Telegram

The telegram to deliver.

Returns:
MessageDispatcher -

A reference to this message dispatcher.

dispatch(sender, receiver, message, delay, data) → {MessageDispatcher}

Receives the raw telegram data and decides how to dispatch the telegram (with or without delay).

Parameters:
Name Type Description
sender GameEntity

The sender.

receiver GameEntity

The receiver.

message String

The actual message.

delay Number

A time value in millisecond used to delay the message dispatching.

data Object

An object for custom data.

Returns:
MessageDispatcher -

A reference to this message dispatcher.

dispatchDelayedMessages(delta) → {MessageDispatcher}

Used to process delayed messages.

Parameters:
Name Type Description
delta Number

The time delta.

Returns:
MessageDispatcher -

A reference to this message dispatcher.

fromJSON(json) → {MessageDispatcher}

Restores this instance from the given JSON object.

Parameters:
Name Type Description
json Object

The JSON object.

Returns:
MessageDispatcher -

A reference to this message dispatcher.

resolveReferences(entities) → {MessageDispatcher}

Restores UUIDs with references to GameEntity objects.

Parameters:
Name Type Description
entities Map.<String, GameEntity>

Maps game entities to UUIDs.

Returns:
MessageDispatcher -

A reference to this message dispatcher.

toJSON() → {Object}

Transforms this instance into a JSON object.

Returns:
Object -

The JSON object.