mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:23:52 +00:00
ESX variable type cleanup
This commit is contained in:
parent
955e2713a9
commit
a7102c143f
3 changed files with 37 additions and 37 deletions
|
@ -21,21 +21,21 @@ namespace MWWorld
|
||||||
Globals::Collection::const_iterator Globals::find (const std::string& name) const
|
Globals::Collection::const_iterator Globals::find (const std::string& name) const
|
||||||
{
|
{
|
||||||
Collection::const_iterator iter = mVariables.find (name);
|
Collection::const_iterator iter = mVariables.find (name);
|
||||||
|
|
||||||
if (iter==mVariables.end())
|
if (iter==mVariables.end())
|
||||||
throw std::runtime_error ("unknown global variable: " + name);
|
throw std::runtime_error ("unknown global variable: " + name);
|
||||||
|
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
Globals::Collection::iterator Globals::find (const std::string& name)
|
Globals::Collection::iterator Globals::find (const std::string& name)
|
||||||
{
|
{
|
||||||
Collection::iterator iter = mVariables.find (name);
|
Collection::iterator iter = mVariables.find (name);
|
||||||
|
|
||||||
if (iter==mVariables.end())
|
if (iter==mVariables.end())
|
||||||
throw std::runtime_error ("unknown global variable: " + name);
|
throw std::runtime_error ("unknown global variable: " + name);
|
||||||
|
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
Globals::Globals (const MWWorld::ESMStore& store)
|
Globals::Globals (const MWWorld::ESMStore& store)
|
||||||
|
@ -46,44 +46,44 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
char type = ' ';
|
char type = ' ';
|
||||||
Data value;
|
Data value;
|
||||||
|
|
||||||
switch (iter->mType)
|
switch (iter->mType)
|
||||||
{
|
{
|
||||||
case ESM::VT_Short:
|
case ESM::VT_Short:
|
||||||
|
|
||||||
type = 's';
|
type = 's';
|
||||||
value.mShort = *reinterpret_cast<const Interpreter::Type_Float *> (
|
value.mShort = *reinterpret_cast<const Interpreter::Type_Float *> (
|
||||||
&iter->mValue);
|
&iter->mValue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESM::VT_Int:
|
case ESM::VT_Long:
|
||||||
|
|
||||||
type = 'l';
|
type = 'l';
|
||||||
value.mLong = *reinterpret_cast<const Interpreter::Type_Float *> (
|
value.mLong = *reinterpret_cast<const Interpreter::Type_Float *> (
|
||||||
&iter->mValue);
|
&iter->mValue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESM::VT_Float:
|
case ESM::VT_Float:
|
||||||
|
|
||||||
type = 'f';
|
type = 'f';
|
||||||
value.mFloat = *reinterpret_cast<const Interpreter::Type_Float *> (
|
value.mFloat = *reinterpret_cast<const Interpreter::Type_Float *> (
|
||||||
&iter->mValue);
|
&iter->mValue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
throw std::runtime_error ("unsupported global variable type");
|
throw std::runtime_error ("unsupported global variable type");
|
||||||
}
|
}
|
||||||
|
|
||||||
mVariables.insert (std::make_pair (iter->mId, std::make_pair (type, value)));
|
mVariables.insert (std::make_pair (iter->mId, std::make_pair (type, value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mVariables.find ("dayspassed")==mVariables.end())
|
if (mVariables.find ("dayspassed")==mVariables.end())
|
||||||
{
|
{
|
||||||
// vanilla Morrowind does not define dayspassed.
|
// vanilla Morrowind does not define dayspassed.
|
||||||
Data value;
|
Data value;
|
||||||
value.mLong = 0;
|
value.mLong = 0;
|
||||||
|
|
||||||
mVariables.insert (std::make_pair ("dayspassed", std::make_pair ('l', value)));
|
mVariables.insert (std::make_pair ("dayspassed", std::make_pair ('l', value)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,31 +91,31 @@ namespace MWWorld
|
||||||
const Globals::Data& Globals::operator[] (const std::string& name) const
|
const Globals::Data& Globals::operator[] (const std::string& name) const
|
||||||
{
|
{
|
||||||
Collection::const_iterator iter = find (name);
|
Collection::const_iterator iter = find (name);
|
||||||
|
|
||||||
return iter->second.second;
|
return iter->second.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
Globals::Data& Globals::operator[] (const std::string& name)
|
Globals::Data& Globals::operator[] (const std::string& name)
|
||||||
{
|
{
|
||||||
Collection::iterator iter = find (name);
|
Collection::iterator iter = find (name);
|
||||||
|
|
||||||
return iter->second.second;
|
return iter->second.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Globals::setInt (const std::string& name, int value)
|
void Globals::setInt (const std::string& name, int value)
|
||||||
{
|
{
|
||||||
Collection::iterator iter = find (name);
|
Collection::iterator iter = find (name);
|
||||||
|
|
||||||
switch (iter->second.first)
|
switch (iter->second.first)
|
||||||
{
|
{
|
||||||
case 's': iter->second.second.mShort = value; break;
|
case 's': iter->second.second.mShort = value; break;
|
||||||
case 'l': iter->second.second.mLong = value; break;
|
case 'l': iter->second.second.mLong = value; break;
|
||||||
case 'f': iter->second.second.mFloat = value; break;
|
case 'f': iter->second.second.mFloat = value; break;
|
||||||
|
|
||||||
default: throw std::runtime_error ("unsupported global variable type");
|
default: throw std::runtime_error ("unsupported global variable type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Globals::setFloat (const std::string& name, float value)
|
void Globals::setFloat (const std::string& name, float value)
|
||||||
{
|
{
|
||||||
Collection::iterator iter = find (name);
|
Collection::iterator iter = find (name);
|
||||||
|
@ -127,9 +127,9 @@ namespace MWWorld
|
||||||
case 'f': iter->second.second.mFloat = value; break;
|
case 'f': iter->second.second.mFloat = value; break;
|
||||||
|
|
||||||
default: throw std::runtime_error ("unsupported global variable type");
|
default: throw std::runtime_error ("unsupported global variable type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Globals::getInt (const std::string& name) const
|
int Globals::getInt (const std::string& name) const
|
||||||
{
|
{
|
||||||
Collection::const_iterator iter = find (name);
|
Collection::const_iterator iter = find (name);
|
||||||
|
@ -141,13 +141,13 @@ namespace MWWorld
|
||||||
case 'f': return iter->second.second.mFloat;
|
case 'f': return iter->second.second.mFloat;
|
||||||
|
|
||||||
default: throw std::runtime_error ("unsupported global variable type");
|
default: throw std::runtime_error ("unsupported global variable type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float Globals::getFloat (const std::string& name) const
|
float Globals::getFloat (const std::string& name) const
|
||||||
{
|
{
|
||||||
Collection::const_iterator iter = find (name);
|
Collection::const_iterator iter = find (name);
|
||||||
|
|
||||||
switch (iter->second.first)
|
switch (iter->second.first)
|
||||||
{
|
{
|
||||||
case 's': return iter->second.second.mShort;
|
case 's': return iter->second.second.mShort;
|
||||||
|
@ -155,16 +155,16 @@ namespace MWWorld
|
||||||
case 'f': return iter->second.second.mFloat;
|
case 'f': return iter->second.second.mFloat;
|
||||||
|
|
||||||
default: throw std::runtime_error ("unsupported global variable type");
|
default: throw std::runtime_error ("unsupported global variable type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char Globals::getType (const std::string& name) const
|
char Globals::getType (const std::string& name) const
|
||||||
{
|
{
|
||||||
Collection::const_iterator iter = mVariables.find (name);
|
Collection::const_iterator iter = mVariables.find (name);
|
||||||
|
|
||||||
if (iter==mVariables.end())
|
if (iter==mVariables.end())
|
||||||
return ' ';
|
return ' ';
|
||||||
|
|
||||||
return iter->second.first;
|
return iter->second.first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ enum VarType
|
||||||
{
|
{
|
||||||
VT_Unknown,
|
VT_Unknown,
|
||||||
VT_None,
|
VT_None,
|
||||||
VT_Short,
|
VT_Short, // stored as a float, kinda
|
||||||
VT_Int,
|
VT_Int,
|
||||||
VT_Long,
|
VT_Long, // stored as a float
|
||||||
VT_Float,
|
VT_Float,
|
||||||
VT_String,
|
VT_String,
|
||||||
VT_Ignored
|
VT_Ignored
|
||||||
|
|
|
@ -12,7 +12,7 @@ void Global::load(ESMReader &esm)
|
||||||
if (tmp == "s")
|
if (tmp == "s")
|
||||||
mType = VT_Short;
|
mType = VT_Short;
|
||||||
else if (tmp == "l")
|
else if (tmp == "l")
|
||||||
mType = VT_Int;
|
mType = VT_Long;
|
||||||
else if (tmp == "f")
|
else if (tmp == "f")
|
||||||
mType = VT_Float;
|
mType = VT_Float;
|
||||||
else
|
else
|
||||||
|
@ -30,7 +30,7 @@ void Global::save(ESMWriter &esm)
|
||||||
esm.writeHNString("FNAM", "s");
|
esm.writeHNString("FNAM", "s");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VT_Int:
|
case VT_Long:
|
||||||
esm.writeHNString("FNAM", "l");
|
esm.writeHNString("FNAM", "l");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue