![]() |
Angel
A 2D Game Prototyping Engine
|
The central class which handles delivery of Messages. More...
#include <Switchboard.h>
Classes | |
| struct | MessageTimer |
| struct | SubscriptionInfo |
Public Member Functions | |
| void | Broadcast (Message *message) |
| void | DeferredBroadcast (Message *message, float delay) |
| void | Update (float dt) |
| const bool | SubscribeTo (MessageListener *subscriber, const String &messageType) |
| const bool | UnsubscribeFrom (MessageListener *subscriber, const String &messageType) |
| const std::set< MessageListener * > | GetSubscribersTo (const String &messageName) |
| const StringSet | GetSubscriptionsFor (MessageListener *subscriber) |
| void | SendAllMessages () |
Static Public Member Functions | |
| static Switchboard & | GetInstance () |
Static Protected Attributes | |
| static Switchboard * | s_Switchboard = NULL |
This class is where all Messages pass through to get to their subscribers. It manages subscribers lists, delivery, and broadcast of messages.
Like the World, it uses the singleton pattern; you can't actually declare a new instance of a Switchboard. To access messaging in your world, use "theSwitchboard" to retrieve the singleton object. "theSwitchboard" is defined in both C++ and Lua.
If you're not familiar with the singleton pattern, this paper is a good starting point. (Don't be afraid that it's written by Microsoft.)
http://msdn.microsoft.com/en-us/library/ms954629.aspx
Definition at line 55 of file Switchboard.h.
| Switchboard & Switchboard::GetInstance | ( | ) | [static] |
Used to access the singleton instance of this class. As a shortcut, you can just use "theSwitchboard".
Definition at line 42 of file Switchboard.cpp.
| void Switchboard::Broadcast | ( | Message * | message | ) |
Send a Message to all the MessageListeners who have subscribed to Messages of that particular name. All Messages are sent at the end of the current frame, outside the Update loop. (Which means you can safely remove objects from the World in response to a Message.)
| message | The message to send |
Definition at line 51 of file Switchboard.cpp.
| void Switchboard::DeferredBroadcast | ( | Message * | message, |
| float | delay | ||
| ) |
Lets you send a Message after a designated delay. Oftentimes you want something to happen a little while *after* an event, and it can be be easier to simply defer the sending of the Message rather than make the MessageListener responsible for implementing the delay.
| message | The message to send |
| delay | Amount of time (in seconds) to wait before sending |
Definition at line 56 of file Switchboard.cpp.
| void Switchboard::Update | ( | float | dt | ) |
Takes the same form as the Renderable::Update function, but Switchboard is not a Renderable. This function gets called by the World to let the Switchboard know about the passage of time so it can manage deferred broadcasts.
| dt | The amount of time elapsed since the last frame |
Definition at line 62 of file Switchboard.cpp.
| const bool Switchboard::SubscribeTo | ( | MessageListener * | subscriber, |
| const String & | messageType | ||
| ) |
Sign a MessageListener up to receive notifications when Messages of a specific class are broadcast through the Switchboard.
| subscriber | The MessageListener to sign up |
| messageType | The name of the Message it's interested in |
Definition at line 80 of file Switchboard.cpp.
| const bool Switchboard::UnsubscribeFrom | ( | MessageListener * | subscriber, |
| const String & | messageType | ||
| ) |
Lets a MessageListener stop receiving notifications of specific name. MessageListeners automatically unsubscribe from all their Messages when their destructors are called, so you don't have to worry about this when destroying an object; this would only be called directly in user code when you no longer care about a particular Message.
| subscriber | The MessageListener that doesn't want to get these Messages anymore |
| messageType | The name of the Message they're tired of hearing about |
Definition at line 93 of file Switchboard.cpp.
| const std::set< MessageListener * > Switchboard::GetSubscribersTo | ( | const String & | messageName | ) |
Get a list of all MessageListeners subscribed to Messages with a given name.
| messageName | The Message you care about |
Definition at line 120 of file Switchboard.cpp.
| const StringSet Switchboard::GetSubscriptionsFor | ( | MessageListener * | subscriber | ) |
Get a list of all Message subscriptions for a certain MessageListener
| subscriber | The MessageListener you care about |
Definition at line 132 of file Switchboard.cpp.
| void Switchboard::SendAllMessages | ( | ) |
Immediately sends all Messages to the appropriate subscribers. Called by the World at the end of each frame; you shouldn't call this directly in your game code.
Definition at line 144 of file Switchboard.cpp.


1.7.5.1