diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-02-26 22:06:10 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-02 18:12:07 +0100 |
commit | 34ac0d64e23f2b2d3981dbb0ea72157f334805dd (patch) | |
tree | 114b1f7a65956c097f7a59078292c9fa29c6451f /src/game-server/statusmanager.cpp | |
parent | e896d0b0125b48e12d43d99ace4498e56d968d50 (diff) | |
download | manaserv-34ac0d64e23f2b2d3981dbb0ea72157f334805dd.tar.gz manaserv-34ac0d64e23f2b2d3981dbb0ea72157f334805dd.tar.bz2 manaserv-34ac0d64e23f2b2d3981dbb0ea72157f334805dd.tar.xz manaserv-34ac0d64e23f2b2d3981dbb0ea72157f334805dd.zip |
Merged all the different Lua states into one
No more Lua state for each status effect, monster, item effect or map. All
scripts are loaded into the same state. This should be more efficient overall
and make it easier to implement dynamic reloading of the scripts in the
future.
Now, this introduces the problem of name collisions between different Lua
scripts. For now this is solved by using more specific function names, like
'tick_plague' and 'tick_jump' rather than just 'tick'. The plan is however
to get rid of these globals, and register these callbacks from the script,
so that they can be local functions without the danger of colliding with
other scripts.
Reviewed-by: Erik Schilling
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/game-server/statusmanager.cpp')
-rw-r--r-- | src/game-server/statusmanager.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/game-server/statusmanager.cpp b/src/game-server/statusmanager.cpp index 66c2642a..15203d65 100644 --- a/src/game-server/statusmanager.cpp +++ b/src/game-server/statusmanager.cpp @@ -23,6 +23,7 @@ #include "common/resourcemanager.h" #include "game-server/statuseffect.h" #include "scripting/script.h" +#include "scripting/scriptmanager.h" #include "utils/logger.h" #include "utils/xml.h" @@ -68,6 +69,8 @@ void StatusManager::reload() } std::string scriptFile = XML::getProperty(node, "script", std::string()); + std::string tickFunction = XML::getProperty(node, "tick-function", + std::string()); //TODO: Get these modifiers /* modifiers.setAttributeValue(BASE_ATTR_PHY_ATK_MIN, XML::getProperty(node, "attack-min", 0)); @@ -82,6 +85,7 @@ void StatusManager::reload() modifiers.setAttributeValue(CHAR_ATTR_WILLPOWER, XML::getProperty(node, "willpower", 0)); */ StatusEffect *statusEffect = new StatusEffect(id); + statusEffect->setTickFunction(tickFunction); if (!scriptFile.empty()) { std::stringstream filename; @@ -89,11 +93,8 @@ void StatusManager::reload() if (ResourceManager::exists(filename.str())) // file exists! { LOG_INFO("Loading status script: " << filename.str()); - std::string engineName = - Script::determineEngineByFilename(filename.str()); - Script *s = Script::create(engineName); + Script *s = ScriptManager::currentState(); s->loadFile(filename.str()); - statusEffect->setScript(s); } else { LOG_WARN("Could not find script file \"" << filename.str() << "\" for status #"<<id); |