mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 09:15:38 +00:00
In the interpretter, the id is no longer passed by vallue, but as a const reference instead.
In getMembersLocal(, a reference to a reference wrapper is used, because the id can change, bu all we need to do is change a pointer.No need to change the value
This commit is contained in:
parent
09d461a8cd
commit
874ff88288
4 changed files with 48 additions and 42 deletions
|
@ -44,7 +44,7 @@ namespace MWScript
|
|||
}
|
||||
}
|
||||
|
||||
const Locals& InterpreterContext::getMemberLocals(ESM::RefId& id, bool global) const
|
||||
const Locals& InterpreterContext::getMemberLocals(std::reference_wrapper<const ESM::RefId>& id, bool global) const
|
||||
{
|
||||
if (global)
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ namespace MWScript
|
|||
{
|
||||
const MWWorld::Ptr ptr = getReferenceImp(id, false);
|
||||
|
||||
id = ptr.getClass().getScript(ptr);
|
||||
id = std::ref(ptr.getClass().getScript(ptr));
|
||||
|
||||
ptr.getRefData().setLocals(*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find(id));
|
||||
|
||||
|
@ -62,7 +62,7 @@ namespace MWScript
|
|||
}
|
||||
}
|
||||
|
||||
Locals& InterpreterContext::getMemberLocals(ESM::RefId& id, bool global)
|
||||
Locals& InterpreterContext::getMemberLocals(std::reference_wrapper<const ESM::RefId>& id, bool global)
|
||||
{
|
||||
if (global)
|
||||
{
|
||||
|
@ -72,7 +72,7 @@ namespace MWScript
|
|||
{
|
||||
const MWWorld::Ptr ptr = getReferenceImp(id, false);
|
||||
|
||||
id = ptr.getClass().getScript(ptr);
|
||||
id = std::ref(ptr.getClass().getScript(ptr));
|
||||
|
||||
ptr.getRefData().setLocals(*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find(id));
|
||||
|
||||
|
@ -428,46 +428,52 @@ namespace MWScript
|
|||
}
|
||||
}
|
||||
|
||||
int InterpreterContext::getMemberShort(ESM::RefId id, std::string_view name, bool global) const
|
||||
int InterpreterContext::getMemberShort(const ESM::RefId& id, std::string_view name, bool global) const
|
||||
{
|
||||
const Locals& locals = getMemberLocals(id, global);
|
||||
auto idRefWrapper = std::ref(id);
|
||||
const Locals& locals = getMemberLocals(idRefWrapper, global);
|
||||
|
||||
return locals.mShorts[findLocalVariableIndex(id, name, 's')];
|
||||
return locals.mShorts[findLocalVariableIndex(idRefWrapper, name, 's')];
|
||||
}
|
||||
|
||||
int InterpreterContext::getMemberLong(ESM::RefId id, std::string_view name, bool global) const
|
||||
int InterpreterContext::getMemberLong(const ESM::RefId& id, std::string_view name, bool global) const
|
||||
{
|
||||
const Locals& locals = getMemberLocals(id, global);
|
||||
auto idRefWrapper = std::ref(id);
|
||||
const Locals& locals = getMemberLocals(idRefWrapper, global);
|
||||
|
||||
return locals.mLongs[findLocalVariableIndex(id, name, 'l')];
|
||||
return locals.mLongs[findLocalVariableIndex(idRefWrapper, name, 'l')];
|
||||
}
|
||||
|
||||
float InterpreterContext::getMemberFloat(ESM::RefId id, std::string_view name, bool global) const
|
||||
float InterpreterContext::getMemberFloat(const ESM::RefId& id, std::string_view name, bool global) const
|
||||
{
|
||||
const Locals& locals = getMemberLocals(id, global);
|
||||
auto idRefWrapper = std::ref(id);
|
||||
const Locals& locals = getMemberLocals(idRefWrapper, global);
|
||||
|
||||
return locals.mFloats[findLocalVariableIndex(id, name, 'f')];
|
||||
return locals.mFloats[findLocalVariableIndex(idRefWrapper, name, 'f')];
|
||||
}
|
||||
|
||||
void InterpreterContext::setMemberShort(ESM::RefId id, std::string_view name, int value, bool global)
|
||||
void InterpreterContext::setMemberShort(const ESM::RefId& id, std::string_view name, int value, bool global)
|
||||
{
|
||||
Locals& locals = getMemberLocals(id, global);
|
||||
auto idRefWrapper = std::ref(id);
|
||||
Locals& locals = getMemberLocals(idRefWrapper, global);
|
||||
|
||||
locals.mShorts[findLocalVariableIndex(id, name, 's')] = value;
|
||||
locals.mShorts[findLocalVariableIndex(idRefWrapper, name, 's')] = value;
|
||||
}
|
||||
|
||||
void InterpreterContext::setMemberLong(ESM::RefId id, std::string_view name, int value, bool global)
|
||||
void InterpreterContext::setMemberLong(const ESM::RefId& id, std::string_view name, int value, bool global)
|
||||
{
|
||||
Locals& locals = getMemberLocals(id, global);
|
||||
auto idRefWrapper = std::ref(id);
|
||||
Locals& locals = getMemberLocals(idRefWrapper, global);
|
||||
|
||||
locals.mLongs[findLocalVariableIndex(id, name, 'l')] = value;
|
||||
locals.mLongs[findLocalVariableIndex(idRefWrapper, name, 'l')] = value;
|
||||
}
|
||||
|
||||
void InterpreterContext::setMemberFloat(ESM::RefId id, std::string_view name, float value, bool global)
|
||||
void InterpreterContext::setMemberFloat(const ESM::RefId& id, std::string_view name, float value, bool global)
|
||||
{
|
||||
Locals& locals = getMemberLocals(id, global);
|
||||
auto idRefWrapper = std::ref(id);
|
||||
Locals& locals = getMemberLocals(idRefWrapper, global);
|
||||
|
||||
locals.mFloats[findLocalVariableIndex(id, name, 'f')] = value;
|
||||
locals.mFloats[findLocalVariableIndex(idRefWrapper, name, 'f')] = value;
|
||||
}
|
||||
|
||||
MWWorld::Ptr InterpreterContext::getReference(bool required) const
|
||||
|
|
|
@ -32,10 +32,10 @@ namespace MWScript
|
|||
const MWWorld::Ptr getReferenceImp(
|
||||
const ESM::RefId& id = ESM::RefId::sEmpty, bool activeOnly = false, bool doThrow = true) const;
|
||||
|
||||
const Locals& getMemberLocals(ESM::RefId& id, bool global) const;
|
||||
const Locals& getMemberLocals(std::reference_wrapper<const ESM::RefId>& id, bool global) const;
|
||||
///< \a id is changed to the respective script ID, if \a id wasn't a script ID before
|
||||
|
||||
Locals& getMemberLocals(ESM::RefId& id, bool global);
|
||||
Locals& getMemberLocals(std::reference_wrapper<const ESM::RefId>& id, bool global);
|
||||
///< \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.
|
||||
|
@ -113,17 +113,17 @@ namespace MWScript
|
|||
void executeActivation(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor);
|
||||
///< Execute the activation action for this ptr. If ptr is mActivated, mark activation as handled.
|
||||
|
||||
int getMemberShort(ESM::RefId id, std::string_view name, bool global) const override;
|
||||
int getMemberShort(const ESM::RefId& id, std::string_view name, bool global) const override;
|
||||
|
||||
int getMemberLong(ESM::RefId id, std::string_view name, bool global) const override;
|
||||
int getMemberLong(const ESM::RefId& id, std::string_view name, bool global) const override;
|
||||
|
||||
float getMemberFloat(ESM::RefId id, std::string_view name, bool global) const override;
|
||||
float getMemberFloat(const ESM::RefId& id, std::string_view name, bool global) const override;
|
||||
|
||||
void setMemberShort(ESM::RefId id, std::string_view name, int value, bool global) override;
|
||||
void setMemberShort(const ESM::RefId& id, std::string_view name, int value, bool global) override;
|
||||
|
||||
void setMemberLong(ESM::RefId id, std::string_view name, int value, bool global) override;
|
||||
void setMemberLong(const ESM::RefId& id, std::string_view name, int value, bool global) override;
|
||||
|
||||
void setMemberFloat(ESM::RefId id, std::string_view name, float value, bool global) override;
|
||||
void setMemberFloat(const ESM::RefId& id, std::string_view name, float value, bool global) override;
|
||||
|
||||
MWWorld::Ptr getReference(bool required = true) const;
|
||||
///< Reference, that the script is running from (can be empty)
|
||||
|
|
|
@ -207,7 +207,7 @@ namespace
|
|||
|
||||
std::string_view getCurrentCellName() const override { return {}; }
|
||||
|
||||
int getMemberShort(const ESM::RefId id, std::string_view name, bool global) const override
|
||||
int getMemberShort(const ESM::RefId& id, std::string_view name, bool global) const override
|
||||
{
|
||||
auto it = mMembers.find(id.getRefIdString());
|
||||
if (it != mMembers.end())
|
||||
|
@ -215,7 +215,7 @@ namespace
|
|||
return {};
|
||||
}
|
||||
|
||||
int getMemberLong(const ESM::RefId id, std::string_view name, bool global) const override
|
||||
int getMemberLong(const ESM::RefId& id, std::string_view name, bool global) const override
|
||||
{
|
||||
auto it = mMembers.find(id.getRefIdString());
|
||||
if (it != mMembers.end())
|
||||
|
@ -223,7 +223,7 @@ namespace
|
|||
return {};
|
||||
}
|
||||
|
||||
float getMemberFloat(const ESM::RefId id, std::string_view name, bool global) const override
|
||||
float getMemberFloat(const ESM::RefId& id, std::string_view name, bool global) const override
|
||||
{
|
||||
auto it = mMembers.find(id.getRefIdString());
|
||||
if (it != mMembers.end())
|
||||
|
@ -231,17 +231,17 @@ namespace
|
|||
return {};
|
||||
}
|
||||
|
||||
void setMemberShort(const ESM::RefId id, std::string_view name, int value, bool global) override
|
||||
void setMemberShort(const ESM::RefId& id, std::string_view name, int value, bool global) override
|
||||
{
|
||||
mMembers[id.getRefIdString()].setShort(name, value);
|
||||
};
|
||||
|
||||
void setMemberLong(const ESM::RefId id, std::string_view name, int value, bool global) override
|
||||
void setMemberLong(const ESM::RefId& id, std::string_view name, int value, bool global) override
|
||||
{
|
||||
mMembers[id.getRefIdString()].setLong(name, value);
|
||||
};
|
||||
|
||||
void setMemberFloat(const ESM::RefId id, std::string_view name, float value, bool global) override
|
||||
void setMemberFloat(const ESM::RefId& id, std::string_view name, float value, bool global) override
|
||||
{
|
||||
mMembers[id.getRefIdString()].setFloat(name, value);
|
||||
};
|
||||
|
|
|
@ -79,17 +79,17 @@ namespace Interpreter
|
|||
|
||||
virtual std::string_view getCurrentCellName() const = 0;
|
||||
|
||||
virtual int getMemberShort(ESM::RefId id, std::string_view name, bool global) const = 0;
|
||||
virtual int getMemberShort(const ESM::RefId& id, std::string_view name, bool global) const = 0;
|
||||
|
||||
virtual int getMemberLong(ESM::RefId id, std::string_view name, bool global) const = 0;
|
||||
virtual int getMemberLong(const ESM::RefId& id, std::string_view name, bool global) const = 0;
|
||||
|
||||
virtual float getMemberFloat(ESM::RefId id, std::string_view name, bool global) const = 0;
|
||||
virtual float getMemberFloat(const ESM::RefId& id, std::string_view name, bool global) const = 0;
|
||||
|
||||
virtual void setMemberShort(ESM::RefId id, std::string_view name, int value, bool global) = 0;
|
||||
virtual void setMemberShort(const ESM::RefId& id, std::string_view name, int value, bool global) = 0;
|
||||
|
||||
virtual void setMemberLong(ESM::RefId id, std::string_view name, int value, bool global) = 0;
|
||||
virtual void setMemberLong(const ESM::RefId& id, std::string_view name, int value, bool global) = 0;
|
||||
|
||||
virtual void setMemberFloat(ESM::RefId id, std::string_view name, float value, bool global) = 0;
|
||||
virtual void setMemberFloat(const ESM::RefId& id, std::string_view name, float value, bool global) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue