summaryrefslogtreecommitdiff
path: root/src/event.h
diff options
context:
space:
mode:
authorChuck Miller <shadowmil@gmail.com>2010-11-11 21:55:25 -0500
committerChuck Miller <shadowmil@gmail.com>2010-11-11 22:45:58 -0500
commit5727a2d9eeb0688a16e5b7fe32f6d9836c4f7a4e (patch)
tree994cdeb1187a94996ca38c5e274aabaa5f1fec76 /src/event.h
parent3dd1baab3fb00a3aa99447430f16a431a205c614 (diff)
downloadmana-5727a2d9eeb0688a16e5b7fe32f6d9836c4f7a4e.tar.gz
mana-5727a2d9eeb0688a16e5b7fe32f6d9836c4f7a4e.tar.bz2
mana-5727a2d9eeb0688a16e5b7fe32f6d9836c4f7a4e.tar.xz
mana-5727a2d9eeb0688a16e5b7fe32f6d9836c4f7a4e.zip
Have the event system channels use enums instead of strings
Reviewed-by: Freeyorp
Diffstat (limited to 'src/event.h')
-rw-r--r--src/event.h29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/event.h b/src/event.h
index c7382fc1..42f4d068 100644
--- a/src/event.h
+++ b/src/event.h
@@ -28,6 +28,21 @@
class ActorSprite;
class Item;
+enum Channels
+{
+ CHANNEL_ACTORSPRITE,
+ CHANNEL_ATTRIBUTES,
+ CHANNEL_BUYSELL,
+ CHANNEL_CHAT,
+ CHANNEL_CLIENT,
+ CHANNEL_GAME,
+ CHANNEL_ITEM,
+ CHANNEL_NOTICES,
+ CHANNEL_NPC,
+ CHANNEL_STATUS,
+ CHANNEL_STORAGE
+};
+
namespace Mana
{
@@ -41,7 +56,7 @@ enum BadEvent {
class Listener;
typedef std::set<Listener *> ListenerSet;
-typedef std::map<std::string, ListenerSet > ListenMap;
+typedef std::map<Channels, ListenerSet > ListenMap;
class VariableData;
typedef std::map<std::string, VariableData *> VariableMap;
@@ -49,7 +64,7 @@ typedef std::map<std::string, VariableData *> VariableMap;
#define SERVER_NOTICE(message) { \
Mana::Event event("ServerNotice"); \
event.setString("message", message); \
-event.trigger("Notices", event); }
+event.trigger(CHANNEL_NOTICES, event); }
class Event
{
@@ -220,19 +235,19 @@ public:
/**
* Sends this event to all classes listening to the given channel.
*/
- inline void trigger(const std::string &channel) const
+ inline void trigger(Channels channel) const
{ trigger(channel, *this); }
/**
* Sends the given event to all classes listening to the given channel.
*/
- static void trigger(const std::string &channel, const Event &event);
+ static void trigger(Channels channel, const Event &event);
/**
* Sends an empty event with the given name to all classes listening to the
* given channel.
*/
- static inline void trigger(const std::string& channel,
+ static inline void trigger(Channels channel,
const std::string& name)
{ trigger(channel, Mana::Event(name)); }
@@ -243,13 +258,13 @@ protected:
* Binds the given listener to the given channel. The listener will receive
* all events triggered on the channel.
*/
- static void bind(Listener *listener, const std::string &channel);
+ static void bind(Listener *listener, Channels channel);
/**
* Unbinds the given listener from the given channel. The listener will no
* longer receive any events from the channel.
*/
- static void unbind(Listener *listener, const std::string &channel);
+ static void unbind(Listener *listener, Channels channel);
/**
* Unbinds the given listener from all channels.