Merge pull request #939 from kpp/rewrite_esm_name_t

Rewrite ESM::NAME_T
This commit is contained in:
scrawl 2016-05-08 13:15:05 +02:00
commit a7e6219091
55 changed files with 255 additions and 118 deletions

View file

@ -357,10 +357,10 @@ int load(Arguments& info)
EsmTool::RecordBase *record = EsmTool::RecordBase::create(n); EsmTool::RecordBase *record = EsmTool::RecordBase::create(n);
if (record == 0) if (record == 0)
{ {
if (std::find(skipped.begin(), skipped.end(), n.val) == skipped.end()) if (std::find(skipped.begin(), skipped.end(), n.intval) == skipped.end())
{ {
std::cout << "Skipping " << n.toString() << " records." << std::endl; std::cout << "Skipping " << n.toString() << " records." << std::endl;
skipped.push_back(n.val); skipped.push_back(n.intval);
} }
esm.skipRecord(); esm.skipRecord();
@ -392,7 +392,7 @@ int load(Arguments& info)
record->print(); record->print();
} }
if (record->getType().val == ESM::REC_CELL && loadCells && interested) if (record->getType().intval == ESM::REC_CELL && loadCells && interested)
{ {
loadCell(record->cast<ESM::Cell>()->get(), esm, info); loadCell(record->cast<ESM::Cell>()->get(), esm, info);
} }
@ -405,7 +405,7 @@ int load(Arguments& info)
{ {
delete record; delete record;
} }
++info.data.mRecordStats[n.val]; ++info.data.mRecordStats[n.intval];
} }
} catch(std::exception &e) { } catch(std::exception &e) {
@ -448,14 +448,13 @@ int clone(Arguments& info)
std::cout << "Loaded " << recordCount << " records:" << std::endl << std::endl; std::cout << "Loaded " << recordCount << " records:" << std::endl << std::endl;
ESM::NAME name;
int i = 0; int i = 0;
typedef std::map<int, int> Stats; typedef std::map<int, int> Stats;
Stats &stats = info.data.mRecordStats; Stats &stats = info.data.mRecordStats;
for (Stats::iterator it = stats.begin(); it != stats.end(); ++it) for (Stats::iterator it = stats.begin(); it != stats.end(); ++it)
{ {
name.val = it->first; ESM::NAME name;
name.intval = it->first;
int amount = it->second; int amount = it->second;
std::cout << std::setw(digitCount) << amount << " " << name.toString() << " "; std::cout << std::setw(digitCount) << amount << " " << name.toString() << " ";
@ -488,12 +487,12 @@ int clone(Arguments& info)
for (Records::iterator it = records.begin(); it != records.end() && i > 0; ++it) for (Records::iterator it = records.begin(); it != records.end() && i > 0; ++it)
{ {
EsmTool::RecordBase *record = *it; EsmTool::RecordBase *record = *it;
name.val = record->getType().val; const ESM::NAME& typeName = record->getType();
esm.startRecord(name.toString(), record->getFlags()); esm.startRecord(typeName.toString(), record->getFlags());
record->save(esm); record->save(esm);
if (name.val == ESM::REC_CELL) { if (typeName.intval == ESM::REC_CELL) {
ESM::Cell *ptr = &record->cast<ESM::Cell>()->get(); ESM::Cell *ptr = &record->cast<ESM::Cell>()->get();
if (!info.data.mCellRefs[ptr].empty()) { if (!info.data.mCellRefs[ptr].empty()) {
typedef std::deque<std::pair<ESM::CellRef, bool> > RefList; typedef std::deque<std::pair<ESM::CellRef, bool> > RefList;
@ -505,7 +504,7 @@ int clone(Arguments& info)
} }
} }
esm.endRecord(name.toString()); esm.endRecord(typeName.toString());
saved++; saved++;
int perc = (int)((saved / (float)recordCount)*100); int perc = (int)((saved / (float)recordCount)*100);

View file

@ -179,7 +179,7 @@ RecordBase::create(ESM::NAME type)
{ {
RecordBase *record = 0; RecordBase *record = 0;
switch (type.val) { switch (type.intval) {
case ESM::REC_ACTI: case ESM::REC_ACTI:
{ {
record = new EsmTool::Record<ESM::Activator>; record = new EsmTool::Record<ESM::Activator>;

View file

@ -322,14 +322,14 @@ namespace ESSImport
ESM::NAME n = esm.getRecName(); ESM::NAME n = esm.getRecName();
esm.getRecHeader(); esm.getRecHeader();
std::map<unsigned int, boost::shared_ptr<Converter> >::iterator it = converters.find(n.val); std::map<unsigned int, boost::shared_ptr<Converter> >::iterator it = converters.find(n.intval);
if (it != converters.end()) if (it != converters.end())
{ {
it->second->read(esm); it->second->read(esm);
} }
else else
{ {
if (unknownRecords.insert(n.val).second) if (unknownRecords.insert(n.intval).second)
{ {
std::ios::fmtflags f(std::cerr.flags()); std::ios::fmtflags f(std::cerr.flags());
std::cerr << "unknown record " << n.toString() << " (0x" << std::hex << esm.getFileOffset() << ")" << std::endl; std::cerr << "unknown record " << n.toString() << " (0x" << std::hex << esm.getFileOffset() << ")" << std::endl;

View file

@ -942,7 +942,7 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Messages& messages)
bool unhandledRecord = false; bool unhandledRecord = false;
switch (n.val) switch (n.intval)
{ {
case ESM::REC_GLOB: mGlobals.load (*mReader, mBase); break; case ESM::REC_GLOB: mGlobals.load (*mReader, mBase); break;
case ESM::REC_GMST: mGmsts.load (*mReader, mBase); break; case ESM::REC_GMST: mGmsts.load (*mReader, mBase); break;

View file

@ -1187,7 +1187,7 @@ namespace CSMWorld
std::vector<ESM::ContItem>& list = container.mInventory.mList; std::vector<ESM::ContItem>& list = container.mInventory.mList;
ESM::ContItem newRow = {0, {""}}; ESM::ContItem newRow = ESM::ContItem();
if (position >= (int)list.size()) if (position >= (int)list.size())
list.push_back(newRow); list.push_back(newRow);

View file

@ -385,7 +385,7 @@ void MWState::StateManager::loadGame (const Character *character, const std::str
ESM::NAME n = reader.getRecName(); ESM::NAME n = reader.getRecName();
reader.getRecHeader(); reader.getRecHeader();
switch (n.val) switch (n.intval)
{ {
case ESM::REC_SAVE: case ESM::REC_SAVE:
{ {
@ -405,12 +405,12 @@ void MWState::StateManager::loadGame (const Character *character, const std::str
case ESM::REC_JOUR_LEGACY: case ESM::REC_JOUR_LEGACY:
case ESM::REC_QUES: case ESM::REC_QUES:
MWBase::Environment::get().getJournal()->readRecord (reader, n.val); MWBase::Environment::get().getJournal()->readRecord (reader, n.intval);
break; break;
case ESM::REC_DIAS: case ESM::REC_DIAS:
MWBase::Environment::get().getDialogueManager()->readRecord (reader, n.val); MWBase::Environment::get().getDialogueManager()->readRecord (reader, n.intval);
break; break;
case ESM::REC_ALCH: case ESM::REC_ALCH:
@ -433,7 +433,7 @@ void MWState::StateManager::loadGame (const Character *character, const std::str
case ESM::REC_ENAB: case ESM::REC_ENAB:
case ESM::REC_LEVC: case ESM::REC_LEVC:
case ESM::REC_LEVI: case ESM::REC_LEVI:
MWBase::Environment::get().getWorld()->readRecord(reader, n.val, contentFileMap); MWBase::Environment::get().getWorld()->readRecord(reader, n.intval, contentFileMap);
break; break;
case ESM::REC_CAM_: case ESM::REC_CAM_:
@ -442,7 +442,7 @@ void MWState::StateManager::loadGame (const Character *character, const std::str
case ESM::REC_GSCR: case ESM::REC_GSCR:
MWBase::Environment::get().getScriptManager()->getGlobalScripts().readRecord (reader, n.val); MWBase::Environment::get().getScriptManager()->getGlobalScripts().readRecord (reader, n.intval);
break; break;
case ESM::REC_GMAP: case ESM::REC_GMAP:
@ -450,13 +450,13 @@ void MWState::StateManager::loadGame (const Character *character, const std::str
case ESM::REC_ASPL: case ESM::REC_ASPL:
case ESM::REC_MARK: case ESM::REC_MARK:
MWBase::Environment::get().getWindowManager()->readRecord(reader, n.val); MWBase::Environment::get().getWindowManager()->readRecord(reader, n.intval);
break; break;
case ESM::REC_DCOU: case ESM::REC_DCOU:
case ESM::REC_STLN: case ESM::REC_STLN:
MWBase::Environment::get().getMechanicsManager()->readRecord(reader, n.val); MWBase::Environment::get().getMechanicsManager()->readRecord(reader, n.intval);
break; break;
default: default:

View file

@ -74,10 +74,10 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener)
esm.getRecHeader(); esm.getRecHeader();
// Look up the record type. // Look up the record type.
std::map<int, StoreBase *>::iterator it = mStores.find(n.val); std::map<int, StoreBase *>::iterator it = mStores.find(n.intval);
if (it == mStores.end()) { if (it == mStores.end()) {
if (n.val == ESM::REC_INFO) { if (n.intval == ESM::REC_INFO) {
if (dialogue) if (dialogue)
{ {
dialogue->readInfo(esm, esm.getIndex() != 0); dialogue->readInfo(esm, esm.getIndex() != 0);
@ -87,12 +87,12 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener)
std::cerr << "error: info record without dialog" << std::endl; std::cerr << "error: info record without dialog" << std::endl;
esm.skipRecord(); esm.skipRecord();
} }
} else if (n.val == ESM::REC_MGEF) { } else if (n.intval == ESM::REC_MGEF) {
mMagicEffects.load (esm); mMagicEffects.load (esm);
} else if (n.val == ESM::REC_SKIL) { } else if (n.intval == ESM::REC_SKIL) {
mSkills.load (esm); mSkills.load (esm);
} }
else if (n.val==ESM::REC_FILT || n.val == ESM::REC_DBGP) else if (n.intval==ESM::REC_FILT || n.intval == ESM::REC_DBGP)
{ {
// ignore project file only records // ignore project file only records
esm.skipRecord(); esm.skipRecord();
@ -110,7 +110,7 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener)
continue; continue;
} }
if (n.val==ESM::REC_DIAL) { if (n.intval==ESM::REC_DIAL) {
dialogue = const_cast<ESM::Dialogue*>(mDialogs.find(id.mId)); dialogue = const_cast<ESM::Dialogue*>(mDialogs.find(id.mId));
} else { } else {
dialogue = 0; dialogue = 0;

View file

@ -9,6 +9,8 @@ if (GTEST_FOUND)
mwworld/test_store.cpp mwworld/test_store.cpp
mwdialogue/test_keywordsearch.cpp mwdialogue/test_keywordsearch.cpp
esm/test_fixed_string.cpp
) )
source_group(apps\\openmw_test_suite FILES openmw_test_suite.cpp ${UNITTEST_SRC_FILES}) source_group(apps\\openmw_test_suite FILES openmw_test_suite.cpp ${UNITTEST_SRC_FILES})

View file

@ -0,0 +1,75 @@
#include <gtest/gtest.h>
#include "components/esm/esmcommon.hpp"
TEST(EsmFixedString, operator__eq_ne)
{
{
SCOPED_TRACE("asdc == asdc");
ESM::NAME name;
name.assign("asdc");
char s[4] = {'a', 's', 'd', 'c'};
std::string ss(s, 4);
EXPECT_TRUE(name == s);
EXPECT_TRUE(name == ss.c_str());
EXPECT_TRUE(name == ss);
}
{
SCOPED_TRACE("asdc == asdcx");
ESM::NAME name;
name.assign("asdc");
char s[5] = {'a', 's', 'd', 'c', 'x'};
std::string ss(s, 5);
EXPECT_TRUE(name != s);
EXPECT_TRUE(name != ss.c_str());
EXPECT_TRUE(name != ss);
}
{
SCOPED_TRACE("asdc == asdc[NULL]");
ESM::NAME name;
name.assign("asdc");
char s[5] = {'a', 's', 'd', 'c', '\0'};
std::string ss(s, 5);
EXPECT_TRUE(name == s);
EXPECT_TRUE(name == ss.c_str());
EXPECT_TRUE(name == ss);
}
}
TEST(EsmFixedString, empty_strings)
{
{
SCOPED_TRACE("4 bytes");
ESM::NAME empty = ESM::NAME();
EXPECT_TRUE(empty == "");
EXPECT_TRUE(empty == static_cast<uint32_t>(0));
EXPECT_TRUE(empty != "some string");
EXPECT_TRUE(empty != static_cast<uint32_t>(42));
}
{
SCOPED_TRACE("32 bytes");
ESM::NAME32 empty = ESM::NAME32();
EXPECT_TRUE(empty == "");
EXPECT_TRUE(empty != "some string");
}
}
TEST(EsmFixedString, struct_size)
{
ASSERT_EQ(4, sizeof(ESM::NAME));
ASSERT_EQ(32, sizeof(ESM::NAME32));
ASSERT_EQ(64, sizeof(ESM::NAME64));
ASSERT_EQ(256, sizeof(ESM::NAME256));
}
TEST(EsmFixedString, DISABLED_is_pod)
{
/* TODO: enable in C++11
* ASSERT_TRUE(std::is_pod<ESM::NAME>::value);
* ASSERT_TRUE(std::is_pod<ESM::NAME32>::value);
* ASSERT_TRUE(std::is_pod<ESM::NAME64>::value);
* ASSERT_TRUE(std::is_pod<ESM::NAME256>::value);
*/
}

View file

@ -62,7 +62,7 @@ void ESM::CellRef::loadData(ESMReader &esm, bool &isDeleted)
while (!isLoaded && esm.hasMoreSubs()) while (!isLoaded && esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::FourCC<'U','N','A','M'>::value: case ESM::FourCC<'U','N','A','M'>::value:
esm.getHT(mReferenceBlocked); esm.getHT(mReferenceBlocked);

View file

@ -13,7 +13,7 @@ void ESM::DebugProfile::load (ESMReader& esm, bool &isDeleted)
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -15,43 +15,98 @@ enum Version
VER_13 = 0x3fa66666 VER_13 = 0x3fa66666
}; };
/* A structure used for holding fixed-length strings. In the case of
LEN=4, it can be more efficient to match the string as a 32 bit // CRTP for FIXED_STRING class, a structure used for holding fixed-length strings
number, therefore the struct is implemented as a union with an int. template< template<size_t> class DERIVED, size_t SIZE>
*/ class FIXED_STRING_BASE
template <int LEN>
union NAME_T
{ {
char name[LEN]; /* The following methods must be implemented in derived classes:
uint32_t val; * char const* ro_data() const; // return pointer to ro buffer
* char* rw_data(); // return pointer to rw buffer
*/
public:
enum { size = SIZE };
bool operator==(const char *str) const template<size_t OTHER_SIZE>
{ bool operator==(char const (&str)[OTHER_SIZE]) const
for(int i=0; i<LEN; i++) {
if(name[i] != str[i]) return false; size_t other_len = strnlen(str, OTHER_SIZE);
else if(name[i] == 0) return true; if (other_len != this->length())
return str[LEN] == 0; return false;
} return std::strncmp(self()->ro_data(), str, size) == 0;
bool operator!=(const char *str) const { return !((*this)==str); } }
bool operator==(const char* const str) const
{
char const* const data = self()->ro_data();
for(size_t i = 0; i < size; ++i)
{
if(data[i] != str[i]) return false;
else if(data[i] == '\0') return true;
}
return str[size] == '\0';
}
bool operator!=(const char* const str) const { return !( (*this) == str ); }
bool operator==(const std::string &str) const bool operator==(const std::string& str) const
{ {
return (*this) == str.c_str(); return (*this) == str.c_str();
} }
bool operator!=(const std::string &str) const { return !((*this)==str); } bool operator!=(const std::string& str) const { return !( (*this) == str ); }
bool operator==(uint32_t v) const { return v == val; } size_t data_size() const { return size; }
bool operator!=(uint32_t v) const { return v != val; } size_t length() const { return strnlen(self()->ro_data(), size); }
std::string toString() const { return std::string(self()->ro_data(), this->length()); }
std::string toString() const { return std::string(name, strnlen(name, LEN)); } void assign(const std::string& value) { std::strncpy(self()->rw_data(), value.c_str(), size); }
void clear() { this->assign(""); }
private:
DERIVED<size> const* self() const
{
return static_cast<DERIVED<size> const*>(this);
}
void assign (const std::string& value) { std::strncpy (name, value.c_str(), LEN); } // write the non-const version in terms of the const version
// Effective C++ 3rd ed., Item 3 (p. 24-25)
DERIVED<size>* self()
{
return const_cast<DERIVED<size>*>(static_cast<FIXED_STRING_BASE const*>(this)->self());
}
}; };
typedef NAME_T<4> NAME; // Generic implementation
typedef NAME_T<32> NAME32; template <size_t SIZE>
typedef NAME_T<64> NAME64; struct FIXED_STRING : public FIXED_STRING_BASE<FIXED_STRING, SIZE>
typedef NAME_T<256> NAME256; {
char data[SIZE];
char const* ro_data() const { return data; }
char* rw_data() { return data; }
};
// In the case of SIZE=4, it can be more efficient to match the string
// as a 32 bit number, therefore the struct is implemented as a union with an int.
template <>
struct FIXED_STRING<4> : public FIXED_STRING_BASE<FIXED_STRING, 4>
{
union {
char data[4];
uint32_t intval;
};
using FIXED_STRING_BASE::operator==;
using FIXED_STRING_BASE::operator!=;
bool operator==(uint32_t v) const { return v == intval; }
bool operator!=(uint32_t v) const { return v != intval; }
char const* ro_data() const { return data; }
char* rw_data() { return data; }
};
typedef FIXED_STRING<4> NAME;
typedef FIXED_STRING<32> NAME32;
typedef FIXED_STRING<64> NAME64;
typedef FIXED_STRING<256> NAME256;
/* This struct defines a file 'context' which can be saved and later /* This struct defines a file 'context' which can be saved and later
restored by an ESMReader instance. It will save the position within restored by an ESMReader instance. It will save the position within

View file

@ -55,8 +55,8 @@ void ESMReader::close()
mCtx.leftRec = 0; mCtx.leftRec = 0;
mCtx.leftSub = 0; mCtx.leftSub = 0;
mCtx.subCached = false; mCtx.subCached = false;
mCtx.recName.val = 0; mCtx.recName.clear();
mCtx.subName.val = 0; mCtx.subName.clear();
} }
void ESMReader::openRaw(Files::IStreamPtr _esm, const std::string& name) void ESMReader::openRaw(Files::IStreamPtr _esm, const std::string& name)
@ -204,16 +204,18 @@ void ESMReader::getSubName()
} }
// reading the subrecord data anyway. // reading the subrecord data anyway.
getExact(mCtx.subName.name, 4); const size_t subNameSize = mCtx.subName.data_size();
mCtx.leftRec -= 4; getExact(mCtx.subName.rw_data(), subNameSize);
mCtx.leftRec -= subNameSize;
} }
bool ESMReader::isEmptyOrGetName() bool ESMReader::isEmptyOrGetName()
{ {
if (mCtx.leftRec) if (mCtx.leftRec)
{ {
getExact(mCtx.subName.name, 4); const size_t subNameSize = mCtx.subName.data_size();
mCtx.leftRec -= 4; getExact(mCtx.subName.rw_data(), subNameSize);
mCtx.leftRec -= subNameSize;
return false; return false;
} }
return true; return true;
@ -267,7 +269,7 @@ NAME ESMReader::getRecName()
if (!hasMoreRecs()) if (!hasMoreRecs())
fail("No more records, getRecName() failed"); fail("No more records, getRecName() failed");
getName(mCtx.recName); getName(mCtx.recName);
mCtx.leftFile -= 4; mCtx.leftFile -= mCtx.recName.data_size();
// Make sure we don't carry over any old cached subrecord // Make sure we don't carry over any old cached subrecord
// names. This can happen in some cases when we skip parts of a // names. This can happen in some cases when we skip parts of a

View file

@ -13,7 +13,7 @@ void ESM::Filter::load (ESMReader& esm, bool &isDeleted)
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
uint32_t name = esm.retSubName().val; uint32_t name = esm.retSubName().intval;
switch (name) switch (name)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:

View file

@ -16,7 +16,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -19,7 +19,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -49,7 +49,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -18,7 +18,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -69,7 +69,7 @@ namespace ESM
while (!isLoaded && esm.hasMoreSubs()) while (!isLoaded && esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mName = esm.getHString(); mName = esm.getHString();
@ -114,7 +114,7 @@ namespace ESM
while (!isLoaded && esm.hasMoreSubs()) while (!isLoaded && esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::FourCC<'I','N','T','V'>::value: case ESM::FourCC<'I','N','T','V'>::value:
int waterl; int waterl;

View file

@ -47,7 +47,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -19,7 +19,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -36,7 +36,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -30,7 +30,7 @@ namespace ESM {
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -28,7 +28,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::FourCC<'D','A','T','A'>::value: case ESM::FourCC<'D','A','T','A'>::value:
{ {

View file

@ -16,7 +16,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -18,7 +18,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -40,7 +40,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -35,7 +35,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::FourCC<'D','A','T','A'>::value: case ESM::FourCC<'D','A','T','A'>::value:
esm.getHT(mData, 12); esm.getHT(mData, 12);

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -94,7 +94,7 @@ namespace ESM
while (!isLoaded && esm.hasMoreSubs()) while (!isLoaded && esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::FourCC<'I','N','T','V'>::value: case ESM::FourCC<'I','N','T','V'>::value:
esm.getSubHeaderIs(8); esm.getSubHeaderIs(8);
@ -125,7 +125,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::FourCC<'V','N','M','L'>::value: case ESM::FourCC<'V','N','M','L'>::value:
esm.skipHSub(); esm.skipHSub();

View file

@ -15,7 +15,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -211,7 +211,7 @@ void MagicEffect::load(ESMReader &esm, bool &isDeleted)
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::FourCC<'I','T','E','X'>::value: case ESM::FourCC<'I','T','E','X'>::value:
mIcon = esm.getHString(); mIcon = esm.getHString();

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -26,7 +26,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -46,7 +46,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mCell = esm.getHString(); mCell = esm.getHString();

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -29,7 +29,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -16,7 +16,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();
@ -61,10 +61,12 @@ namespace ESM
esm.getHT(mMapColor); esm.getHT(mMapColor);
break; break;
case ESM::FourCC<'S','N','A','M'>::value: case ESM::FourCC<'S','N','A','M'>::value:
{
SoundRef sr; SoundRef sr;
esm.getHT(sr, 33); esm.getHT(sr, 33);
mSoundList.push_back(sr); mSoundList.push_back(sr);
break; break;
}
case ESM::SREC_DELE: case ESM::SREC_DELE:
esm.skipHSub(); esm.skipHSub();
isDeleted = true; isDeleted = true;

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -67,15 +67,17 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::FourCC<'S','C','H','D'>::value: case ESM::FourCC<'S','C','H','D'>::value:
{
SCHD data; SCHD data;
esm.getHT(data, 52); esm.getHT(data, 52);
mData = data.mData; mData = data.mData;
mId = data.mName.toString(); mId = data.mName.toString();
hasHeader = true; hasHeader = true;
break; break;
}
case ESM::FourCC<'S','C','V','R'>::value: case ESM::FourCC<'S','C','V','R'>::value:
// list of local variables // list of local variables
loadSCVR(esm); loadSCVR(esm);
@ -113,7 +115,7 @@ namespace ESM
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
data.mData = mData; data.mData = mData;
memcpy(data.mName.name, mId.c_str(), mId.size()); data.mName.assign(mId);
esm.writeHNT("SCHD", data, 52); esm.writeHNT("SCHD", data, 52);

View file

@ -138,7 +138,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::FourCC<'I','N','D','X'>::value: case ESM::FourCC<'I','N','D','X'>::value:
esm.getHT(mIndex); esm.getHT(mIndex);

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -19,7 +19,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -16,7 +16,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -9,8 +9,8 @@ void ESM::Header::blank()
{ {
mData.version = ESM::VER_13; mData.version = ESM::VER_13;
mData.type = 0; mData.type = 0;
mData.author.assign (""); mData.author.clear();
mData.desc.assign (""); mData.desc.clear();
mData.records = 0; mData.records = 0;
mFormat = CurrentFormat; mFormat = CurrentFormat;
mMaster.clear(); mMaster.clear();
@ -32,8 +32,8 @@ void ESM::Header::load (ESMReader &esm)
esm.getSubHeader(); esm.getSubHeader();
esm.getT(mData.version); esm.getT(mData.version);
esm.getT(mData.type); esm.getT(mData.type);
mData.author.assign(esm.getString(sizeof(mData.author.name))); mData.author.assign( esm.getString(mData.author.data_size()) );
mData.desc.assign(esm.getString(sizeof(mData.desc.name))); mData.desc.assign( esm.getString(mData.desc.data_size()) );
esm.getT(mData.records); esm.getT(mData.records);
} }
@ -73,8 +73,8 @@ void ESM::Header::save (ESMWriter &esm)
esm.startSubRecord("HEDR"); esm.startSubRecord("HEDR");
esm.writeT(mData.version); esm.writeT(mData.version);
esm.writeT(mData.type); esm.writeT(mData.type);
esm.writeFixedSizeString(mData.author.toString(), 32); esm.writeFixedSizeString(mData.author.toString(), mData.author.data_size());
esm.writeFixedSizeString(mData.desc.toString(), 256); esm.writeFixedSizeString(mData.desc.toString(), mData.desc.data_size());
esm.writeT(mData.records); esm.writeT(mData.records);
esm.endRecord("HEDR"); esm.endRecord("HEDR");

View file

@ -17,7 +17,7 @@ namespace ESM
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
{ {
esm.getSubName(); esm.getSubName();
switch (esm.retSubName().val) switch (esm.retSubName().intval)
{ {
case ESM::SREC_NAME: case ESM::SREC_NAME:
mId = esm.getHString(); mId = esm.getHString();

View file

@ -8,13 +8,13 @@ namespace ESM
void Transport::add(ESMReader &esm) void Transport::add(ESMReader &esm)
{ {
if (esm.retSubName().val == ESM::FourCC<'D','O','D','T'>::value) if (esm.retSubName().intval == ESM::FourCC<'D','O','D','T'>::value)
{ {
Dest dodt; Dest dodt;
esm.getHExact(&dodt.mPos, 24); esm.getHExact(&dodt.mPos, 24);
mList.push_back(dodt); mList.push_back(dodt);
} }
else if (esm.retSubName().val == ESM::FourCC<'D','N','A','M'>::value) else if (esm.retSubName().intval == ESM::FourCC<'D','N','A','M'>::value)
{ {
mList.back().mCellName = esm.getHString(); mList.back().mCellName = esm.getHString();
} }