mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 21:49:55 +00:00
removed function ScriptManager::getLocalIndex (was redundant and was also depending on precompiled scripts)
This commit is contained in:
parent
f55084463b
commit
2e355df8b3
6 changed files with 45 additions and 80 deletions
|
@ -50,13 +50,7 @@ namespace MWBase
|
||||||
///< Return locals for script \a name.
|
///< Return locals for script \a name.
|
||||||
|
|
||||||
virtual MWScript::GlobalScripts& getGlobalScripts() = 0;
|
virtual MWScript::GlobalScripts& getGlobalScripts() = 0;
|
||||||
|
};
|
||||||
virtual int getLocalIndex (const std::string& scriptId, const std::string& variable,
|
|
||||||
char type) = 0;
|
|
||||||
///< Return index of the variable of the given name and type in the given script. Will
|
|
||||||
/// throw an exception, if there is no such script or variable or the type does not match.
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,8 +3,12 @@
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <components/interpreter/types.hpp>
|
#include <components/interpreter/types.hpp>
|
||||||
|
|
||||||
|
#include <components/compiler/locals.hpp>
|
||||||
|
|
||||||
#include "../mwworld/esmstore.hpp"
|
#include "../mwworld/esmstore.hpp"
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
|
@ -103,6 +107,32 @@ namespace MWScript
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int InterpreterContext::findLocalVariableIndex (const std::string& scriptId,
|
||||||
|
const std::string& name, char type) const
|
||||||
|
{
|
||||||
|
int index = MWBase::Environment::get().getScriptManager()->getLocals (scriptId).
|
||||||
|
search (type, name);
|
||||||
|
|
||||||
|
if (index!=-1)
|
||||||
|
return index;
|
||||||
|
|
||||||
|
std::ostringstream stream;
|
||||||
|
|
||||||
|
stream << "Failed to access ";
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case 's': stream << "short"; break;
|
||||||
|
case 'l': stream << "long"; break;
|
||||||
|
case 'f': stream << "float"; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream << " member variable " << name << " in script " << scriptId;
|
||||||
|
|
||||||
|
throw std::runtime_error (stream.str().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
InterpreterContext::InterpreterContext (
|
InterpreterContext::InterpreterContext (
|
||||||
MWScript::Locals *locals, MWWorld::Ptr reference, const std::string& targetId)
|
MWScript::Locals *locals, MWWorld::Ptr reference, const std::string& targetId)
|
||||||
: mLocals (locals), mReference (reference),
|
: mLocals (locals), mReference (reference),
|
||||||
|
@ -485,10 +515,7 @@ namespace MWScript
|
||||||
|
|
||||||
const Locals& locals = getMemberLocals (scriptId, global);
|
const Locals& locals = getMemberLocals (scriptId, global);
|
||||||
|
|
||||||
int index = MWBase::Environment::get().getScriptManager()->getLocalIndex (
|
return locals.mShorts[findLocalVariableIndex (scriptId, name, 's')];
|
||||||
scriptId, name, 's');
|
|
||||||
|
|
||||||
return locals.mShorts[index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int InterpreterContext::getMemberLong (const std::string& id, const std::string& name,
|
int InterpreterContext::getMemberLong (const std::string& id, const std::string& name,
|
||||||
|
@ -498,10 +525,7 @@ namespace MWScript
|
||||||
|
|
||||||
const Locals& locals = getMemberLocals (scriptId, global);
|
const Locals& locals = getMemberLocals (scriptId, global);
|
||||||
|
|
||||||
int index = MWBase::Environment::get().getScriptManager()->getLocalIndex (
|
return locals.mLongs[findLocalVariableIndex (scriptId, name, 'l')];
|
||||||
scriptId, name, 'l');
|
|
||||||
|
|
||||||
return locals.mLongs[index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float InterpreterContext::getMemberFloat (const std::string& id, const std::string& name,
|
float InterpreterContext::getMemberFloat (const std::string& id, const std::string& name,
|
||||||
|
@ -511,10 +535,7 @@ namespace MWScript
|
||||||
|
|
||||||
const Locals& locals = getMemberLocals (scriptId, global);
|
const Locals& locals = getMemberLocals (scriptId, global);
|
||||||
|
|
||||||
int index = MWBase::Environment::get().getScriptManager()->getLocalIndex (
|
return locals.mFloats[findLocalVariableIndex (scriptId, name, 'f')];
|
||||||
scriptId, name, 'f');
|
|
||||||
|
|
||||||
return locals.mFloats[index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterpreterContext::setMemberShort (const std::string& id, const std::string& name,
|
void InterpreterContext::setMemberShort (const std::string& id, const std::string& name,
|
||||||
|
@ -524,10 +545,7 @@ namespace MWScript
|
||||||
|
|
||||||
Locals& locals = getMemberLocals (scriptId, global);
|
Locals& locals = getMemberLocals (scriptId, global);
|
||||||
|
|
||||||
int index =
|
locals.mShorts[findLocalVariableIndex (scriptId, name, 's')] = value;
|
||||||
MWBase::Environment::get().getScriptManager()->getLocalIndex (scriptId, name, 's');
|
|
||||||
|
|
||||||
locals.mShorts[index] = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterpreterContext::setMemberLong (const std::string& id, const std::string& name, int value, bool global)
|
void InterpreterContext::setMemberLong (const std::string& id, const std::string& name, int value, bool global)
|
||||||
|
@ -536,10 +554,7 @@ namespace MWScript
|
||||||
|
|
||||||
Locals& locals = getMemberLocals (scriptId, global);
|
Locals& locals = getMemberLocals (scriptId, global);
|
||||||
|
|
||||||
int index =
|
locals.mLongs[findLocalVariableIndex (scriptId, name, 'l')] = value;
|
||||||
MWBase::Environment::get().getScriptManager()->getLocalIndex (scriptId, name, 'l');
|
|
||||||
|
|
||||||
locals.mLongs[index] = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterpreterContext::setMemberFloat (const std::string& id, const std::string& name, float value, bool global)
|
void InterpreterContext::setMemberFloat (const std::string& id, const std::string& name, float value, bool global)
|
||||||
|
@ -548,10 +563,7 @@ namespace MWScript
|
||||||
|
|
||||||
Locals& locals = getMemberLocals (scriptId, global);
|
Locals& locals = getMemberLocals (scriptId, global);
|
||||||
|
|
||||||
int index =
|
locals.mFloats[findLocalVariableIndex (scriptId, name, 'f')] = value;
|
||||||
MWBase::Environment::get().getScriptManager()->getLocalIndex (scriptId, name, 'f');
|
|
||||||
|
|
||||||
locals.mFloats[index] = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MWWorld::Ptr InterpreterContext::getReference(bool required)
|
MWWorld::Ptr InterpreterContext::getReference(bool required)
|
||||||
|
|
|
@ -50,6 +50,10 @@ namespace MWScript
|
||||||
Locals& getMemberLocals (std::string& id, bool global);
|
Locals& getMemberLocals (std::string& id, bool global);
|
||||||
///< \a id is changed to the respective script ID, if \a id wasn't a script ID before
|
///< \a id is changed to the respective script ID, if \a id wasn't a script ID before
|
||||||
|
|
||||||
|
/// Throws an exception if local variable can't be found.
|
||||||
|
int findLocalVariableIndex (const std::string& scriptId, const std::string& name,
|
||||||
|
char type) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
InterpreterContext (MWScript::Locals *locals, MWWorld::Ptr reference,
|
InterpreterContext (MWScript::Locals *locals, MWWorld::Ptr reference,
|
||||||
|
|
|
@ -196,46 +196,4 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
return mGlobalScripts;
|
return mGlobalScripts;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScriptManager::getLocalIndex (const std::string& scriptId, const std::string& variable,
|
|
||||||
char type)
|
|
||||||
{
|
|
||||||
const ESM::Script *script = mStore.get<ESM::Script>().find (scriptId);
|
|
||||||
|
|
||||||
int offset = 0;
|
|
||||||
int size = 0;
|
|
||||||
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case 's':
|
|
||||||
|
|
||||||
offset = 0;
|
|
||||||
size = script->mData.mNumShorts;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'l':
|
|
||||||
|
|
||||||
offset = script->mData.mNumShorts;
|
|
||||||
size = script->mData.mNumLongs;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'f':
|
|
||||||
|
|
||||||
offset = script->mData.mNumShorts+script->mData.mNumLongs;
|
|
||||||
size = script->mData.mNumFloats;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
|
|
||||||
throw std::runtime_error ("invalid variable type");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string variable2 = Misc::StringUtils::lowerCase (variable);
|
|
||||||
|
|
||||||
for (int i=0; i<size; ++i)
|
|
||||||
if (Misc::StringUtils::lowerCase (script->mVarNames.at (i+offset))==variable2)
|
|
||||||
return i;
|
|
||||||
|
|
||||||
throw std::runtime_error ("unable to access local variable " + variable + " of " + scriptId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,11 +71,6 @@ namespace MWScript
|
||||||
///< Return locals for script \a name.
|
///< Return locals for script \a name.
|
||||||
|
|
||||||
virtual GlobalScripts& getGlobalScripts();
|
virtual GlobalScripts& getGlobalScripts();
|
||||||
|
|
||||||
virtual int getLocalIndex (const std::string& scriptId, const std::string& variable,
|
|
||||||
char type);
|
|
||||||
///< Return index of the variable of the given name and type in the given script. Will
|
|
||||||
/// throw an exception, if there is no such script or variable or the type does not match.
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,6 @@ namespace Compiler
|
||||||
|
|
||||||
int searchIndex (char type, const std::string& name) const;
|
int searchIndex (char type, const std::string& name) const;
|
||||||
|
|
||||||
bool search (char type, const std::string& name) const;
|
|
||||||
|
|
||||||
std::vector<std::string>& get (char type);
|
std::vector<std::string>& get (char type);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -29,6 +27,10 @@ namespace Compiler
|
||||||
int getIndex (const std::string& name) const;
|
int getIndex (const std::string& name) const;
|
||||||
///< return index for local variable \a name (-1: does not exist).
|
///< return index for local variable \a name (-1: does not exist).
|
||||||
|
|
||||||
|
/// Return index for local variable \a name of type \a type (-1: variable does not
|
||||||
|
/// exit).
|
||||||
|
bool search (char type, const std::string& name) const;
|
||||||
|
|
||||||
const std::vector<std::string>& get (char type) const;
|
const std::vector<std::string>& get (char type) const;
|
||||||
|
|
||||||
void write (std::ostream& localFile) const;
|
void write (std::ostream& localFile) const;
|
||||||
|
|
Loading…
Reference in a new issue