diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-05-27 23:26:19 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-01-09 17:12:15 +0100 |
commit | 0b339e547b77f80d6e81313bfb38249ce8995553 (patch) | |
tree | f22fee0142f72042430ace070a6e6ef4493e7c39 /src/game-server/entity.h | |
parent | 16074a7c2c8197a061281a6880ddbc3967d8ea0c (diff) | |
download | manaserv-0b339e547b77f80d6e81313bfb38249ce8995553.tar.gz manaserv-0b339e547b77f80d6e81313bfb38249ce8995553.tar.bz2 manaserv-0b339e547b77f80d6e81313bfb38249ce8995553.tar.xz manaserv-0b339e547b77f80d6e81313bfb38249ce8995553.zip |
Replaced EventListener with signals based on libsigc++
This replaces the rather hard to understand event dispatcher with a
probably even harder to understand templated library, but fortunately
we can rely on the available documentation.
Hopefully it will also help with the readability of our code and with
adding additional signals to other classes.
Added libsigc++ to README and Travis CI configuration.
Reviewed-by: Erik Schilling
Diffstat (limited to 'src/game-server/entity.h')
-rw-r--r-- | src/game-server/entity.h | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/src/game-server/entity.h b/src/game-server/entity.h index 652db7c7..91f13699 100644 --- a/src/game-server/entity.h +++ b/src/game-server/entity.h @@ -23,18 +23,20 @@ #include "common/manaserv_protocol.h" -using namespace ManaServ; - #include <set> -class EventListener; +#include <sigc++/signal.h> +#include <sigc++/trackable.h> + +using namespace ManaServ; + class MapComposite; /** * Base class for in-game objects. Knows only its type and the map it resides * on. Provides listeners. */ -class Entity +class Entity : public sigc::trackable { public: Entity(EntityType type, MapComposite *map = 0) @@ -42,7 +44,7 @@ class Entity mType(type) {} - virtual ~Entity(); + virtual ~Entity() {} /** * Gets type of this entity. @@ -88,29 +90,8 @@ class Entity virtual void setMap(MapComposite *map) { mMap = map; } - /** - * Adds a new listener. - */ - void addListener(const EventListener *); - - /** - * Removes an existing listener. - */ - void removeListener(const EventListener *); - - /** - * Calls all the "inserted" listeners. - */ - virtual void inserted(); - - /** - * Calls all the "removed" listeners. - */ - virtual void removed(); - - protected: - typedef std::set< const EventListener * > Listeners; - Listeners mListeners; /**< List of event listeners. */ + sigc::signal<void, Entity *> signal_inserted; + sigc::signal<void, Entity *> signal_removed; private: MapComposite *mMap; /**< Map the entity is on */ |