diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 89b107ae8f..8bcbbe5c7a 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -4,6 +4,8 @@ #include #include +#include + #include "locals.hpp" #include "../mwworld/world.hpp" @@ -78,32 +80,44 @@ namespace MWScript int InterpreterContext::getGlobalShort (const std::string& name) const { - return 0; + Interpreter::Type_Data value = mEnvironment.mWorld->getGlobalVariable (name); + return static_cast ( + *reinterpret_cast (&value)); } int InterpreterContext::getGlobalLong (const std::string& name) const { - return 0; + // a global long is internally a float. + Interpreter::Type_Data value = mEnvironment.mWorld->getGlobalVariable (name); + return static_cast ( + *reinterpret_cast (&value)); } float InterpreterContext::getGlobalFloat (const std::string& name) const { - return 0; + Interpreter::Type_Data value = mEnvironment.mWorld->getGlobalVariable (name); + return *reinterpret_cast (&value); } void InterpreterContext::setGlobalShort (const std::string& name, int value) { - + mEnvironment.mWorld->getGlobalVariable (name) = + *reinterpret_cast (&value); } void InterpreterContext::setGlobalLong (const std::string& name, int value) { - + // a global long is internally a float. + float value2 = value; + + mEnvironment.mWorld->getGlobalVariable (name) = + *reinterpret_cast (&value2); } void InterpreterContext::setGlobalFloat (const std::string& name, float value) { - + mEnvironment.mWorld->getGlobalVariable (name) = + *reinterpret_cast (&value); } MWWorld::World& InterpreterContext::getWorld() diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index aae72e5bc3..0381fa159a 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -72,6 +72,12 @@ namespace MWWorld mInteriors[startCell].loadInt (startCell, mStore, mEsm); insertInteriorScripts (mInteriors[startCell]); + + // global variables + for (ESMS::RecListT::MapType::const_iterator iter + (mStore.globals.list.begin()); + iter != mStore.globals.list.end(); ++iter) + mGlobalVariables.insert (std::make_pair (iter->first, iter->second.value)); std::cout << "\nSetting up cell rendering\n"; @@ -123,4 +129,14 @@ namespace MWWorld // Cell change not implemented yet. return false; } + + Interpreter::Type_Data& World::getGlobalVariable (const std::string& name) + { + std::map::iterator iter = mGlobalVariables.find (name); + + if (iter==mGlobalVariables.end()) + throw std::runtime_error ("unknown global variable: " + name); + + return iter->second; + } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index ce18e9368e..98f22963ab 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -8,6 +8,8 @@ #include +#include + #include "../mwrender/playerpos.hpp" #include "../mwrender/mwscene.hpp" @@ -49,6 +51,7 @@ namespace MWWorld ESMS::ESMStore mStore; std::map mInteriors; ScriptList mLocalScripts; + std::map mGlobalVariables; // not implemented World (const World&); @@ -72,6 +75,8 @@ namespace MWWorld bool hasCellChanged() const; ///< Has the player moved to a different cell, since the last frame? + + Interpreter::Type_Data& getGlobalVariable (const std::string& name); }; }