Game Messages

Game Messages inheritance structure

This is (only) the "top" of the GameMessage inheritance hierarchy (In reality, it has 30 inheritors). All game messages inherit from GameMessage.

diagram

The MessageBus

The MessageBus works per the publish/subscribe pattern.

The MessageBus works synchronously. This has the advantage that when a call to MessageBus.Post(myMessage) returns, all side effects of the message have already occurred. However, it must be noted that performance is crucial inside code blocks that react to GameMessages.

Listening to GameMessages

Users of the Engine should not have to worry about issuing (posting) GameMessages, as it is an internal working, but if you want to extend the engine, maybe receiving (listening for) messages comes in handy.

To listen for messages, you can write:

MessageBus.Singleton.OfType<PickupCollideWithUnit>().Subscribe(OnPickupCollideWithUnit);

private static void OnPickupCollideWithUnit(PickupCollideWithUnit message){
    // reaction
}
Note that OfType<T>() selects the type T and all its subclasses.

Order of GameMessages

Throughout TBE, ActorMessages are always posted AFTER other messages so that

  1. Other Messages execute logic.

  2. ActorMessages react on updated values.

In TBE, ActorMessage (and it’s inheritors) are only received by the Actor system and will not trigger any additional TBE internal logic.

Posting Messages

GameMessages are not supposed to be posted by user code except UnitActorMsg where you can supply a custom string. (Which you then also give in a reacting Actor event.)