forked from teamnwah/openmw-tes3coop
changed global variable records to new variant type
This commit is contained in:
parent
65081f5520
commit
a1ac20c6f3
6 changed files with 22 additions and 62 deletions
|
@ -713,9 +713,7 @@ void Record<ESM::Faction>::print()
|
|||
template<>
|
||||
void Record<ESM::Global>::print()
|
||||
{
|
||||
// nothing to print (well, nothing that's correct anyway)
|
||||
std::cout << " Type: " << mData.mType << std::endl;
|
||||
std::cout << " Value: " << mData.mValue << std::endl;
|
||||
std::cout << " " << mData.mValue << std::endl;
|
||||
}
|
||||
|
||||
template<>
|
||||
|
|
|
@ -154,8 +154,7 @@ void CSMDoc::Document::addOptionalGlobals()
|
|||
{
|
||||
ESM::Global global;
|
||||
global.mId = sGlobals[i];
|
||||
global.mType = ESM::VT_Int;
|
||||
global.mValue = 0;
|
||||
global.mValue.setType (ESM::VT_Int);
|
||||
addOptionalGlobal (global);
|
||||
}
|
||||
}
|
||||
|
@ -192,9 +191,14 @@ void CSMDoc::Document::createBase()
|
|||
for (int i=0; sGlobals[i]; ++i)
|
||||
{
|
||||
ESM::Global record;
|
||||
|
||||
record.mId = sGlobals[i];
|
||||
record.mValue = i==0 ? 1 : 0;
|
||||
record.mType = ESM::VT_Float;
|
||||
|
||||
record.mValue.setType (i==2 ? ESM::VT_Float : ESM::VT_Int);
|
||||
|
||||
if (i==0)
|
||||
record.mValue.setInteger (1);
|
||||
|
||||
getData().getGlobals().add (record);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,13 @@ namespace CSMWorld
|
|||
|
||||
virtual QVariant get (const Record<ESXRecordT>& record) const
|
||||
{
|
||||
return record.get().mValue;
|
||||
return record.get().mValue.getFloat();
|
||||
}
|
||||
|
||||
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
||||
{
|
||||
ESXRecordT record2 = record.get();
|
||||
record2.mValue = data.toFloat();
|
||||
record2.mValue.setFloat (data.toFloat());
|
||||
record.setModified (record2);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,27 +47,24 @@ namespace MWWorld
|
|||
char type = ' ';
|
||||
Data value;
|
||||
|
||||
switch (iter->mType)
|
||||
switch (iter->mValue.getType())
|
||||
{
|
||||
case ESM::VT_Short:
|
||||
|
||||
type = 's';
|
||||
value.mShort = *reinterpret_cast<const Interpreter::Type_Float *> (
|
||||
&iter->mValue);
|
||||
value.mShort = iter->mValue.getInteger();
|
||||
break;
|
||||
|
||||
case ESM::VT_Long:
|
||||
|
||||
type = 'l';
|
||||
value.mLong = *reinterpret_cast<const Interpreter::Type_Float *> (
|
||||
&iter->mValue);
|
||||
value.mLong = iter->mValue.getInteger();
|
||||
break;
|
||||
|
||||
case ESM::VT_Float:
|
||||
|
||||
type = 'f';
|
||||
value.mFloat = *reinterpret_cast<const Interpreter::Type_Float *> (
|
||||
&iter->mValue);
|
||||
value.mFloat = iter->mValue.getFloat();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -6,60 +6,23 @@
|
|||
namespace ESM
|
||||
{
|
||||
|
||||
void Global::load(ESMReader &esm)
|
||||
{
|
||||
std::string tmp = esm.getHNString("FNAM");
|
||||
if (tmp == "s")
|
||||
mType = VT_Short;
|
||||
else if (tmp == "l")
|
||||
mType = VT_Long;
|
||||
else if (tmp == "f")
|
||||
mType = VT_Float;
|
||||
else
|
||||
esm.fail("Illegal global variable type " + tmp);
|
||||
|
||||
// Note: Both floats and longs are represented as floats.
|
||||
esm.getHNT(mValue, "FLTV");
|
||||
|
||||
if (mType==VT_Short)
|
||||
void Global::load(ESMReader &esm)
|
||||
{
|
||||
if (mValue!=mValue)
|
||||
mValue = 0; // nan
|
||||
else
|
||||
mValue = static_cast<short> (mValue);
|
||||
mValue.read (esm, ESM::Variant::Format_Global);
|
||||
}
|
||||
}
|
||||
|
||||
void Global::save(ESMWriter &esm)
|
||||
{
|
||||
switch(mType)
|
||||
void Global::save(ESMWriter &esm)
|
||||
{
|
||||
case VT_Short:
|
||||
esm.writeHNString("FNAM", "s");
|
||||
break;
|
||||
|
||||
case VT_Long:
|
||||
esm.writeHNString("FNAM", "l");
|
||||
break;
|
||||
|
||||
case VT_Float:
|
||||
esm.writeHNString("FNAM", "f");
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
mValue.write (esm, ESM::Variant::Format_Global);
|
||||
}
|
||||
esm.writeHNT("FLTV", mValue);
|
||||
}
|
||||
|
||||
void Global::blank()
|
||||
{
|
||||
mValue = 0;
|
||||
mType = VT_Float;
|
||||
mValue.setType (ESM::VT_None);
|
||||
}
|
||||
|
||||
bool operator== (const Global& left, const Global& right)
|
||||
{
|
||||
return left.mId==right.mId && left.mValue==right.mValue && left.mType==right.mType;
|
||||
return left.mId==right.mId && left.mValue==right.mValue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "defs.hpp"
|
||||
#include "variant.hpp"
|
||||
|
||||
namespace ESM
|
||||
|
@ -19,8 +18,7 @@ class ESMWriter;
|
|||
struct Global
|
||||
{
|
||||
std::string mId;
|
||||
float mValue;
|
||||
VarType mType;
|
||||
Variant mValue;
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm);
|
||||
|
|
Loading…
Reference in a new issue