Skip to content

Commit

Permalink
inherit variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Assumeru committed Jul 29, 2020
1 parent 72b63ed commit b39f35d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
9 changes: 9 additions & 0 deletions apps/openmw/mwscript/globalscripts.cpp
Expand Up @@ -299,6 +299,15 @@ namespace MWScript
return iter->second->mLocals;
}

const Locals* GlobalScripts::getLocalsIfPresent (const std::string& name) const
{
std::string name2 = ::Misc::StringUtils::lowerCase (name);
auto iter = mScripts.find (name2);
if (iter==mScripts.end())
return nullptr;
return &iter->second->mLocals;
}

void GlobalScripts::updatePtrs(const MWWorld::Ptr& base, const MWWorld::Ptr& updated)
{
MatchPtrVisitor visitor(base);
Expand Down
2 changes: 2 additions & 0 deletions apps/openmw/mwscript/globalscripts.hpp
Expand Up @@ -82,6 +82,8 @@ namespace MWScript
///< If the script \a name has not been added as a global script yet, it is added
/// automatically, but is not set to running state.

const Locals* getLocalsIfPresent (const std::string& name) const;

void updatePtrs(const MWWorld::Ptr& base, const MWWorld::Ptr& updated);
///< Update the Ptrs stored in mTarget. Should be called after the reference has been moved to a new cell.
};
Expand Down
29 changes: 20 additions & 9 deletions apps/openmw/mwscript/locals.cpp
@@ -1,4 +1,5 @@
#include "locals.hpp"
#include "globalscripts.hpp"

#include <components/esm/loadscpt.hpp>
#include <components/esm/variant.hpp>
Expand Down Expand Up @@ -33,15 +34,25 @@ namespace MWScript
if (mInitialised)
return false;

const Compiler::Locals& locals =
MWBase::Environment::get().getScriptManager()->getLocals (script.mId);

mShorts.clear();
mShorts.resize (locals.get ('s').size(), 0);
mLongs.clear();
mLongs.resize (locals.get ('l').size(), 0);
mFloats.clear();
mFloats.resize (locals.get ('f').size(), 0);
const Locals* global = MWBase::Environment::get().getScriptManager()->getGlobalScripts().getLocalsIfPresent(script.mId);
if(global)
{
mShorts = global->mShorts;
mLongs = global->mLongs;
mFloats = global->mFloats;
}
else
{
const Compiler::Locals& locals =
MWBase::Environment::get().getScriptManager()->getLocals (script.mId);

mShorts.clear();
mShorts.resize (locals.get ('s').size(), 0);
mLongs.clear();
mLongs.resize (locals.get ('l').size(), 0);
mFloats.clear();
mFloats.resize (locals.get ('f').size(), 0);
}

mInitialised = true;
return true;
Expand Down

0 comments on commit b39f35d

Please sign in to comment.