diff --git a/CMakeLists.txt b/CMakeLists.txt index f69f0f66d..cb4958df3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ source_group(apps\\openmw\\mwinput FILES ${GAMEINPUT} ${GAMEINPUT_HEADER}) set(GAMESCRIPT apps/openmw/mwscript/scriptmanager.cpp + apps/openmw/mwscript/compilercontext.cpp apps/openmw/mwscript/interpretercontext.cpp apps/openmw/mwscript/cellextensions.cpp apps/openmw/mwscript/extensions.cpp diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index a757d26d3..e93bd9587 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -180,7 +180,8 @@ void OMW::Engine::go() MWScript::registerExtensions (mExtensions); - mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full); + mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full, + mEnvironment); mScriptContext->setExtensions (&mExtensions); mScriptManager = new MWScript::ScriptManager (mEnvironment.mWorld->getStore(), mVerboseScripts, diff --git a/apps/openmw/mwscript/compilercontext.cpp b/apps/openmw/mwscript/compilercontext.cpp new file mode 100644 index 000000000..bcd88b620 --- /dev/null +++ b/apps/openmw/mwscript/compilercontext.cpp @@ -0,0 +1,26 @@ + +#include "compilercontext.hpp" + +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" + +namespace MWScript +{ + CompilerContext::CompilerContext (Type type, const MWWorld::Environment& environment) + : mType (type), mEnvironment (environment) + {} + + bool CompilerContext::canDeclareLocals() const + { + return mType==Type_Full; + } + + char CompilerContext::getGlobalType (const std::string& name) const + { + if (const ESM::Global *global = mEnvironment.mWorld->getStore().globals.find (name)) + return global->type; + + return ' '; + } +} + diff --git a/apps/openmw/mwscript/compilercontext.hpp b/apps/openmw/mwscript/compilercontext.hpp index de177376d..41d5f314e 100644 --- a/apps/openmw/mwscript/compilercontext.hpp +++ b/apps/openmw/mwscript/compilercontext.hpp @@ -3,6 +3,11 @@ #include +namespace MWWorld +{ + class Environment; +} + namespace MWScript { class CompilerContext : public Compiler::Context @@ -19,19 +24,17 @@ namespace MWScript private: Type mType; + const MWWorld::Environment& mEnvironment; public: - CompilerContext (Type type) : mType (type) {} + CompilerContext (Type type, const MWWorld::Environment& environment); - // Is the compiler allowed to declare local variables? - virtual bool canDeclareLocals() const - { - return mType==Type_Full; - } + /// Is the compiler allowed to declare local variables? + virtual bool canDeclareLocals() const; - virtual char getGlobalType (const std::string& name) const { return ' '; } - ///< 'l: long, 's': short, 'f': float, ' ': does not exist. + /// 'l: long, 's': short, 'f': float, ' ': does not exist. + virtual char getGlobalType (const std::string& name) const; }; } diff --git a/components/esm/loadglob.hpp b/components/esm/loadglob.hpp index ca1675097..9de3e1a46 100644 --- a/components/esm/loadglob.hpp +++ b/components/esm/loadglob.hpp @@ -11,7 +11,7 @@ namespace ESM { struct Global { - float value; + unsigned value; VarType type; void load(ESMReader &esm) @@ -24,8 +24,7 @@ struct Global else esm.fail("Illegal global variable type " + tmp); type = t; - // The value looks like a float in many cases, and like an integer - // in others (for the s type at least.) Figure it out. + // Note: Both floats and longs are represented as floats. esm.getHNT(value, "FLTV"); } };