summaryrefslogtreecommitdiff
path: root/src/scripting
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-05-27 23:26:19 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-01-09 17:12:15 +0100
commit0b339e547b77f80d6e81313bfb38249ce8995553 (patch)
treef22fee0142f72042430ace070a6e6ef4493e7c39 /src/scripting
parent16074a7c2c8197a061281a6880ddbc3967d8ea0c (diff)
downloadmanaserv-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/scripting')
-rw-r--r--src/scripting/lua.cpp6
-rw-r--r--src/scripting/luascript.cpp2
-rw-r--r--src/scripting/luascript.h2
-rw-r--r--src/scripting/script.cpp3
-rw-r--r--src/scripting/script.h22
5 files changed, 12 insertions, 23 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 545e365e..880216d2 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -1709,7 +1709,11 @@ static int chr_get_post(lua_State *s)
static int being_register(lua_State *s)
{
Being *being = checkBeing(s, 1);
- being->addListener(getScript(s)->getScriptListener());
+ Script *script = getScript(s);
+
+ being->signal_died.connect(sigc::mem_fun(script, &Script::processDeathEvent));
+ being->signal_removed.connect(sigc::mem_fun(script, &Script::processRemoveEvent));
+
return 0;
}
diff --git a/src/scripting/luascript.cpp b/src/scripting/luascript.cpp
index 4104bc89..f4ea39ac 100644
--- a/src/scripting/luascript.cpp
+++ b/src/scripting/luascript.cpp
@@ -265,8 +265,6 @@ void LuaScript::processRemoveEvent(Entity *entity)
// being. This might be very interesting for scripting quests.
execute();
}
-
- entity->removeListener(getScriptListener());
}
/**
diff --git a/src/scripting/luascript.h b/src/scripting/luascript.h
index 7631d982..9515bf0e 100644
--- a/src/scripting/luascript.h
+++ b/src/scripting/luascript.h
@@ -28,6 +28,8 @@ extern "C" {
#include "scripting/script.h"
+class Character;
+
/**
* Implementation of the Script class for Lua.
*/
diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp
index 3e299461..63ab7ff4 100644
--- a/src/scripting/script.cpp
+++ b/src/scripting/script.cpp
@@ -40,8 +40,7 @@ Script::Ref Script::mUpdateCallback;
Script::Script():
mCurrentThread(0),
- mMap(0),
- mEventListener(&scriptEventDispatch)
+ mMap(0)
{}
Script::~Script()
diff --git a/src/scripting/script.h b/src/scripting/script.h
index 238bc34c..8dee23a9 100644
--- a/src/scripting/script.h
+++ b/src/scripting/script.h
@@ -23,19 +23,21 @@
#include "common/inventorydata.h"
#include "common/manaserv_protocol.h"
-#include "game-server/eventlistener.h"
#include <list>
#include <string>
#include <vector>
+#include <sigc++/trackable.h>
+
+class Being;
class MapComposite;
class Entity;
/**
* Abstract interface for calling functions written in an external language.
*/
-class Script
+class Script : public sigc::trackable
{
public:
/**
@@ -216,9 +218,6 @@ class Script
MapComposite *getMap() const
{ return mMap; }
- EventListener *getScriptListener()
- { return &mEventListener; }
-
virtual void processDeathEvent(Being *entity) = 0;
virtual void processRemoveEvent(Entity *entity) = 0;
@@ -235,7 +234,6 @@ class Script
private:
MapComposite *mMap;
- EventListener mEventListener; /**< Tracking of being deaths. */
std::vector<Thread*> mThreads;
static Ref mCreateNpcDelayedCallback;
@@ -245,16 +243,4 @@ class Script
friend class Thread;
};
-struct ScriptEventDispatch: EventDispatch
-{
- ScriptEventDispatch()
- {
- typedef EventListenerFactory< Script, &Script::mEventListener > Factory;
- died = &Factory::create< Being, &Script::processDeathEvent >::function;
- removed = &Factory::create< Entity, &Script::processRemoveEvent >::function;
- }
-};
-
-static ScriptEventDispatch scriptEventDispatch;
-
#endif // SCRIPTING_SCRIPT_H