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/itemmanager.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/itemmanager.cpp')
-rw-r--r-- | src/game-server/itemmanager.cpp | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index ffbdce89..b334760a 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -26,6 +26,7 @@ #include "game-server/item.h" #include "game-server/skillmanager.h" #include "scripting/script.h" +#include "scripting/scriptmanager.h" #include "utils/logger.h" #include <map> @@ -401,7 +402,7 @@ void ItemManager::readEffectNode(xmlNodePtr effectNode, ItemClass *item) } else if (xmlStrEqual(subNode->name, BAD_CAST "consumes")) { - item->addEffect(new ItemEffectConsumes(), triggerTypes.first); + item->addEffect(new ItemEffectConsumes, triggerTypes.first); } else if (xmlStrEqual(subNode->name, BAD_CAST "script")) { @@ -432,29 +433,19 @@ void ItemManager::readEffectNode(xmlNodePtr effectNode, ItemClass *item) } LOG_INFO("Loading item script: " << filename.str()); - - std::string engineName = - Script::determineEngineByFilename(filename.str()); - Script *script = Script::create(engineName); + Script *script = ScriptManager::currentState(); if (!script->loadFile(filename.str())) { - // Delete the script as it's invalid. - delete script; - LOG_WARN("Could not load script file \"" << filename.str() - << "\" for item #" << item->mDatabaseID); + << "\" for item #" << item->mDatabaseID); continue; } - for_each_xml_child_node(scriptSubNode, subNode) - { - // TODO: Load variables from variable subnodes - } std::string dispellFunctionName = XML::getProperty(subNode, "dispell-function", std::string()); - item->addEffect(new ItemEffectScript(item->mDatabaseID, script, + item->addEffect(new ItemEffectScript(item->mDatabaseID, activateFunctionName, dispellFunctionName), triggerTypes.first, |