added access to remote access of local variables of global scripts

actorid
Marc Zinnschlag 11 years ago
parent 3147aebf75
commit 3b990795c4

@ -19,9 +19,10 @@ char CSMWorld::ScriptContext::getGlobalType (const std::string& name) const
return ' '; return ' ';
} }
char CSMWorld::ScriptContext::getMemberType (const std::string& name, const std::string& id) const std::pair<char, bool> CSMWorld::ScriptContext::getMemberType (const std::string& name,
const std::string& id) const
{ {
return ' '; return std::make_pair (' ', false);
} }
bool CSMWorld::ScriptContext::isId (const std::string& name) const bool CSMWorld::ScriptContext::isId (const std::string& name) const

@ -26,8 +26,12 @@ namespace CSMWorld
virtual char getGlobalType (const std::string& name) const; virtual char getGlobalType (const std::string& name) const;
///< 'l: long, 's': short, 'f': float, ' ': does not exist. ///< 'l: long, 's': short, 'f': float, ' ': does not exist.
virtual char getMemberType (const std::string& name, const std::string& id) const; virtual std::pair<char, bool> getMemberType (const std::string& name,
///< 'l: long, 's': short, 'f': float, ' ': does not exist. const std::string& id) const;
///< Return type of member variable \a name in script \a id or in script of reference of
/// \a id
/// \return first: 'l: long, 's': short, 'f': float, ' ': does not exist.
/// second: true: script of reference
virtual bool isId (const std::string& name) const; virtual bool isId (const std::string& name) const;
///< Does \a name match an ID, that can be referenced? ///< Does \a name match an ID, that can be referenced?

@ -30,16 +30,31 @@ namespace MWScript
return MWBase::Environment::get().getWorld()->getGlobalVariableType (name); return MWBase::Environment::get().getWorld()->getGlobalVariableType (name);
} }
char CompilerContext::getMemberType (const std::string& name, const std::string& id) const std::pair<char, bool> CompilerContext::getMemberType (const std::string& name,
const std::string& id) const
{ {
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPtr (id, false); std::string script;
bool reference = false;
std::string script = MWWorld::Class::get (ptr).getScript (ptr); if (const ESM::Script *scriptRecord =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().search (id))
{
script = scriptRecord->mId;
}
else
{
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPtr (id, false);
if (script.empty()) script = MWWorld::Class::get (ptr).getScript (ptr);
return ' '; reference = true;
}
return MWBase::Environment::get().getScriptManager()->getLocals (script).getType (name); char type = ' ';
if (!script.empty())
type = MWBase::Environment::get().getScriptManager()->getLocals (script).getType (name);
return std::make_pair (type, reference);
} }
bool CompilerContext::isId (const std::string& name) const bool CompilerContext::isId (const std::string& name) const

@ -30,8 +30,12 @@ namespace MWScript
/// '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; virtual char getGlobalType (const std::string& name) const;
virtual char getMemberType (const std::string& name, const std::string& id) const; virtual std::pair<char, bool> getMemberType (const std::string& name,
///< 'l: long, 's': short, 'f': float, ' ': does not exist. const std::string& id) const;
///< Return type of member variable \a name in script \a id or in script of reference of
/// \a id
/// \return first: 'l: long, 's': short, 'f': float, ' ': does not exist.
/// second: true: script of reference
virtual bool isId (const std::string& name) const; virtual bool isId (const std::string& name) const;
///< Does \a name match an ID, that can be referenced? ///< Does \a name match an ID, that can be referenced?

@ -148,4 +148,25 @@ namespace MWScript
return false; return false;
} }
Locals& GlobalScripts::getLocals (const std::string& name)
{
std::string name2 = Misc::StringUtils::lowerCase (name);
std::map<std::string, std::pair<bool, Locals> >::iterator iter =
mScripts.find (name2);
if (iter==mScripts.end())
{
if (const ESM::Script *script = mStore.get<ESM::Script>().find (name))
{
Locals locals;
locals.configure (*script);
iter = mScripts.insert (std::make_pair (name, std::make_pair (false, locals))).first;
}
}
return iter->second.second;
}
} }

@ -52,6 +52,10 @@ namespace MWScript
///< Records for variables that do not exist are dropped silently. ///< Records for variables that do not exist are dropped silently.
/// ///
/// \return Known type? /// \return Known type?
Locals& getLocals (const std::string& name);
///< 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.
}; };
} }

@ -54,6 +54,47 @@ namespace MWScript
} }
} }
const Locals& InterpreterContext::getMemberLocals (std::string& id, bool global)
const
{
if (global)
{
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().
getLocals (id);
}
else
{
const MWWorld::Ptr ptr = getReference (id, false);
std::string id = MWWorld::Class::get (ptr).getScript (ptr);
ptr.getRefData().setLocals (
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (id));
return ptr.getRefData().getLocals();
}
}
Locals& InterpreterContext::getMemberLocals (std::string& id, bool global)
{
if (global)
{
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().
getLocals (id);
}
else
{
const MWWorld::Ptr ptr = getReference (id, false);
std::string id = MWWorld::Class::get (ptr).getScript (ptr);
ptr.getRefData().setLocals (
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (id));
return ptr.getRefData().getLocals();
}
}
InterpreterContext::InterpreterContext ( InterpreterContext::InterpreterContext (
MWScript::Locals *locals, MWWorld::Ptr reference) MWScript::Locals *locals, MWWorld::Ptr reference)
: mLocals (locals), mReference (reference), : mLocals (locals), mReference (reference),
@ -407,82 +448,80 @@ namespace MWScript
MWBase::Environment::get().getWorld()->disable (ref); MWBase::Environment::get().getWorld()->disable (ref);
} }
int InterpreterContext::getMemberShort (const std::string& id, const std::string& name) const int InterpreterContext::getMemberShort (const std::string& id, const std::string& name,
bool global) const
{ {
const MWWorld::Ptr ptr = getReference (id, false); std::string scriptId (id);
std::string scriptId = MWWorld::Class::get (ptr).getScript (ptr); const Locals& locals = getMemberLocals (scriptId, global);
int index = MWBase::Environment::get().getScriptManager()->getLocalIndex (scriptId, name, 's'); int index = MWBase::Environment::get().getScriptManager()->getLocalIndex (
scriptId, name, 's');
ptr.getRefData().setLocals ( return locals.mShorts[index];
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (scriptId));
return ptr.getRefData().getLocals().mShorts[index];
} }
int InterpreterContext::getMemberLong (const std::string& id, const std::string& name) const int InterpreterContext::getMemberLong (const std::string& id, const std::string& name,
bool global) const
{ {
const MWWorld::Ptr ptr = getReference (id, false); std::string scriptId (id);
std::string scriptId = MWWorld::Class::get (ptr).getScript (ptr); const Locals& locals = getMemberLocals (scriptId, global);
int index = MWBase::Environment::get().getScriptManager()->getLocalIndex (scriptId, name, 'l'); int index = MWBase::Environment::get().getScriptManager()->getLocalIndex (
scriptId, name, 'l');
ptr.getRefData().setLocals ( return locals.mLongs[index];
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (scriptId));
return ptr.getRefData().getLocals().mLongs[index];
} }
float InterpreterContext::getMemberFloat (const std::string& id, const std::string& name) const float InterpreterContext::getMemberFloat (const std::string& id, const std::string& name,
bool global) const
{ {
const MWWorld::Ptr ptr = getReference (id, false); std::string scriptId (id);
std::string scriptId = MWWorld::Class::get (ptr).getScript (ptr); const Locals& locals = getMemberLocals (scriptId, global);
int index = MWBase::Environment::get().getScriptManager()->getLocalIndex (scriptId, name, 'f'); int index = MWBase::Environment::get().getScriptManager()->getLocalIndex (
scriptId, name, 'f');
ptr.getRefData().setLocals ( return locals.mFloats[index];
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (scriptId));
return ptr.getRefData().getLocals().mFloats[index];
} }
void InterpreterContext::setMemberShort (const std::string& id, const std::string& name, int value) void InterpreterContext::setMemberShort (const std::string& id, const std::string& name,
int value, bool global)
{ {
const MWWorld::Ptr ptr = getReference (id, false); std::string scriptId (id);
std::string scriptId = MWWorld::Class::get (ptr).getScript (ptr); Locals& locals = getMemberLocals (scriptId, global);
int index = MWBase::Environment::get().getScriptManager()->getLocalIndex (scriptId, name, 's'); int index =
MWBase::Environment::get().getScriptManager()->getLocalIndex (scriptId, name, 's');
ptr.getRefData().setLocals ( locals.mShorts[index] = value;
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (scriptId));
ptr.getRefData().getLocals().mShorts[index] = value;
} }
void InterpreterContext::setMemberLong (const std::string& id, const std::string& name, int value) void InterpreterContext::setMemberLong (const std::string& id, const std::string& name, int value, bool global)
{ {
const MWWorld::Ptr ptr = getReference (id, false); std::string scriptId (id);
std::string scriptId = MWWorld::Class::get (ptr).getScript (ptr); Locals& locals = getMemberLocals (scriptId, global);
int index = MWBase::Environment::get().getScriptManager()->getLocalIndex (scriptId, name, 'l'); int index =
MWBase::Environment::get().getScriptManager()->getLocalIndex (scriptId, name, 'l');
ptr.getRefData().setLocals ( locals.mLongs[index] = value;
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (scriptId));
ptr.getRefData().getLocals().mLongs[index] = value;
} }
void InterpreterContext::setMemberFloat (const std::string& id, const std::string& name, float value) void InterpreterContext::setMemberFloat (const std::string& id, const std::string& name, float value, bool global)
{ {
const MWWorld::Ptr ptr = getReference (id, false); std::string scriptId (id);
std::string scriptId = MWWorld::Class::get (ptr).getScript (ptr); Locals& locals = getMemberLocals (scriptId, global);
int index = MWBase::Environment::get().getScriptManager()->getLocalIndex (scriptId, name, 'f'); int index =
MWBase::Environment::get().getScriptManager()->getLocalIndex (scriptId, name, 'f');
ptr.getRefData().setLocals ( locals.mFloats[index] = value;
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (scriptId));
ptr.getRefData().getLocals().mFloats[index] = value;
} }
MWWorld::Ptr InterpreterContext::getReference(bool required) MWWorld::Ptr InterpreterContext::getReference(bool required)

@ -37,6 +37,12 @@ namespace MWScript
const MWWorld::Ptr getReference (const std::string& id, bool activeOnly, bool doThrow=true) const; const MWWorld::Ptr getReference (const std::string& id, bool activeOnly, bool doThrow=true) const;
const Locals& getMemberLocals (std::string& id, bool global) const;
///< \a id is changed to the respective script ID, if \a id wasn't a script ID before
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
public: public:
InterpreterContext (MWScript::Locals *locals, MWWorld::Ptr reference); InterpreterContext (MWScript::Locals *locals, MWWorld::Ptr reference);
@ -75,35 +81,35 @@ namespace MWScript
virtual void setGlobalLong (const std::string& name, int value); virtual void setGlobalLong (const std::string& name, int value);
virtual void setGlobalFloat (const std::string& name, float value); virtual void setGlobalFloat (const std::string& name, float value);
virtual std::vector<std::string> getGlobals () const; virtual std::vector<std::string> getGlobals () const;
virtual char getGlobalType (const std::string& name) const; virtual char getGlobalType (const std::string& name) const;
virtual std::string getActionBinding(const std::string& action) const; virtual std::string getActionBinding(const std::string& action) const;
virtual std::string getNPCName() const; virtual std::string getNPCName() const;
virtual std::string getNPCRace() const; virtual std::string getNPCRace() const;
virtual std::string getNPCClass() const; virtual std::string getNPCClass() const;
virtual std::string getNPCFaction() const; virtual std::string getNPCFaction() const;
virtual std::string getNPCRank() const; virtual std::string getNPCRank() const;
virtual std::string getPCName() const; virtual std::string getPCName() const;
virtual std::string getPCRace() const; virtual std::string getPCRace() const;
virtual std::string getPCClass() const; virtual std::string getPCClass() const;
virtual std::string getPCRank() const; virtual std::string getPCRank() const;
virtual std::string getPCNextRank() const; virtual std::string getPCNextRank() const;
virtual int getPCBounty() const; virtual int getPCBounty() const;
virtual std::string getCurrentCellName() const; virtual std::string getCurrentCellName() const;
virtual bool isScriptRunning (const std::string& name) const; virtual bool isScriptRunning (const std::string& name) const;
@ -138,17 +144,17 @@ namespace MWScript
virtual void disable (const std::string& id = ""); virtual void disable (const std::string& id = "");
virtual int getMemberShort (const std::string& id, const std::string& name) const; virtual int getMemberShort (const std::string& id, const std::string& name, bool global) const;
virtual int getMemberLong (const std::string& id, const std::string& name) const; virtual int getMemberLong (const std::string& id, const std::string& name, bool global) const;
virtual float getMemberFloat (const std::string& id, const std::string& name) const; virtual float getMemberFloat (const std::string& id, const std::string& name, bool global) const;
virtual void setMemberShort (const std::string& id, const std::string& name, int value); virtual void setMemberShort (const std::string& id, const std::string& name, int value, bool global);
virtual void setMemberLong (const std::string& id, const std::string& name, int value); virtual void setMemberLong (const std::string& id, const std::string& name, int value, bool global);
virtual void setMemberFloat (const std::string& id, const std::string& name, float value); virtual void setMemberFloat (const std::string& id, const std::string& name, float value, bool global);
MWWorld::Ptr getReference(bool required=true); MWWorld::Ptr getReference(bool required=true);
///< Reference, that the script is running from (can be empty) ///< Reference, that the script is running from (can be empty)

@ -33,8 +33,12 @@ namespace Compiler
virtual char getGlobalType (const std::string& name) const = 0; virtual char getGlobalType (const std::string& name) const = 0;
///< 'l: long, 's': short, 'f': float, ' ': does not exist. ///< 'l: long, 's': short, 'f': float, ' ': does not exist.
virtual char getMemberType (const std::string& name, const std::string& id) const = 0; virtual std::pair<char, bool> getMemberType (const std::string& name,
///< 'l: long, 's': short, 'f': float, ' ': does not exist. const std::string& id) const = 0;
///< Return type of member variable \a name in script \a id or in script of reference of
/// \a id
/// \return first: 'l: long, 's': short, 'f': float, ' ': does not exist.
/// second: true: script of reference
virtual bool isId (const std::string& name) const = 0; virtual bool isId (const std::string& name) const = 0;
///< Does \a name match an ID, that can be referenced? ///< Does \a name match an ID, that can be referenced?

@ -204,14 +204,15 @@ namespace Compiler
std::string name2 = Misc::StringUtils::lowerCase (name); std::string name2 = Misc::StringUtils::lowerCase (name);
std::string id = Misc::StringUtils::lowerCase (mExplicit); std::string id = Misc::StringUtils::lowerCase (mExplicit);
char type = getContext().getMemberType (name2, id); std::pair<char, bool> type = getContext().getMemberType (name2, id);
if (type!=' ') if (type.first!=' ')
{ {
Generator::fetchMember (mCode, mLiterals, type, name2, id); Generator::fetchMember (mCode, mLiterals, type.first, name2, id, !type.second);
mNextOperand = false; mNextOperand = false;
mExplicit.clear(); mExplicit.clear();
mOperands.push_back (type=='f' ? 'f' : 'l'); mOperands.push_back (type.first=='f' ? 'f' : 'l');
return true; return true;
} }

@ -260,34 +260,34 @@ namespace
code.push_back (Compiler::Generator::segment5 (44)); code.push_back (Compiler::Generator::segment5 (44));
} }
void opStoreMemberShort (Compiler::Generator::CodeContainer& code) void opStoreMemberShort (Compiler::Generator::CodeContainer& code, bool global)
{ {
code.push_back (Compiler::Generator::segment5 (59)); code.push_back (Compiler::Generator::segment5 (global ? 65 : 59));
} }
void opStoreMemberLong (Compiler::Generator::CodeContainer& code) void opStoreMemberLong (Compiler::Generator::CodeContainer& code, bool global)
{ {
code.push_back (Compiler::Generator::segment5 (60)); code.push_back (Compiler::Generator::segment5 (global ? 66 : 60));
} }
void opStoreMemberFloat (Compiler::Generator::CodeContainer& code) void opStoreMemberFloat (Compiler::Generator::CodeContainer& code, bool global)
{ {
code.push_back (Compiler::Generator::segment5 (61)); code.push_back (Compiler::Generator::segment5 (global ? 67 : 61));
} }
void opFetchMemberShort (Compiler::Generator::CodeContainer& code) void opFetchMemberShort (Compiler::Generator::CodeContainer& code, bool global)
{ {
code.push_back (Compiler::Generator::segment5 (62)); code.push_back (Compiler::Generator::segment5 (global ? 68 : 62));
} }
void opFetchMemberLong (Compiler::Generator::CodeContainer& code) void opFetchMemberLong (Compiler::Generator::CodeContainer& code, bool global)
{ {
code.push_back (Compiler::Generator::segment5 (63)); code.push_back (Compiler::Generator::segment5 (global ? 69 : 63));
} }
void opFetchMemberFloat (Compiler::Generator::CodeContainer& code) void opFetchMemberFloat (Compiler::Generator::CodeContainer& code, bool global)
{ {
code.push_back (Compiler::Generator::segment5 (64)); code.push_back (Compiler::Generator::segment5 (global ? 70 : 64));
} }
void opRandom (Compiler::Generator::CodeContainer& code) void opRandom (Compiler::Generator::CodeContainer& code)
@ -738,7 +738,8 @@ namespace Compiler
} }
void assignToMember (CodeContainer& code, Literals& literals, char localType, void assignToMember (CodeContainer& code, Literals& literals, char localType,
const std::string& name, const std::string& id, const CodeContainer& value, char valueType) const std::string& name, const std::string& id, const CodeContainer& value,
char valueType, bool global)
{ {
int index = literals.addString (name); int index = literals.addString (name);
@ -766,17 +767,17 @@ namespace Compiler
{ {
case 'f': case 'f':
opStoreMemberFloat (code); opStoreMemberFloat (code, global);
break; break;
case 's': case 's':
opStoreMemberShort (code); opStoreMemberShort (code, global);
break; break;
case 'l': case 'l':
opStoreMemberLong (code); opStoreMemberLong (code, global);
break; break;
default: default:
@ -786,7 +787,7 @@ namespace Compiler
} }
void fetchMember (CodeContainer& code, Literals& literals, char localType, void fetchMember (CodeContainer& code, Literals& literals, char localType,
const std::string& name, const std::string& id) const std::string& name, const std::string& id, bool global)
{ {
int index = literals.addString (name); int index = literals.addString (name);
@ -800,17 +801,17 @@ namespace Compiler
{ {
case 'f': case 'f':
opFetchMemberFloat (code); opFetchMemberFloat (code, global);
break; break;
case 's': case 's':
opFetchMemberShort (code); opFetchMemberShort (code, global);
break; break;
case 'l': case 'l':
opFetchMemberLong (code); opFetchMemberLong (code, global);
break; break;
default: default:

@ -102,10 +102,12 @@ namespace Compiler
const std::string& name); const std::string& name);
void assignToMember (CodeContainer& code, Literals& literals, char memberType, void assignToMember (CodeContainer& code, Literals& literals, char memberType,
const std::string& name, const std::string& id, const CodeContainer& value, char valueType); const std::string& name, const std::string& id, const CodeContainer& value, char valueType, bool global);
///< \param global Member of a global script instead of a script of a reference.
void fetchMember (CodeContainer& code, Literals& literals, char memberType, void fetchMember (CodeContainer& code, Literals& literals, char memberType,
const std::string& name, const std::string& id); const std::string& name, const std::string& id, bool global);
///< \param global Member of a global script instead of a script of a reference.
void random (CodeContainer& code); void random (CodeContainer& code);

@ -113,12 +113,13 @@ namespace Compiler
if (mState==SetMemberVarState) if (mState==SetMemberVarState)
{ {
mMemberName = name; mMemberName = name;
char type = getContext().getMemberType (mMemberName, mName); std::pair<char, bool> type = getContext().getMemberType (mMemberName, mName);
if (type!=' ') if (type.first!=' ')
{ {
mState = SetMemberVarState2; mState = SetMemberVarState2;
mType = type; mType = type.first;
mReferenceMember = type.second;
return true; return true;
} }
@ -353,7 +354,8 @@ namespace Compiler
std::vector<Interpreter::Type_Code> code; std::vector<Interpreter::Type_Code> code;
char type = mExprParser.append (code); char type = mExprParser.append (code);
Generator::assignToMember (mCode, mLiterals, mType, mMemberName, mName, code, type); Generator::assignToMember (mCode, mLiterals, mType, mMemberName, mName, code, type,
!mReferenceMember);
mState = EndState; mState = EndState;
return true; return true;

@ -33,6 +33,7 @@ namespace Compiler
State mState; State mState;
std::string mName; std::string mName;
std::string mMemberName; std::string mMemberName;
bool mReferenceMember;
int mButtons; int mButtons;
std::string mExplicit; std::string mExplicit;
char mType; char mType;

@ -50,33 +50,33 @@ namespace Interpreter
virtual void setGlobalFloat (const std::string& name, float value) = 0; virtual void setGlobalFloat (const std::string& name, float value) = 0;
virtual std::vector<std::string> getGlobals () const = 0; virtual std::vector<std::string> getGlobals () const = 0;
virtual char getGlobalType (const std::string& name) const = 0; virtual char getGlobalType (const std::string& name) const = 0;
virtual std::string getActionBinding(const std::string& action) const = 0; virtual std::string getActionBinding(const std::string& action) const = 0;
virtual std::string getNPCName() const = 0; virtual std::string getNPCName() const = 0;
virtual std::string getNPCRace() const = 0; virtual std::string getNPCRace() const = 0;
virtual std::string getNPCClass() const = 0; virtual std::string getNPCClass() const = 0;
virtual std::string getNPCFaction() const = 0; virtual std::string getNPCFaction() const = 0;
virtual std::string getNPCRank() const = 0; virtual std::string getNPCRank() const = 0;
virtual std::string getPCName() const = 0; virtual std::string getPCName() const = 0;
virtual std::string getPCRace() const = 0; virtual std::string getPCRace() const = 0;
virtual std::string getPCClass() const = 0; virtual std::string getPCClass() const = 0;
virtual std::string getPCRank() const = 0; virtual std::string getPCRank() const = 0;
virtual std::string getPCNextRank() const = 0; virtual std::string getPCNextRank() const = 0;
virtual int getPCBounty() const = 0; virtual int getPCBounty() const = 0;
virtual std::string getCurrentCellName() const = 0; virtual std::string getCurrentCellName() const = 0;
virtual bool isScriptRunning (const std::string& name) const = 0; virtual bool isScriptRunning (const std::string& name) const = 0;
@ -96,17 +96,17 @@ namespace Interpreter
virtual void disable (const std::string& id = "") = 0; virtual void disable (const std::string& id = "") = 0;
virtual int getMemberShort (const std::string& id, const std::string& name) const = 0; virtual int getMemberShort (const std::string& id, const std::string& name, bool global) const = 0;
virtual int getMemberLong (const std::string& id, const std::string& name) const = 0; virtual int getMemberLong (const std::string& id, const std::string& name, bool global) const = 0;
virtual float getMemberFloat (const std::string& id, const std::string& name) const = 0; virtual float getMemberFloat (const std::string& id, const std::string& name, bool global) const = 0;
virtual void setMemberShort (const std::string& id, const std::string& name, int value) = 0; virtual void setMemberShort (const std::string& id, const std::string& name, int value, bool global) = 0;
virtual void setMemberLong (const std::string& id, const std::string& name, int value) = 0; virtual void setMemberLong (const std::string& id, const std::string& name, int value, bool global) = 0;
virtual void setMemberFloat (const std::string& id, const std::string& name, float value) virtual void setMemberFloat (const std::string& id, const std::string& name, float value, bool global)
= 0; = 0;
}; };
} }

@ -127,5 +127,11 @@ op 61: store stack[0] in member float stack[2] of object with ID stack[1]
op 62: replace stack[0] with member short stack[1] of object with ID stack[0] op 62: replace stack[0] with member short stack[1] of object with ID stack[0]
op 63: replace stack[0] with member short stack[1] of object with ID stack[0] op 63: replace stack[0] with member short stack[1] of object with ID stack[0]
op 64: replace stack[0] with member short stack[1] of object with ID stack[0] op 64: replace stack[0] with member short stack[1] of object with ID stack[0]
opcodes 65-33554431 unused op 65: store stack[0] in member short stack[2] of global script with ID stack[1]
op 66: store stack[0] in member long stack[2] of global script with ID stack[1]
op 67: store stack[0] in member float stack[2] of global script with ID stack[1]
op 68: replace stack[0] with member short stack[1] of global script with ID stack[0]
op 69: replace stack[0] with member short stack[1] of global script with ID stack[0]
op 70: replace stack[0] with member short stack[1] of global script with ID stack[0]
opcodes 71-33554431 unused
opcodes 33554432-67108863 reserved for extensions opcodes 33554432-67108863 reserved for extensions

@ -40,12 +40,18 @@ namespace Interpreter
interpreter.installSegment5 (42, new OpFetchGlobalShort); interpreter.installSegment5 (42, new OpFetchGlobalShort);
interpreter.installSegment5 (43, new OpFetchGlobalLong); interpreter.installSegment5 (43, new OpFetchGlobalLong);
interpreter.installSegment5 (44, new OpFetchGlobalFloat); interpreter.installSegment5 (44, new OpFetchGlobalFloat);
interpreter.installSegment5 (59, new OpStoreMemberShort); interpreter.installSegment5 (59, new OpStoreMemberShort (false));
interpreter.installSegment5 (60, new OpStoreMemberLong); interpreter.installSegment5 (60, new OpStoreMemberLong (false));
interpreter.installSegment5 (61, new OpStoreMemberFloat); interpreter.installSegment5 (61, new OpStoreMemberFloat (false));
interpreter.installSegment5 (62, new OpFetchMemberShort); interpreter.installSegment5 (62, new OpFetchMemberShort (false));
interpreter.installSegment5 (63, new OpFetchMemberLong); interpreter.installSegment5 (63, new OpFetchMemberLong (false));
interpreter.installSegment5 (64, new OpFetchMemberFloat); interpreter.installSegment5 (64, new OpFetchMemberFloat (false));
interpreter.installSegment5 (65, new OpStoreMemberShort (true));
interpreter.installSegment5 (66, new OpStoreMemberLong (true));
interpreter.installSegment5 (67, new OpStoreMemberFloat (true));
interpreter.installSegment5 (68, new OpFetchMemberShort (true));
interpreter.installSegment5 (69, new OpFetchMemberLong (true));
interpreter.installSegment5 (70, new OpFetchMemberFloat (true));
// math // math
interpreter.installSegment5 (9, new OpAddInt<Type_Integer>); interpreter.installSegment5 (9, new OpAddInt<Type_Integer>);

@ -208,8 +208,12 @@ namespace Interpreter
class OpStoreMemberShort : public Opcode0 class OpStoreMemberShort : public Opcode0
{ {
bool mGlobal;
public: public:
OpStoreMemberShort (bool global) : mGlobal (global) {}
virtual void execute (Runtime& runtime) virtual void execute (Runtime& runtime)
{ {
Type_Integer data = runtime[0].mInteger; Type_Integer data = runtime[0].mInteger;
@ -218,7 +222,7 @@ namespace Interpreter
index = runtime[2].mInteger; index = runtime[2].mInteger;
std::string variable = runtime.getStringLiteral (index); std::string variable = runtime.getStringLiteral (index);
runtime.getContext().setMemberShort (id, variable, data); runtime.getContext().setMemberShort (id, variable, data, mGlobal);
runtime.pop(); runtime.pop();
runtime.pop(); runtime.pop();
@ -228,8 +232,12 @@ namespace Interpreter
class OpStoreMemberLong : public Opcode0 class OpStoreMemberLong : public Opcode0
{ {
bool mGlobal;
public: public:
OpStoreMemberLong (bool global) : mGlobal (global) {}
virtual void execute (Runtime& runtime) virtual void execute (Runtime& runtime)
{ {
Type_Integer data = runtime[0].mInteger; Type_Integer data = runtime[0].mInteger;
@ -238,7 +246,7 @@ namespace Interpreter
index = runtime[2].mInteger; index = runtime[2].mInteger;
std::string variable = runtime.getStringLiteral (index); std::string variable = runtime.getStringLiteral (index);
runtime.getContext().setMemberLong (id, variable, data); runtime.getContext().setMemberLong (id, variable, data, mGlobal);
runtime.pop(); runtime.pop();
runtime.pop(); runtime.pop();
@ -248,8 +256,12 @@ namespace Interpreter
class OpStoreMemberFloat : public Opcode0 class OpStoreMemberFloat : public Opcode0
{ {
bool mGlobal;
public: public:
OpStoreMemberFloat (bool global) : mGlobal (global) {}
virtual void execute (Runtime& runtime) virtual void execute (Runtime& runtime)
{ {
Type_Float data = runtime[0].mFloat; Type_Float data = runtime[0].mFloat;
@ -258,7 +270,7 @@ namespace Interpreter
index = runtime[2].mInteger; index = runtime[2].mInteger;
std::string variable = runtime.getStringLiteral (index); std::string variable = runtime.getStringLiteral (index);
runtime.getContext().setMemberFloat (id, variable, data); runtime.getContext().setMemberFloat (id, variable, data, mGlobal);
runtime.pop(); runtime.pop();
runtime.pop(); runtime.pop();
@ -268,8 +280,12 @@ namespace Interpreter
class OpFetchMemberShort : public Opcode0 class OpFetchMemberShort : public Opcode0
{ {
bool mGlobal;
public: public:
OpFetchMemberShort (bool global) : mGlobal (global) {}
virtual void execute (Runtime& runtime) virtual void execute (Runtime& runtime)
{ {
Type_Integer index = runtime[0].mInteger; Type_Integer index = runtime[0].mInteger;
@ -278,15 +294,19 @@ namespace Interpreter
std::string variable = runtime.getStringLiteral (index); std::string variable = runtime.getStringLiteral (index);
runtime.pop(); runtime.pop();
int value = runtime.getContext().getMemberShort (id, variable); int value = runtime.getContext().getMemberShort (id, variable, mGlobal);
runtime[0].mInteger = value; runtime[0].mInteger = value;
} }
}; };
class OpFetchMemberLong : public Opcode0 class OpFetchMemberLong : public Opcode0
{ {
bool mGlobal;
public: public:
OpFetchMemberLong (bool global) : mGlobal (global) {}
virtual void execute (Runtime& runtime) virtual void execute (Runtime& runtime)
{ {
Type_Integer index = runtime[0].mInteger; Type_Integer index = runtime[0].mInteger;
@ -295,15 +315,19 @@ namespace Interpreter
std::string variable = runtime.getStringLiteral (index); std::string variable = runtime.getStringLiteral (index);
runtime.pop(); runtime.pop();
int value = runtime.getContext().getMemberLong (id, variable); int value = runtime.getContext().getMemberLong (id, variable, mGlobal);
runtime[0].mInteger = value; runtime[0].mInteger = value;
} }
}; };
class OpFetchMemberFloat : public Opcode0 class OpFetchMemberFloat : public Opcode0
{ {
bool mGlobal;
public: public:
OpFetchMemberFloat (bool global) : mGlobal (global) {}
virtual void execute (Runtime& runtime) virtual void execute (Runtime& runtime)
{ {
Type_Integer index = runtime[0].mInteger; Type_Integer index = runtime[0].mInteger;
@ -312,7 +336,7 @@ namespace Interpreter
std::string variable = runtime.getStringLiteral (index); std::string variable = runtime.getStringLiteral (index);
runtime.pop(); runtime.pop();
float value = runtime.getContext().getMemberFloat (id, variable); float value = runtime.getContext().getMemberFloat (id, variable, mGlobal);
runtime[0].mFloat = value; runtime[0].mFloat = value;
} }
}; };

Loading…
Cancel
Save