1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-19 22:53:53 +00:00
openmw/components/esm/loadglob.cpp

66 lines
1.2 KiB
C++
Raw Normal View History

#include "loadglob.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
2012-09-17 07:37:50 +00:00
namespace ESM
{
void Global::load(ESMReader &esm)
{
std::string tmp = esm.getHNString("FNAM");
if (tmp == "s")
2012-09-17 07:37:50 +00:00
mType = VT_Short;
else if (tmp == "l")
2013-02-26 13:33:05 +00:00
mType = VT_Long;
else if (tmp == "f")
2012-09-17 07:37:50 +00:00
mType = VT_Float;
else
esm.fail("Illegal global variable type " + tmp);
// Note: Both floats and longs are represented as floats.
2012-09-17 07:37:50 +00:00
esm.getHNT(mValue, "FLTV");
2013-02-28 10:50:29 +00:00
if (mType==VT_Short)
{
if (mValue!=mValue)
mValue = 0; // nan
else
mValue = static_cast<short> (mValue);
}
}
void Global::save(ESMWriter &esm)
{
2012-09-17 07:37:50 +00:00
switch(mType)
{
2012-09-17 07:37:50 +00:00
case VT_Short:
esm.writeHNString("FNAM", "s");
break;
2013-02-26 13:33:05 +00:00
case VT_Long:
2012-09-17 07:37:50 +00:00
esm.writeHNString("FNAM", "l");
break;
case VT_Float:
esm.writeHNString("FNAM", "f");
break;
default:
return;
}
2012-09-17 07:37:50 +00:00
esm.writeHNT("FLTV", mValue);
}
2012-12-03 21:16:02 +00:00
void Global::blank()
{
mValue = 0;
mType = VT_Float;
}
bool operator== (const Global& left, const Global& right)
{
return left.mId==right.mId && left.mValue==right.mValue && left.mType==right.mType;
}
}