From 926c825d0c7f0a373fb6bd22d88d0df850407f3c Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 7 Jul 2015 15:37:42 +0300 Subject: [PATCH 01/49] Add NAME and DELE handling to ESM records. Changed records are those where DELE is located after NAME sub-record. And DELE is the last sub-record. --- components/esm/loadacti.cpp | 15 +++++++++++++++ components/esm/loadacti.hpp | 2 ++ components/esm/loadalch.cpp | 16 ++++++++++++++++ components/esm/loadalch.hpp | 2 ++ components/esm/loadappa.cpp | 15 +++++++++++++++ components/esm/loadappa.hpp | 2 ++ components/esm/loadarmo.cpp | 16 ++++++++++++++++ components/esm/loadarmo.hpp | 2 ++ components/esm/loadbody.cpp | 16 ++++++++++++++++ components/esm/loadbody.hpp | 2 ++ components/esm/loadbook.cpp | 15 +++++++++++++++ components/esm/loadbook.hpp | 2 ++ components/esm/loadclas.cpp | 16 ++++++++++++++++ components/esm/loadclas.hpp | 2 ++ components/esm/loadclot.cpp | 16 ++++++++++++++++ components/esm/loadclot.hpp | 2 ++ components/esm/loadcont.cpp | 16 ++++++++++++++++ components/esm/loadcont.hpp | 2 ++ components/esm/loadcrea.cpp | 15 +++++++++++++++ components/esm/loadcrea.hpp | 3 ++- components/esm/loaddoor.cpp | 15 +++++++++++++++ components/esm/loaddoor.hpp | 2 ++ components/esm/loadench.cpp | 17 +++++++++++++++++ components/esm/loadench.hpp | 2 ++ components/esm/loadfact.cpp | 16 ++++++++++++++++ components/esm/loadfact.hpp | 2 ++ components/esm/loadingr.cpp | 16 ++++++++++++++++ components/esm/loadingr.hpp | 2 ++ components/esm/loadlevlist.cpp | 15 +++++++++++++++ components/esm/loadlevlist.hpp | 2 ++ components/esm/loadligh.cpp | 15 +++++++++++++++ components/esm/loadligh.hpp | 2 ++ components/esm/loadlock.cpp | 15 +++++++++++++++ components/esm/loadlock.hpp | 2 ++ components/esm/loadmisc.cpp | 15 +++++++++++++++ components/esm/loadmisc.hpp | 2 ++ components/esm/loadnpc.cpp | 15 +++++++++++++++ components/esm/loadnpc.hpp | 2 ++ components/esm/loadprob.cpp | 15 +++++++++++++++ components/esm/loadprob.hpp | 2 ++ components/esm/loadrepa.cpp | 15 +++++++++++++++ components/esm/loadrepa.hpp | 2 ++ components/esm/loadsndg.cpp | 15 +++++++++++++++ components/esm/loadsndg.hpp | 2 ++ components/esm/loadsoun.cpp | 16 ++++++++++++++++ components/esm/loadsoun.hpp | 2 ++ components/esm/loadspel.cpp | 17 +++++++++++++++++ components/esm/loadspel.hpp | 2 ++ components/esm/loadstat.cpp | 15 +++++++++++++++ components/esm/loadstat.hpp | 2 ++ components/esm/loadweap.cpp | 16 ++++++++++++++++ components/esm/loadweap.hpp | 2 ++ components/esm/util.cpp | 20 ++++++++++++++++++++ components/esm/util.hpp | 9 +++++++++ 54 files changed, 485 insertions(+), 1 deletion(-) create mode 100644 components/esm/util.cpp diff --git a/components/esm/loadacti.cpp b/components/esm/loadacti.cpp index b5adce550..295d35f7e 100644 --- a/components/esm/loadacti.cpp +++ b/components/esm/loadacti.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Activator::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + while (esm.hasMoreSubs()) { esm.getSubName(); @@ -32,6 +39,13 @@ namespace ESM } void Activator::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("SCRI", mScript); @@ -42,5 +56,6 @@ namespace ESM mName.clear(); mScript.clear(); mModel.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadacti.hpp b/components/esm/loadacti.hpp index d9a55023b..406512a22 100644 --- a/components/esm/loadacti.hpp +++ b/components/esm/loadacti.hpp @@ -17,6 +17,8 @@ struct Activator std::string mId, mName, mScript, mModel; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadalch.cpp b/components/esm/loadalch.cpp index 18db512c0..12078a5f7 100644 --- a/components/esm/loadalch.cpp +++ b/components/esm/loadalch.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -11,6 +12,13 @@ namespace ESM void Potion::load(ESMReader &esm) { mEffects.mList.clear(); + + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -46,6 +54,13 @@ namespace ESM } void Potion::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("TEXT", mIcon); esm.writeHNOCString("SCRI", mScript); @@ -64,5 +79,6 @@ namespace ESM mIcon.clear(); mScript.clear(); mEffects.mList.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadalch.hpp b/components/esm/loadalch.hpp index b90a7c448..3d1e6dee7 100644 --- a/components/esm/loadalch.hpp +++ b/components/esm/loadalch.hpp @@ -33,6 +33,8 @@ struct Potion std::string mId, mName, mModel, mIcon, mScript; EffectList mEffects; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadappa.cpp b/components/esm/loadappa.cpp index f2c82aacf..9107e5a8e 100644 --- a/components/esm/loadappa.cpp +++ b/components/esm/loadappa.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Apparatus::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -43,6 +50,13 @@ void Apparatus::load(ESMReader &esm) void Apparatus::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNCString("FNAM", mName); esm.writeHNT("AADT", mData, 16); @@ -60,5 +74,6 @@ void Apparatus::save(ESMWriter &esm) const mIcon.clear(); mScript.clear(); mName.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadappa.hpp b/components/esm/loadappa.hpp index f18b04648..62d8561a1 100644 --- a/components/esm/loadappa.hpp +++ b/components/esm/loadappa.hpp @@ -38,6 +38,8 @@ struct Apparatus AADTstruct mData; std::string mId, mModel, mIcon, mScript, mName; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadarmo.cpp b/components/esm/loadarmo.cpp index 066551d6f..626893d00 100644 --- a/components/esm/loadarmo.cpp +++ b/components/esm/loadarmo.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -41,6 +42,13 @@ namespace ESM void Armor::load(ESMReader &esm) { mParts.mParts.clear(); + + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -80,6 +88,13 @@ namespace ESM void Armor::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("SCRI", mScript); @@ -103,5 +118,6 @@ namespace ESM mIcon.clear(); mScript.clear(); mEnchant.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadarmo.hpp b/components/esm/loadarmo.hpp index 54416fd31..eb911254f 100644 --- a/components/esm/loadarmo.hpp +++ b/components/esm/loadarmo.hpp @@ -96,6 +96,8 @@ struct Armor std::string mId, mName, mModel, mIcon, mScript, mEnchant; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadbody.cpp b/components/esm/loadbody.cpp index ed24ded57..644eb3b50 100644 --- a/components/esm/loadbody.cpp +++ b/components/esm/loadbody.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -11,6 +12,12 @@ namespace ESM void BodyPart::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -38,6 +45,13 @@ void BodyPart::load(ESMReader &esm) } void BodyPart::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mRace); esm.writeHNT("BYDT", mData, 4); @@ -52,5 +66,7 @@ void BodyPart::save(ESMWriter &esm) const mModel.clear(); mRace.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadbody.hpp b/components/esm/loadbody.hpp index c48c31305..8e1e81f82 100644 --- a/components/esm/loadbody.hpp +++ b/components/esm/loadbody.hpp @@ -60,6 +60,8 @@ struct BodyPart BYDTstruct mData; std::string mId, mModel, mRace; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadbook.cpp b/components/esm/loadbook.cpp index 47f52fc31..aec361873 100644 --- a/components/esm/loadbook.cpp +++ b/components/esm/loadbook.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Book::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -48,6 +55,13 @@ namespace ESM } void Book::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("BKDT", mData, 20); @@ -70,5 +84,6 @@ namespace ESM mScript.clear(); mEnchant.clear(); mText.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadbook.hpp b/components/esm/loadbook.hpp index 6211b3e45..2f374c4b2 100644 --- a/components/esm/loadbook.hpp +++ b/components/esm/loadbook.hpp @@ -28,6 +28,8 @@ struct Book std::string mName, mModel, mIcon, mScript, mEnchant, mText; std::string mId; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadclas.cpp b/components/esm/loadclas.cpp index 66acaea72..df47a1a33 100644 --- a/components/esm/loadclas.cpp +++ b/components/esm/loadclas.cpp @@ -5,6 +5,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -41,6 +42,12 @@ namespace ESM void Class::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -69,6 +76,13 @@ namespace ESM } void Class::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNOCString("FNAM", mName); esm.writeHNT("CLDT", mData, 60); esm.writeHNOString("DESC", mDescription); @@ -87,5 +101,7 @@ namespace ESM for (int i=0; i<5; ++i) for (int i2=0; i2<2; ++i2) mData.mSkills[i][i2] = 0; + + mIsDeleted = false; } } diff --git a/components/esm/loadclas.hpp b/components/esm/loadclas.hpp index 972b48e88..b61913734 100644 --- a/components/esm/loadclas.hpp +++ b/components/esm/loadclas.hpp @@ -73,6 +73,8 @@ struct Class std::string mId, mName, mDescription; CLDTstruct mData; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadclot.cpp b/components/esm/loadclot.cpp index 5f49b5e70..1c73c4f21 100644 --- a/components/esm/loadclot.cpp +++ b/components/esm/loadclot.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -11,6 +12,13 @@ namespace ESM void Clothing::load(ESMReader &esm) { mParts.mParts.clear(); + + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -50,6 +58,13 @@ namespace ESM void Clothing::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("CTDT", mData, 12); @@ -74,5 +89,6 @@ namespace ESM mIcon.clear(); mEnchant.clear(); mScript.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadclot.hpp b/components/esm/loadclot.hpp index 6945f224a..8b4a8b3bb 100644 --- a/components/esm/loadclot.hpp +++ b/components/esm/loadclot.hpp @@ -48,6 +48,8 @@ struct Clothing std::string mId, mName, mModel, mIcon, mEnchant, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadcont.cpp b/components/esm/loadcont.cpp index 3481189c3..f54fe66e2 100644 --- a/components/esm/loadcont.cpp +++ b/components/esm/loadcont.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -27,6 +28,13 @@ namespace ESM void Container::load(ESMReader &esm) { mInventory.mList.clear(); + + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasWeight = false; bool hasFlags = false; while (esm.hasMoreSubs()) @@ -71,6 +79,13 @@ namespace ESM void Container::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("CNDT", mWeight, 4); @@ -89,5 +104,6 @@ namespace ESM mWeight = 0; mFlags = 0x8; // set default flag value mInventory.mList.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadcont.hpp b/components/esm/loadcont.hpp index ab587f935..51166b8d4 100644 --- a/components/esm/loadcont.hpp +++ b/components/esm/loadcont.hpp @@ -52,6 +52,8 @@ struct Container int mFlags; InventoryList mInventory; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index 50c47349c..6da32eed7 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -17,6 +18,12 @@ namespace ESM { mSpells.mList.clear(); mTransport.mList.clear(); + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + mScale = 1.f; mHasAI = false; bool hasNpdt = false; @@ -84,6 +91,13 @@ namespace ESM { void Creature::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("CNAM", mOriginal); esm.writeHNOCString("FNAM", mName); @@ -127,6 +141,7 @@ namespace ESM { mAiData.mServices = 0; mAiPackage.mList.clear(); mTransport.mList.clear(); + mIsDeleted = false; } const std::vector& Creature::getTransport() const diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index 47e5954a5..fb43f6272 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -91,12 +91,13 @@ struct Creature InventoryList mInventory; SpellList mSpells; - bool mHasAI; AIData mAiData; AIPackageList mAiPackage; Transport mTransport; + bool mIsDeleted; + const std::vector& getTransport() const; void load(ESMReader &esm); diff --git a/components/esm/loaddoor.cpp b/components/esm/loaddoor.cpp index f446eed61..6ee43fd1a 100644 --- a/components/esm/loaddoor.cpp +++ b/components/esm/loaddoor.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Door::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + while (esm.hasMoreSubs()) { esm.getSubName(); @@ -39,6 +46,13 @@ namespace ESM void Door::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("SCRI", mScript); @@ -53,5 +67,6 @@ namespace ESM mScript.clear(); mOpenSound.clear(); mCloseSound.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loaddoor.hpp b/components/esm/loaddoor.hpp index 3073f4e9d..b0326a744 100644 --- a/components/esm/loaddoor.hpp +++ b/components/esm/loaddoor.hpp @@ -17,6 +17,8 @@ struct Door std::string mId, mName, mModel, mScript, mOpenSound, mCloseSound; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadench.cpp b/components/esm/loadench.cpp index 54690d9a0..88d9e0f2e 100644 --- a/components/esm/loadench.cpp +++ b/components/esm/loadench.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -11,6 +12,13 @@ namespace ESM void Enchantment::load(ESMReader &esm) { mEffects.mList.clear(); + + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -36,6 +44,13 @@ void Enchantment::load(ESMReader &esm) void Enchantment::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNT("ENDT", mData, 16); mEffects.save(esm); } @@ -48,5 +63,7 @@ void Enchantment::save(ESMWriter &esm) const mData.mAutocalc = 0; mEffects.mList.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadench.hpp b/components/esm/loadench.hpp index cfcdd4edc..c9b19e31b 100644 --- a/components/esm/loadench.hpp +++ b/components/esm/loadench.hpp @@ -42,6 +42,8 @@ struct Enchantment ENDTstruct mData; EffectList mEffects; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadfact.cpp b/components/esm/loadfact.cpp index 006ca0ce0..9149c2a30 100644 --- a/components/esm/loadfact.cpp +++ b/components/esm/loadfact.cpp @@ -5,6 +5,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -32,6 +33,12 @@ void Faction::load(ESMReader &esm) for (int i=0;i<10;++i) mRanks[i].clear(); + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + int rankCounter=0; bool hasData = false; while (esm.hasMoreSubs()) @@ -71,6 +78,13 @@ void Faction::load(ESMReader &esm) } void Faction::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNOCString("FNAM", mName); for (int i = 0; i < 10; i++) @@ -109,5 +123,7 @@ void Faction::save(ESMWriter &esm) const mData.mSkills[i] = 0; mReactions.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadfact.hpp b/components/esm/loadfact.hpp index 8645e23fd..fec13b1ca 100644 --- a/components/esm/loadfact.hpp +++ b/components/esm/loadfact.hpp @@ -62,6 +62,8 @@ struct Faction // Name of faction ranks (may be empty for NPC factions) std::string mRanks[10]; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadingr.cpp b/components/esm/loadingr.cpp index 7e0cc3168..8bf0278f7 100644 --- a/components/esm/loadingr.cpp +++ b/components/esm/loadingr.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Ingredient::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -67,6 +74,13 @@ namespace ESM void Ingredient::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("IRDT", mData, 56); @@ -89,5 +103,7 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadingr.hpp b/components/esm/loadingr.hpp index 5846a9780..69a650180 100644 --- a/components/esm/loadingr.hpp +++ b/components/esm/loadingr.hpp @@ -31,6 +31,8 @@ struct Ingredient IRDTstruct mData; std::string mId, mName, mModel, mIcon, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadlevlist.cpp b/components/esm/loadlevlist.cpp index ca5c5d74d..c8cb110a6 100644 --- a/components/esm/loadlevlist.cpp +++ b/components/esm/loadlevlist.cpp @@ -3,12 +3,19 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { void LevelledListBase::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + esm.getHNT(mFlags, "DATA"); esm.getHNT(mChanceNone, "NNAM"); @@ -42,6 +49,13 @@ namespace ESM } void LevelledListBase::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNT("DATA", mFlags); esm.writeHNT("NNAM", mChanceNone); esm.writeHNT("INDX", mList.size()); @@ -58,6 +72,7 @@ namespace ESM mFlags = 0; mChanceNone = 0; mList.clear(); + mIsDeleted = false; } unsigned int CreatureLevList::sRecordId = REC_LEVC; diff --git a/components/esm/loadlevlist.hpp b/components/esm/loadlevlist.hpp index dc6fcda5e..4165275b2 100644 --- a/components/esm/loadlevlist.hpp +++ b/components/esm/loadlevlist.hpp @@ -36,6 +36,8 @@ struct LevelledListBase std::vector mList; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadligh.cpp b/components/esm/loadligh.cpp index 26d70d964..bd91e096c 100644 --- a/components/esm/loadligh.cpp +++ b/components/esm/loadligh.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Light::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -45,6 +52,13 @@ namespace ESM } void Light::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("ITEX", mIcon); @@ -66,5 +80,6 @@ namespace ESM mModel.clear(); mIcon.clear(); mName.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadligh.hpp b/components/esm/loadligh.hpp index ed8c36665..76274e6f4 100644 --- a/components/esm/loadligh.hpp +++ b/components/esm/loadligh.hpp @@ -47,6 +47,8 @@ struct Light std::string mSound, mScript, mModel, mIcon, mName, mId; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadlock.cpp b/components/esm/loadlock.cpp index 2747a6f78..c1e866b58 100644 --- a/components/esm/loadlock.cpp +++ b/components/esm/loadlock.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Lockpick::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = true; while (esm.hasMoreSubs()) { @@ -43,6 +50,13 @@ namespace ESM void Lockpick::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); @@ -61,5 +75,6 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadlock.hpp b/components/esm/loadlock.hpp index 0d678cd64..af18773ed 100644 --- a/components/esm/loadlock.hpp +++ b/components/esm/loadlock.hpp @@ -27,6 +27,8 @@ struct Lockpick Data mData; std::string mId, mName, mModel, mIcon, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadmisc.cpp b/components/esm/loadmisc.cpp index 81c094f2b..11d2f2a05 100644 --- a/components/esm/loadmisc.cpp +++ b/components/esm/loadmisc.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Miscellaneous::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -41,6 +48,13 @@ namespace ESM void Miscellaneous::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("MCDT", mData, 12); @@ -57,5 +71,6 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadmisc.hpp b/components/esm/loadmisc.hpp index 6e0b4e01b..5d5e9f66f 100644 --- a/components/esm/loadmisc.hpp +++ b/components/esm/loadmisc.hpp @@ -32,6 +32,8 @@ struct Miscellaneous std::string mId, mName, mModel, mIcon, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index 44d298785..280db0791 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -17,6 +18,12 @@ namespace ESM mTransport.mList.clear(); mAiPackage.mList.clear(); + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasNpdt = false; bool hasFlags = false; mHasAI = false; @@ -103,6 +110,13 @@ namespace ESM } void NPC::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNOCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNCString("RNAM", mRace); @@ -178,6 +192,7 @@ namespace ESM mScript.clear(); mHair.clear(); mHead.clear(); + mIsDeleted = false; } int NPC::getFactionRank() const diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index 9bda9560e..7b75cb178 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -130,6 +130,8 @@ struct NPC // body parts std::string mHair, mHead; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadprob.cpp b/components/esm/loadprob.cpp index c5f80c584..12f7ad00a 100644 --- a/components/esm/loadprob.cpp +++ b/components/esm/loadprob.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Probe::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = true; while (esm.hasMoreSubs()) { @@ -43,6 +50,13 @@ namespace ESM void Probe::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); @@ -61,5 +75,6 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadprob.hpp b/components/esm/loadprob.hpp index c737757aa..9daab6b1b 100644 --- a/components/esm/loadprob.hpp +++ b/components/esm/loadprob.hpp @@ -27,6 +27,8 @@ struct Probe Data mData; std::string mId, mName, mModel, mIcon, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadrepa.cpp b/components/esm/loadrepa.cpp index f90f9e39d..608536f02 100644 --- a/components/esm/loadrepa.cpp +++ b/components/esm/loadrepa.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Repair::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = true; while (esm.hasMoreSubs()) { @@ -43,6 +50,13 @@ void Repair::load(ESMReader &esm) void Repair::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); @@ -61,5 +75,6 @@ void Repair::save(ESMWriter &esm) const mModel.clear(); mIcon.clear(); mScript.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadrepa.hpp b/components/esm/loadrepa.hpp index e765bc93a..a660574be 100644 --- a/components/esm/loadrepa.hpp +++ b/components/esm/loadrepa.hpp @@ -27,6 +27,8 @@ struct Repair Data mData; std::string mId, mName, mModel, mIcon, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadsndg.cpp b/components/esm/loadsndg.cpp index 5ee6f5245..f92c4eee8 100644 --- a/components/esm/loadsndg.cpp +++ b/components/esm/loadsndg.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void SoundGenerator::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -36,6 +43,13 @@ namespace ESM } void SoundGenerator::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNT("DATA", mType, 4); esm.writeHNOCString("CNAM", mCreature); esm.writeHNOCString("SNAM", mSound); @@ -46,5 +60,6 @@ namespace ESM mType = LeftFoot; mCreature.clear(); mSound.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadsndg.hpp b/components/esm/loadsndg.hpp index 056958f0a..e486976f5 100644 --- a/components/esm/loadsndg.hpp +++ b/components/esm/loadsndg.hpp @@ -36,6 +36,8 @@ struct SoundGenerator std::string mId, mCreature, mSound; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadsoun.cpp b/components/esm/loadsoun.cpp index 690c1b448..19e8a5d80 100644 --- a/components/esm/loadsoun.cpp +++ b/components/esm/loadsoun.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Sound::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -34,6 +41,13 @@ namespace ESM void Sound::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNOCString("FNAM", mSound); esm.writeHNT("DATA", mData, 3); } @@ -45,5 +59,7 @@ namespace ESM mData.mVolume = 128; mData.mMinRange = 0; mData.mMaxRange = 255; + + mIsDeleted = false; } } diff --git a/components/esm/loadsoun.hpp b/components/esm/loadsoun.hpp index ff2202ca7..95c89b29d 100644 --- a/components/esm/loadsoun.hpp +++ b/components/esm/loadsoun.hpp @@ -23,6 +23,8 @@ struct Sound SOUNstruct mData; std::string mId, mSound; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadspel.cpp b/components/esm/loadspel.cpp index 96c048e0a..cac06b200 100644 --- a/components/esm/loadspel.cpp +++ b/components/esm/loadspel.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -11,6 +12,13 @@ namespace ESM void Spell::load(ESMReader &esm) { mEffects.mList.clear(); + + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -39,6 +47,13 @@ namespace ESM void Spell::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNOCString("FNAM", mName); esm.writeHNT("SPDT", mData, 12); mEffects.save(esm); @@ -53,5 +68,7 @@ namespace ESM mName.clear(); mEffects.mList.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadspel.hpp b/components/esm/loadspel.hpp index 491da1d17..2aba131ad 100644 --- a/components/esm/loadspel.hpp +++ b/components/esm/loadspel.hpp @@ -45,6 +45,8 @@ struct Spell std::string mId, mName; EffectList mEffects; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadstat.cpp b/components/esm/loadstat.cpp index b0ab89bed..a49caba89 100644 --- a/components/esm/loadstat.cpp +++ b/components/esm/loadstat.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,15 +11,29 @@ namespace ESM void Static::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + mModel = esm.getHNString("MODL"); } void Static::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); } void Static::blank() { mModel.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadstat.hpp b/components/esm/loadstat.hpp index aa4fe67b8..c4306ad8f 100644 --- a/components/esm/loadstat.hpp +++ b/components/esm/loadstat.hpp @@ -28,6 +28,8 @@ struct Static std::string mId, mModel; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadweap.cpp b/components/esm/loadweap.cpp index 981a5815a..66d65d0f5 100644 --- a/components/esm/loadweap.cpp +++ b/components/esm/loadweap.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Weapon::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -45,6 +52,13 @@ namespace ESM } void Weapon::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("WPDT", mData, 32); @@ -72,5 +86,7 @@ namespace ESM mIcon.clear(); mEnchant.clear(); mScript.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadweap.hpp b/components/esm/loadweap.hpp index f66e9f3a6..30dfbc92a 100644 --- a/components/esm/loadweap.hpp +++ b/components/esm/loadweap.hpp @@ -69,6 +69,8 @@ struct Weapon std::string mId, mName, mModel, mIcon, mEnchant, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/util.cpp b/components/esm/util.cpp new file mode 100644 index 000000000..c20bd4d51 --- /dev/null +++ b/components/esm/util.cpp @@ -0,0 +1,20 @@ +#include "util.hpp" + +namespace ESM +{ + bool readDeleSubRecord(ESMReader &esm) + { + if (esm.isNextSub("DELE")) + { + esm.getSubName(); + esm.skipHSub(); + return true; + } + return false; + } + + void writeDeleSubRecord(ESMWriter &esm) + { + esm.writeHNString("DELE", ""); + } +} diff --git a/components/esm/util.hpp b/components/esm/util.hpp index a80df2456..c670fb23a 100644 --- a/components/esm/util.hpp +++ b/components/esm/util.hpp @@ -1,9 +1,15 @@ #ifndef OPENMW_ESM_UTIL_H #define OPENMW_ESM_UTIL_H +#include + #include #include +#include "esmreader.hpp" +#include "esmwriter.hpp" +#include "loadbsgn.hpp" + namespace ESM { @@ -48,6 +54,9 @@ struct Vector3 } }; +bool readDeleSubRecord(ESMReader &esm); +void writeDeleSubRecord(ESMWriter &esm); + } #endif From 9ac20a33552e61182dbb90c5e2f0b34683720583 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 7 Jul 2015 15:49:55 +0300 Subject: [PATCH 02/49] Add NAME and DELE handling to ESM records. Changed records are those where DELE is inserted at the beginning of a record (before NAME). The record has all required sub-records in this case. --- components/esm/loadbsgn.cpp | 11 +++++++++++ components/esm/loadbsgn.hpp | 2 ++ components/esm/loadltex.cpp | 9 +++++++++ components/esm/loadltex.hpp | 2 ++ components/esm/loadregn.cpp | 10 ++++++++++ components/esm/loadregn.hpp | 2 ++ 6 files changed, 36 insertions(+) diff --git a/components/esm/loadbsgn.cpp b/components/esm/loadbsgn.cpp index e0cd83ea0..7892bfc68 100644 --- a/components/esm/loadbsgn.cpp +++ b/components/esm/loadbsgn.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -11,6 +12,10 @@ namespace ESM void BirthSign::load(ESMReader &esm) { mPowers.mList.clear(); + + mIsDeleted = readDeleSubRecord(esm); + mId = esm.getHNString("NAME"); + while (esm.hasMoreSubs()) { esm.getSubName(); @@ -37,6 +42,11 @@ void BirthSign::load(ESMReader &esm) void BirthSign::save(ESMWriter &esm) const { + if (mIsDeleted) + { + writeDeleSubRecord(esm); + } + esm.writeHNCString("NAME", mId); esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("TNAM", mTexture); esm.writeHNOCString("DESC", mDescription); @@ -50,6 +60,7 @@ void BirthSign::save(ESMWriter &esm) const mDescription.clear(); mTexture.clear(); mPowers.mList.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadbsgn.hpp b/components/esm/loadbsgn.hpp index f91f91c97..41c70fb24 100644 --- a/components/esm/loadbsgn.hpp +++ b/components/esm/loadbsgn.hpp @@ -22,6 +22,8 @@ struct BirthSign // List of powers and abilities that come with this birth sign. SpellList mPowers; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadltex.cpp b/components/esm/loadltex.cpp index c3e2d50ff..0ee30b11c 100644 --- a/components/esm/loadltex.cpp +++ b/components/esm/loadltex.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,11 +11,18 @@ namespace ESM void LandTexture::load(ESMReader &esm) { + mIsDeleted = readDeleSubRecord(esm); + mId = esm.getHNString("NAME"); esm.getHNT(mIndex, "INTV"); mTexture = esm.getHNString("DATA"); } void LandTexture::save(ESMWriter &esm) const { + if (mIsDeleted) + { + writeDeleSubRecord(esm); + } + esm.writeHNCString("NAME", mId); esm.writeHNT("INTV", mIndex); esm.writeHNCString("DATA", mTexture); } @@ -23,6 +31,7 @@ void LandTexture::blank() { mTexture.clear(); mIndex = -1; + mIsDeleted = false; } } diff --git a/components/esm/loadltex.hpp b/components/esm/loadltex.hpp index 50a788105..e019e269e 100644 --- a/components/esm/loadltex.hpp +++ b/components/esm/loadltex.hpp @@ -34,6 +34,8 @@ struct LandTexture std::string mId, mTexture; int mIndex; + bool mIsDeleted; + void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadregn.cpp b/components/esm/loadregn.cpp index 1b08b7217..b0adc6f58 100644 --- a/components/esm/loadregn.cpp +++ b/components/esm/loadregn.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,8 @@ namespace ESM void Region::load(ESMReader &esm) { + mIsDeleted = readDeleSubRecord(esm); + mId = esm.getHNString("NAME"); mName = esm.getHNOString("FNAM"); esm.getSubNameIs("WEAT"); @@ -49,6 +52,11 @@ void Region::load(ESMReader &esm) } void Region::save(ESMWriter &esm) const { + if (mIsDeleted) + { + writeDeleSubRecord(esm); + } + esm.writeHNString("NAME", mId); esm.writeHNOCString("FNAM", mName); if (esm.getVersion() == VER_12) @@ -77,5 +85,7 @@ void Region::save(ESMWriter &esm) const mName.clear(); mSleepList.clear(); mSoundList.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadregn.hpp b/components/esm/loadregn.hpp index 1e241fffb..921ab887b 100644 --- a/components/esm/loadregn.hpp +++ b/components/esm/loadregn.hpp @@ -51,6 +51,8 @@ struct Region std::vector mSoundList; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; From d2c15647a3f1a03ad3c34dd7eaf6fe6cfbcd35ab Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 7 Jul 2015 17:00:40 +0300 Subject: [PATCH 03/49] Add NAME and DELE handling to Script record --- components/esm/loadscpt.cpp | 12 ++++++++++++ components/esm/loadscpt.hpp | 2 ++ 2 files changed, 14 insertions(+) diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index fd807ddd3..67c1b8f6f 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" #include @@ -65,6 +66,10 @@ namespace ESM mData = data.mData; mId = data.mName.toString(); + // In scripts DELE sub-record appears after a header. + // The script data is following after DELE in this case. + mIsDeleted = readDeleSubRecord(esm); + mVarNames.clear(); while (esm.hasMoreSubs()) @@ -106,6 +111,11 @@ namespace ESM esm.writeHNT("SCHD", data, 52); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + } + if (!mVarNames.empty()) { esm.startSubRecord("SCVR"); @@ -136,6 +146,8 @@ namespace ESM mScriptText = "Begin \"" + mId + "\"\n\nEnd " + mId + "\n"; else mScriptText = "Begin " + mId + "\n\nEnd " + mId + "\n"; + + mIsDeleted = false; } } diff --git a/components/esm/loadscpt.hpp b/components/esm/loadscpt.hpp index 56390f384..401dfe105 100644 --- a/components/esm/loadscpt.hpp +++ b/components/esm/loadscpt.hpp @@ -50,6 +50,8 @@ public: /// Script source code std::string mScriptText; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; From 19ac4e942a9efb329143415a46aabaaf51cbe8ef Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 7 Jul 2015 19:18:42 +0300 Subject: [PATCH 04/49] Change DELE sub-record value to 0 (4 bytes) --- components/esm/util.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/esm/util.cpp b/components/esm/util.cpp index c20bd4d51..892113cda 100644 --- a/components/esm/util.cpp +++ b/components/esm/util.cpp @@ -1,5 +1,7 @@ #include "util.hpp" +#include + namespace ESM { bool readDeleSubRecord(ESMReader &esm) @@ -15,6 +17,6 @@ namespace ESM void writeDeleSubRecord(ESMWriter &esm) { - esm.writeHNString("DELE", ""); + esm.writeHNT("DELE", static_cast(0)); } } From 0b537186e5b513cf7d6045a7c88e8c6b4d4afc7c Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 7 Jul 2015 19:42:24 +0300 Subject: [PATCH 05/49] Add NAME and DELE handling to Dialogue record --- components/esm/loaddial.cpp | 27 +++++++++++++++++---------- components/esm/loaddial.hpp | 5 +++-- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/components/esm/loaddial.cpp b/components/esm/loaddial.cpp index f2da8f377..77a04ca01 100644 --- a/components/esm/loaddial.cpp +++ b/components/esm/loaddial.cpp @@ -2,9 +2,12 @@ #include +#include + #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -12,18 +15,19 @@ namespace ESM void Dialogue::load(ESMReader &esm) { + mIsDeleted = false; + + mId = esm.getHNString("NAME"); esm.getSubNameIs("DATA"); esm.getSubHeader(); int si = esm.getSubSize(); if (si == 1) esm.getT(mType); - else if (si == 4) + else if (si == 4) // The dialogue is deleted { - // These are just markers, their values are not used. - int i; - esm.getT(i); - esm.getHNT(i, "DELE"); - mType = Deleted; + int32_t empty; + esm.getT(empty); // Skip an empty DATA + mIsDeleted = readDeleSubRecord(esm); } else esm.fail("Unknown sub record size"); @@ -31,12 +35,15 @@ void Dialogue::load(ESMReader &esm) void Dialogue::save(ESMWriter &esm) const { - if (mType != Deleted) - esm.writeHNT("DATA", mType); + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + esm.writeHNT("DATA", static_cast(0)); + writeDeleSubRecord(esm); + } else { - esm.writeHNT("DATA", (int)1); - esm.writeHNT("DELE", (int)1); + esm.writeHNT("DATA", mType); } } diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index 58598d353..ab8cf4bff 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -30,8 +30,7 @@ struct Dialogue Voice = 1, Greeting = 2, Persuasion = 3, - Journal = 4, - Deleted = -1 + Journal = 4 }; std::string mId; @@ -46,6 +45,8 @@ struct Dialogue // This is only used during the loading phase to speed up DialInfo merging. LookupMap mLookup; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; From 847614c26f372d5483bb96a3b30e90dd9358b28f Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 7 Jul 2015 19:57:08 +0300 Subject: [PATCH 06/49] Add DELE handling to Info record --- components/esm/loadinfo.cpp | 21 ++++++++++++++++++--- components/esm/loadinfo.hpp | 2 ++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index a2bade1c5..3394ddbad 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -19,11 +20,18 @@ void DialInfo::load(ESMReader &esm) // Since there's no way to mark selects as "deleted", we have to clear the SelectStructs from all previous loadings mSelects.clear(); - // Not present if deleted - if (esm.isNextSub("DATA")) { - esm.getHT(mData, 12); + // If the info is deleted, NAME and DELE sub-records are followed after NNAM + if (esm.isNextSub("NAME")) + { + esm.getSubName(); + mResponse = esm.getHString(); + mIsDeleted = readDeleSubRecord(esm); + return; } + esm.getSubNameIs("DATA"); + esm.getHT(mData, 12); + if (!esm.hasMoreSubs()) return; @@ -131,6 +139,13 @@ void DialInfo::save(ESMWriter &esm) const { esm.writeHNCString("PNAM", mPrev); esm.writeHNCString("NNAM", mNext); + if (mIsDeleted) + { + esm.writeHNCString("NAME", mResponse); + writeDeleSubRecord(esm); + return; + } + esm.writeHNT("DATA", mData, 12); esm.writeHNOCString("ONAM", mActor); esm.writeHNOCString("RNAM", mRace); diff --git a/components/esm/loadinfo.hpp b/components/esm/loadinfo.hpp index 54003b0d9..8b4fae761 100644 --- a/components/esm/loadinfo.hpp +++ b/components/esm/loadinfo.hpp @@ -106,6 +106,8 @@ struct DialInfo REC_DELE = 0x454c4544 }; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; From b667338a8fe5ffb78bc28151948f31e03dc99407 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 7 Jul 2015 20:41:39 +0300 Subject: [PATCH 07/49] Add NAME and DELE handling to Cell record --- components/esm/loadcell.cpp | 23 +++++++++++++++-------- components/esm/loadcell.hpp | 3 +++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 94f4b0b6e..86b4e4edb 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -12,6 +12,7 @@ #include "esmwriter.hpp" #include "defs.hpp" #include "cellid.hpp" +#include "util.hpp" namespace { @@ -54,10 +55,17 @@ namespace ESM void Cell::load(ESMReader &esm, bool saveContext) { + loadName(esm); loadData(esm); loadCell(esm, saveContext); } +void Cell::loadName(ESMReader &esm) +{ + mName = esm.getHNString("NAME"); + mIsDeleted = readDeleSubRecord(esm); +} + void Cell::loadCell(ESMReader &esm, bool saveContext) { mRefNumCounter = 0; @@ -105,13 +113,6 @@ void Cell::loadCell(ESMReader &esm, bool saveContext) void Cell::loadData(ESMReader &esm) { - // Ignore this for now, it might mean we should delete the entire - // cell? - // TODO: treat the special case "another plugin moved this ref, but we want to delete it"! - if (esm.isNextSub("DELE")) { - esm.skipHSub(); - } - esm.getHNT(mData, "DATA", 12); } @@ -124,6 +125,12 @@ void Cell::postLoad(ESMReader &esm) void Cell::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mName); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + } + esm.writeHNT("DATA", mData, 12); if (mData.mFlags & Interior) { @@ -147,7 +154,7 @@ void Cell::save(ESMWriter &esm) const esm.writeHNT("NAM5", mMapColor); } - if (mRefNumCounter != 0) + if (mRefNumCounter != 0 && !mIsDeleted) esm.writeHNT("NAM0", mRefNumCounter); } diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index 12fb8c068..b313435d6 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -112,11 +112,14 @@ struct Cell CellRefTracker mLeasedRefs; MovedCellRefTracker mMovedRefs; + bool mIsDeleted; + void postLoad(ESMReader &esm); // This method is left in for compatibility with esmtool. Parsing moved references currently requires // passing ESMStore, bit it does not know about this parameter, so we do it this way. void load(ESMReader &esm, bool saveContext = true); // Load everything (except references) + void loadName(ESMReader &esm); // Load NAME and checks for DELE void loadData(ESMReader &esm); // Load DATAstruct only void loadCell(ESMReader &esm, bool saveContext = true); // Load everything, except DATAstruct and references From 8c3654af11e21ec8ca068c1581e69de707000f67 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 7 Jul 2015 20:56:26 +0300 Subject: [PATCH 08/49] Add NAME handling to Race record --- components/esm/loadrace.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/esm/loadrace.cpp b/components/esm/loadrace.cpp index e88454d4c..3feb06c92 100644 --- a/components/esm/loadrace.cpp +++ b/components/esm/loadrace.cpp @@ -22,6 +22,8 @@ void Race::load(ESMReader &esm) { mPowers.mList.clear(); + mId = esm.getHNString("NAME"); + bool hasData = false; while (esm.hasMoreSubs()) { @@ -51,6 +53,7 @@ void Race::load(ESMReader &esm) } void Race::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); esm.writeHNOCString("FNAM", mName); esm.writeHNT("RADT", mData, 140); mPowers.save(esm); From 30b42bf4c0a3c953703987ec333bd89ecd667f7e Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 7 Jul 2015 21:24:35 +0300 Subject: [PATCH 09/49] Remove redundant code --- components/esm/loadinfo.cpp | 1 - components/esm/util.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index 3394ddbad..3b5e0ea3a 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -23,7 +23,6 @@ void DialInfo::load(ESMReader &esm) // If the info is deleted, NAME and DELE sub-records are followed after NNAM if (esm.isNextSub("NAME")) { - esm.getSubName(); mResponse = esm.getHString(); mIsDeleted = readDeleSubRecord(esm); return; diff --git a/components/esm/util.cpp b/components/esm/util.cpp index 892113cda..ff2436544 100644 --- a/components/esm/util.cpp +++ b/components/esm/util.cpp @@ -8,7 +8,6 @@ namespace ESM { if (esm.isNextSub("DELE")) { - esm.getSubName(); esm.skipHSub(); return true; } From 09a33580170076f14b2d46d72ad93d60fe52fc07 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Wed, 8 Jul 2015 00:04:14 +0300 Subject: [PATCH 10/49] Add NAME and DELE handling to Global record --- components/esm/loadglob.cpp | 16 ++++++++++++++++ components/esm/loadglob.hpp | 2 ++ 2 files changed, 18 insertions(+) diff --git a/components/esm/loadglob.cpp b/components/esm/loadglob.cpp index a78ed1a1b..6cc37d675 100644 --- a/components/esm/loadglob.cpp +++ b/components/esm/loadglob.cpp @@ -1,6 +1,9 @@ #include "loadglob.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -8,11 +11,24 @@ namespace ESM void Global::load (ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + mValue.read (esm, ESM::Variant::Format_Global); } void Global::save (ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + mValue.write (esm, ESM::Variant::Format_Global); } diff --git a/components/esm/loadglob.hpp b/components/esm/loadglob.hpp index cc5dbbdcf..45b47a3bc 100644 --- a/components/esm/loadglob.hpp +++ b/components/esm/loadglob.hpp @@ -24,6 +24,8 @@ struct Global std::string mId; Variant mValue; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; From b2f3ccb080b459f212280cc2565110a0343645ec Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Wed, 8 Jul 2015 21:17:59 +0300 Subject: [PATCH 11/49] Add NAME handling to GameSetting record --- components/esm/loadgmst.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/esm/loadgmst.cpp b/components/esm/loadgmst.cpp index 21d66339a..9e2a80270 100644 --- a/components/esm/loadgmst.cpp +++ b/components/esm/loadgmst.cpp @@ -1,5 +1,7 @@ #include "loadgmst.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" #include "defs.hpp" namespace ESM @@ -8,11 +10,13 @@ namespace ESM void GameSetting::load (ESMReader &esm) { + mId = esm.getHNString("NAME"); mValue.read (esm, ESM::Variant::Format_Gmst); } void GameSetting::save (ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); mValue.write (esm, ESM::Variant::Format_Gmst); } From 89e44c8f1fcb02a0ea78b468402a2c8e96d5465c Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Wed, 8 Jul 2015 21:24:05 +0300 Subject: [PATCH 12/49] Remove explicit record ID in load/read methods of MWWorld::Store --- apps/openmw/mwworld/store.cpp | 10 ++-- apps/openmw/mwworld/store.hpp | 110 +++++++++++++++++++++++----------- components/esm/util.cpp | 18 ++++++ components/esm/util.hpp | 27 ++++++++- 4 files changed, 123 insertions(+), 42 deletions(-) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index cdcc00b4d..767a33b13 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -35,7 +35,7 @@ void Store::handleMovedCellRefs(ESM::ESMReader& esm, ESM::Cell* cell) } } -void Store::load(ESM::ESMReader &esm, const std::string &id) +void Store::load(ESM::ESMReader &esm) { // Don't automatically assume that a new cell must be spawned. Multiple plugins write to the same cell, // and we merge all this data into one Cell object. However, we can't simply search for the cell id, @@ -43,9 +43,9 @@ void Store::load(ESM::ESMReader &esm, const std::string &id) // are not available until both cells have been loaded at least partially! // All cells have a name record, even nameless exterior cells. - std::string idLower = Misc::StringUtils::lowerCase(id); ESM::Cell cell; - cell.mName = id; + cell.loadName(esm); + std::string idLower = Misc::StringUtils::lowerCase(cell.mName); // Load the (x,y) coordinates of the cell, if it is an exterior cell, // so we can find the cell we need to merge with @@ -119,9 +119,9 @@ void Store::load(ESM::ESMReader &esm, const std::string &id) } } -void Store::load(ESM::ESMReader &esm, const std::string &id) +void Store::load(ESM::ESMReader &esm) { - load(esm, id, esm.getIndex()); + load(esm, esm.getIndex()); } } diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 2d73d5312..a61cbd2ac 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -10,6 +10,7 @@ #include #include +#include #include @@ -26,15 +27,19 @@ namespace MWWorld virtual size_t getSize() const = 0; virtual int getDynamicSize() const { return 0; } - virtual void load(ESM::ESMReader &esm, const std::string &id) = 0; + virtual void load(ESM::ESMReader &esm) = 0; virtual bool eraseStatic(const std::string &id) {return false;} virtual void clearDynamic() {} virtual void write (ESM::ESMWriter& writer, Loading::Listener& progress) const {} - virtual void read (ESM::ESMReader& reader, const std::string& id) {} + virtual void read (ESM::ESMReader& reader) {} ///< Read into dynamic storage + + virtual std::string getLastAddedRecordId() const { return ""; } + ///< Returns the last loaded/read ID or empty string if a loaded record has no ID + virtual bool isLastAddedRecordDeleted() const { return false; } }; template @@ -126,6 +131,7 @@ namespace MWWorld } }; + T mLastAddedRecord; friend class ESMStore; @@ -208,15 +214,16 @@ namespace MWWorld return ptr; } - void load(ESM::ESMReader &esm, const std::string &id) { - std::string idLower = Misc::StringUtils::lowerCase(id); + void load(ESM::ESMReader &esm) { + T record; + record.load(esm); - std::pair inserted = mStatic.insert(std::make_pair(idLower, T())); + std::string idLower = Misc::StringUtils::lowerCase(record.mId); + std::pair inserted = mStatic.insert(std::make_pair(idLower, record)); if (inserted.second) mShared.push_back(&inserted.first->second); - inserted.first->second.mId = idLower; - inserted.first->second.load(esm); + mLastAddedRecord = record; } void setUp() { @@ -325,58 +332,79 @@ namespace MWWorld ++iter) { writer.startRecord (T::sRecordId); - writer.writeHNString ("NAME", iter->second.mId); iter->second.save (writer); writer.endRecord (T::sRecordId); } } - void read (ESM::ESMReader& reader, const std::string& id) + void read (ESM::ESMReader& reader) { T record; - record.mId = id; record.load (reader); insert (record); + + mLastAddedRecord = record; + } + + std::string getLastAddedRecordId() const + { + return ESM::getRecordId(mLastAddedRecord); + } + + bool isLastAddedRecordDeleted() const + { + return ESM::isRecordDeleted(mLastAddedRecord); } }; template <> - inline void Store::load(ESM::ESMReader &esm, const std::string &id) { - std::string idLower = Misc::StringUtils::lowerCase(id); + inline void Store::load(ESM::ESMReader &esm) { + ESM::Dialogue dialogue; + dialogue.load(esm); - std::map::iterator it = mStatic.find(idLower); - if (it == mStatic.end()) { - it = mStatic.insert( std::make_pair( idLower, ESM::Dialogue() ) ).first; - it->second.mId = id; // don't smash case here, as this line is printed + std::string idLower = Misc::StringUtils::lowerCase(dialogue.mId); + std::map::iterator found = mStatic.find(idLower); + if (found == mStatic.end()) + { + mStatic.insert(std::make_pair(idLower, dialogue)); } - - it->second.load(esm); + else + { + found->second = dialogue; + } + + mLastAddedRecord = dialogue; } template <> - inline void Store::load(ESM::ESMReader &esm, const std::string &id) { - ESM::Script scpt; - scpt.load(esm); - Misc::StringUtils::toLower(scpt.mId); + inline void Store::load(ESM::ESMReader &esm) { + ESM::Script script; + script.load(esm); - std::pair inserted = mStatic.insert(std::make_pair(scpt.mId, scpt)); + std::string idLower = Misc::StringUtils::toLower(script.mId); + std::pair inserted = mStatic.insert(std::make_pair(idLower, script)); if (inserted.second) mShared.push_back(&inserted.first->second); else - inserted.first->second = scpt; + inserted.first->second = script; + + mLastAddedRecord = script; } template <> - inline void Store::load(ESM::ESMReader &esm, const std::string &id) + inline void Store::load(ESM::ESMReader &esm) { - ESM::StartScript s; - s.load(esm); - s.mId = Misc::StringUtils::toLower(s.mId); - std::pair inserted = mStatic.insert(std::make_pair(s.mId, s)); + ESM::StartScript script; + script.load(esm); + + std::string idLower = Misc::StringUtils::toLower(script.mId); + std::pair inserted = mStatic.insert(std::make_pair(idLower, script)); if (inserted.second) mShared.push_back(&inserted.first->second); else - inserted.first->second = s; + inserted.first->second = script; + + mLastAddedRecord = script; } template <> @@ -385,6 +413,7 @@ namespace MWWorld // For multiple ESM/ESP files we need one list per file. typedef std::vector LandTextureList; std::vector mStatic; + ESM::LandTexture mLastLoadedTexture; public: Store() { @@ -426,10 +455,9 @@ namespace MWWorld return mStatic[plugin].size(); } - void load(ESM::ESMReader &esm, const std::string &id, size_t plugin) { + void load(ESM::ESMReader &esm, size_t plugin) { ESM::LandTexture lt; lt.load(esm); - lt.mId = id; // Make sure we have room for the structure if (plugin >= mStatic.size()) { @@ -443,7 +471,7 @@ namespace MWWorld ltexl[lt.mIndex] = lt; } - void load(ESM::ESMReader &esm, const std::string &id); + void load(ESM::ESMReader &esm); iterator begin(size_t plugin) const { assert(plugin < mStatic.size()); @@ -454,6 +482,16 @@ namespace MWWorld assert(plugin < mStatic.size()); return mStatic[plugin].end(); } + + std::string getLastAddedRecordId() const + { + return ESM::getRecordId(mLastLoadedTexture); + } + + bool isLastAddedRecordDeleted() const + { + return ESM::isRecordDeleted(mLastLoadedTexture); + } }; template <> @@ -521,7 +559,7 @@ namespace MWWorld return ptr; } - void load(ESM::ESMReader &esm, const std::string &id) { + void load(ESM::ESMReader &esm) { ESM::Land *ptr = new ESM::Land(); ptr->load(esm); @@ -688,7 +726,7 @@ namespace MWWorld // errors related to the compare operator used in std::find for ESM::MovedCellRefTracker::find. // There some nasty three-way cyclic header dependency involved, which I could only fix by moving // this method. - void load(ESM::ESMReader &esm, const std::string &id); + void load(ESM::ESMReader &esm); iterator intBegin() const { return iterator(mSharedInt.begin()); @@ -857,7 +895,7 @@ namespace MWWorld mCells = &cells; } - void load(ESM::ESMReader &esm, const std::string &id) { + void load(ESM::ESMReader &esm) { ESM::Pathgrid pathgrid; pathgrid.load(esm); diff --git a/components/esm/util.cpp b/components/esm/util.cpp index ff2436544..4cfe644e8 100644 --- a/components/esm/util.cpp +++ b/components/esm/util.cpp @@ -18,4 +18,22 @@ namespace ESM { esm.writeHNT("DELE", static_cast(0)); } + + template <> + bool isRecordDeleted(const StartScript &script) + { + return false; + } + + template <> + bool isRecordDeleted(const Race &race) + { + return false; + } + + template <> + bool isRecordDeleted(const GameSetting &gmst) + { + return false; + } } diff --git a/components/esm/util.hpp b/components/esm/util.hpp index c670fb23a..94a7956ef 100644 --- a/components/esm/util.hpp +++ b/components/esm/util.hpp @@ -8,7 +8,10 @@ #include "esmreader.hpp" #include "esmwriter.hpp" -#include "loadbsgn.hpp" +#include "loadsscr.hpp" +#include "loadglob.hpp" +#include "loadrace.hpp" +#include "loadgmst.hpp" namespace ESM { @@ -57,6 +60,28 @@ struct Vector3 bool readDeleSubRecord(ESMReader &esm); void writeDeleSubRecord(ESMWriter &esm); +template +std::string getRecordId(const RecordT &record) +{ + return record.mId; +} + +template +bool isRecordDeleted(const RecordT &record) +{ + return record.mIsDeleted; +} + +// The following records can't be deleted (for now) +template <> +bool isRecordDeleted(const StartScript &script); + +template <> +bool isRecordDeleted(const Race &race); + +template <> +bool isRecordDeleted(const GameSetting &gmst); + } #endif From 9301bc148e9fa10e58519debdc7103a9babae07b Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Wed, 8 Jul 2015 21:26:20 +0300 Subject: [PATCH 13/49] Remove NAME handling from MWWorld::ESMStore --- apps/openmw/mwworld/esmstore.cpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 5d9beecb6..50a7e3376 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -95,23 +95,12 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener) throw std::runtime_error(error.str()); } } else { - // Load it - std::string id = esm.getHNOString("NAME"); - // ... unless it got deleted! This means that the following record - // has been deleted, and trying to load it using standard assumptions - // on the structure will (probably) fail. - if (esm.isNextSub("DELE")) { - esm.skipRecord(); - it->second->eraseStatic(id); - continue; - } - it->second->load(esm, id); - - // DELE can also occur after the usual subrecords - if (esm.isNextSub("DELE")) { - esm.skipRecord(); - it->second->eraseStatic(id); - continue; + it->second->load(esm); + std::string id = it->second->getLastAddedRecordId(); + if (it->second->isLastAddedRecordDeleted()) + { + it->second->eraseStatic(id); + continue; } if (n.val==ESM::REC_DIAL) { @@ -194,13 +183,13 @@ void ESMStore::setUp() case ESM::REC_LEVC: { - std::string id = reader.getHNString ("NAME"); - mStores[type]->read (reader, id); + StoreBase *store = mStores[type]; + store->read (reader); // FIXME: there might be stale dynamic IDs in mIds from an earlier savegame // that really should be cleared instead of just overwritten - mIds[id] = type; + mIds[store->getLastAddedRecordId()] = type; } if (type==ESM::REC_NPC_) From 897a52cdda1cec48833af47c2798b6836c9f4d36 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Wed, 8 Jul 2015 21:40:01 +0300 Subject: [PATCH 14/49] Remove NAME handling from MWWorld::Globals --- apps/openmw/mwworld/globals.cpp | 26 ++++++++++++-------------- apps/openmw/mwworld/globals.hpp | 4 ++-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwworld/globals.cpp b/apps/openmw/mwworld/globals.cpp index e7cb04590..671793a17 100644 --- a/apps/openmw/mwworld/globals.cpp +++ b/apps/openmw/mwworld/globals.cpp @@ -14,7 +14,7 @@ namespace MWWorld { Globals::Collection::const_iterator Globals::find (const std::string& name) const { - Collection::const_iterator iter = mVariables.find (name); + Collection::const_iterator iter = mVariables.find (Misc::StringUtils::lowerCase (name)); if (iter==mVariables.end()) throw std::runtime_error ("unknown global variable: " + name); @@ -24,7 +24,7 @@ namespace MWWorld Globals::Collection::iterator Globals::find (const std::string& name) { - Collection::iterator iter = mVariables.find (name); + Collection::iterator iter = mVariables.find (Misc::StringUtils::lowerCase (name)); if (iter==mVariables.end()) throw std::runtime_error ("unknown global variable: " + name); @@ -41,28 +41,28 @@ namespace MWWorld for (MWWorld::Store::iterator iter = globals.begin(); iter!=globals.end(); ++iter) { - mVariables.insert (std::make_pair (iter->mId, iter->mValue)); + mVariables.insert (std::make_pair (Misc::StringUtils::lowerCase (iter->mId), *iter)); } } const ESM::Variant& Globals::operator[] (const std::string& name) const { - return find (name)->second; + return find (Misc::StringUtils::lowerCase (name))->second.mValue; } ESM::Variant& Globals::operator[] (const std::string& name) { - return find (name)->second; + return find (Misc::StringUtils::lowerCase (name))->second.mValue; } char Globals::getType (const std::string& name) const { - Collection::const_iterator iter = mVariables.find (name); + Collection::const_iterator iter = mVariables.find (Misc::StringUtils::lowerCase (name)); if (iter==mVariables.end()) return ' '; - switch (iter->second.getType()) + switch (iter->second.mValue.getType()) { case ESM::VT_Short: return 's'; case ESM::VT_Long: return 'l'; @@ -82,8 +82,7 @@ namespace MWWorld for (Collection::const_iterator iter (mVariables.begin()); iter!=mVariables.end(); ++iter) { writer.startRecord (ESM::REC_GLOB); - writer.writeHNString ("NAME", iter->first); - iter->second.write (writer, ESM::Variant::Format_Global); + iter->second.save (writer); writer.endRecord (ESM::REC_GLOB); } } @@ -92,14 +91,13 @@ namespace MWWorld { if (type==ESM::REC_GLOB) { - std::string id = reader.getHNString ("NAME"); + ESM::Global global; + global.load(reader); - Collection::iterator iter = mVariables.find (Misc::StringUtils::lowerCase (id)); + Collection::iterator iter = mVariables.find (Misc::StringUtils::lowerCase (global.mId)); if (iter!=mVariables.end()) - iter->second.read (reader, ESM::Variant::Format_Global); - else - reader.skipRecord(); + iter->second = global; return true; } diff --git a/apps/openmw/mwworld/globals.hpp b/apps/openmw/mwworld/globals.hpp index bb4ab13d9..3468c2e71 100644 --- a/apps/openmw/mwworld/globals.hpp +++ b/apps/openmw/mwworld/globals.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include namespace ESM { @@ -29,7 +29,7 @@ namespace MWWorld { private: - typedef std::map Collection; + typedef std::map Collection; Collection mVariables; // type, value From 00bf87b5611d7dbc8fc8e7d5add1a4a236071733 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Thu, 9 Jul 2015 15:17:38 +0300 Subject: [PATCH 15/49] Convert IDs of loaded records to lower case in MWWorld::Store --- apps/openmw/mwworld/store.hpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index a61cbd2ac..c482486d8 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -217,9 +217,9 @@ namespace MWWorld void load(ESM::ESMReader &esm) { T record; record.load(esm); + Misc::StringUtils::toLower(record.mId); - std::string idLower = Misc::StringUtils::lowerCase(record.mId); - std::pair inserted = mStatic.insert(std::make_pair(idLower, record)); + std::pair inserted = mStatic.insert(std::make_pair(record.mId, record)); if (inserted.second) mShared.push_back(&inserted.first->second); @@ -359,6 +359,7 @@ namespace MWWorld template <> inline void Store::load(ESM::ESMReader &esm) { + // The original letter case of a dialogue ID is saved, because it's printed ESM::Dialogue dialogue; dialogue.load(esm); @@ -380,9 +381,9 @@ namespace MWWorld inline void Store::load(ESM::ESMReader &esm) { ESM::Script script; script.load(esm); + Misc::StringUtils::toLower(script.mId); - std::string idLower = Misc::StringUtils::toLower(script.mId); - std::pair inserted = mStatic.insert(std::make_pair(idLower, script)); + std::pair inserted = mStatic.insert(std::make_pair(script.mId, script)); if (inserted.second) mShared.push_back(&inserted.first->second); else @@ -396,9 +397,9 @@ namespace MWWorld { ESM::StartScript script; script.load(esm); + Misc::StringUtils::toLower(script.mId); - std::string idLower = Misc::StringUtils::toLower(script.mId); - std::pair inserted = mStatic.insert(std::make_pair(idLower, script)); + std::pair inserted = mStatic.insert(std::make_pair(script.mId, script)); if (inserted.second) mShared.push_back(&inserted.first->second); else From 20723581a102f021ba04296096d5cd0c715f0d66 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Thu, 9 Jul 2015 21:10:57 +0300 Subject: [PATCH 16/49] Letter case fix for MWWorld::Globals --- apps/openmw/mwworld/globals.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/globals.cpp b/apps/openmw/mwworld/globals.cpp index 671793a17..668a33f09 100644 --- a/apps/openmw/mwworld/globals.cpp +++ b/apps/openmw/mwworld/globals.cpp @@ -93,9 +93,9 @@ namespace MWWorld { ESM::Global global; global.load(reader); + Misc::StringUtils::toLower(global.mId); - Collection::iterator iter = mVariables.find (Misc::StringUtils::lowerCase (global.mId)); - + Collection::iterator iter = mVariables.find (global.mId); if (iter!=mVariables.end()) iter->second = global; From 7ecb54a776a298bee470397c40ce64945a2b0174 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Thu, 9 Jul 2015 21:45:24 +0300 Subject: [PATCH 17/49] Set Deleted flag to false when initializing ESM records --- components/esm/loadacti.cpp | 4 + components/esm/loadacti.hpp | 2 + components/esm/loadalch.cpp | 4 + components/esm/loadalch.hpp | 2 + components/esm/loadappa.cpp | 96 ++++++----- components/esm/loadappa.hpp | 2 + components/esm/loadarmo.cpp | 4 + components/esm/loadarmo.hpp | 2 + components/esm/loadbody.cpp | 80 ++++----- components/esm/loadbody.hpp | 2 + components/esm/loadbook.cpp | 4 + components/esm/loadbook.hpp | 2 + components/esm/loadbsgn.cpp | 76 +++++---- components/esm/loadbsgn.hpp | 2 + components/esm/loadcell.hpp | 3 +- components/esm/loadclas.cpp | 3 + components/esm/loadclas.hpp | 2 + components/esm/loadclot.cpp | 4 + components/esm/loadclot.hpp | 2 + components/esm/loadcont.cpp | 4 + components/esm/loadcont.hpp | 2 + components/esm/loadcrea.cpp | 4 + components/esm/loadcrea.hpp | 2 + components/esm/loaddial.cpp | 207 +++++++++++----------- components/esm/loaddial.hpp | 2 + components/esm/loaddoor.cpp | 4 + components/esm/loaddoor.hpp | 2 + components/esm/loadench.cpp | 76 +++++---- components/esm/loadench.hpp | 2 + components/esm/loadfact.cpp | 129 +++++++------- components/esm/loadfact.hpp | 2 + components/esm/loadglob.cpp | 4 + components/esm/loadglob.hpp | 2 + components/esm/loadinfo.cpp | 302 +++++++++++++++++---------------- components/esm/loadinfo.hpp | 2 + components/esm/loadingr.cpp | 4 + components/esm/loadingr.hpp | 2 + components/esm/loadlevlist.cpp | 3 + components/esm/loadlevlist.hpp | 2 + components/esm/loadligh.cpp | 4 + components/esm/loadligh.hpp | 2 + components/esm/loadlock.cpp | 4 + components/esm/loadlock.hpp | 2 + components/esm/loadltex.cpp | 47 ++--- components/esm/loadltex.hpp | 6 +- components/esm/loadmisc.cpp | 4 + components/esm/loadmisc.hpp | 2 + components/esm/loadnpc.cpp | 4 + components/esm/loadnpc.hpp | 2 + components/esm/loadprob.cpp | 4 + components/esm/loadprob.hpp | 2 + components/esm/loadregn.cpp | 101 +++++------ components/esm/loadregn.hpp | 2 + components/esm/loadrepa.cpp | 96 ++++++----- components/esm/loadrepa.hpp | 2 + components/esm/loadscpt.cpp | 5 +- components/esm/loadscpt.hpp | 2 + components/esm/loadsndg.cpp | 4 + components/esm/loadsndg.hpp | 2 + components/esm/loadsoun.cpp | 4 + components/esm/loadsoun.hpp | 2 + components/esm/loadspel.cpp | 4 + components/esm/loadspel.hpp | 2 + components/esm/loadstat.cpp | 4 + components/esm/loadstat.hpp | 2 + components/esm/loadweap.cpp | 4 + components/esm/loadweap.hpp | 2 + 67 files changed, 785 insertions(+), 589 deletions(-) diff --git a/components/esm/loadacti.cpp b/components/esm/loadacti.cpp index 295d35f7e..14a3abe54 100644 --- a/components/esm/loadacti.cpp +++ b/components/esm/loadacti.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Activator::sRecordId = REC_ACTI; + Activator::Activator() + : mIsDeleted(false) + {} + void Activator::load(ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loadacti.hpp b/components/esm/loadacti.hpp index 406512a22..93de07b25 100644 --- a/components/esm/loadacti.hpp +++ b/components/esm/loadacti.hpp @@ -19,6 +19,8 @@ struct Activator bool mIsDeleted; + Activator(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadalch.cpp b/components/esm/loadalch.cpp index 12078a5f7..5faeb99e1 100644 --- a/components/esm/loadalch.cpp +++ b/components/esm/loadalch.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Potion::sRecordId = REC_ALCH; + Potion::Potion() + : mIsDeleted(false) + {} + void Potion::load(ESMReader &esm) { mEffects.mList.clear(); diff --git a/components/esm/loadalch.hpp b/components/esm/loadalch.hpp index 3d1e6dee7..921585a9d 100644 --- a/components/esm/loadalch.hpp +++ b/components/esm/loadalch.hpp @@ -35,6 +35,8 @@ struct Potion bool mIsDeleted; + Potion(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadappa.cpp b/components/esm/loadappa.cpp index 9107e5a8e..ea375aa7f 100644 --- a/components/esm/loadappa.cpp +++ b/components/esm/loadappa.cpp @@ -9,60 +9,64 @@ namespace ESM { unsigned int Apparatus::sRecordId = REC_APPA; -void Apparatus::load(ESMReader &esm) -{ - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + Apparatus::Apparatus() + : mIsDeleted(false) + {} - bool hasData = false; - while (esm.hasMoreSubs()) + void Apparatus::load(ESMReader &esm) { - esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) { - case ESM::FourCC<'M','O','D','L'>::value: - mModel = esm.getHString(); - break; - case ESM::FourCC<'F','N','A','M'>::value: - mName = esm.getHString(); - break; - case ESM::FourCC<'A','A','D','T'>::value: - esm.getHT(mData); - hasData = true; - break; - case ESM::FourCC<'S','C','R','I'>::value: - mScript = esm.getHString(); - break; - case ESM::FourCC<'I','T','E','X'>::value: - mIcon = esm.getHString(); - break; - default: - esm.fail("Unknown subrecord"); + return; } + + bool hasData = false; + while (esm.hasMoreSubs()) + { + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'M','O','D','L'>::value: + mModel = esm.getHString(); + break; + case ESM::FourCC<'F','N','A','M'>::value: + mName = esm.getHString(); + break; + case ESM::FourCC<'A','A','D','T'>::value: + esm.getHT(mData); + hasData = true; + break; + case ESM::FourCC<'S','C','R','I'>::value: + mScript = esm.getHString(); + break; + case ESM::FourCC<'I','T','E','X'>::value: + mIcon = esm.getHString(); + break; + default: + esm.fail("Unknown subrecord"); + } + } + if (!hasData) + esm.fail("Missing AADT"); } - if (!hasData) - esm.fail("Missing AADT"); -} -void Apparatus::save(ESMWriter &esm) const -{ - esm.writeHNCString("NAME", mId); - if (mIsDeleted) + void Apparatus::save(ESMWriter &esm) const { - writeDeleSubRecord(esm); - return; - } + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } - esm.writeHNCString("MODL", mModel); - esm.writeHNCString("FNAM", mName); - esm.writeHNT("AADT", mData, 16); - esm.writeHNOCString("SCRI", mScript); - esm.writeHNCString("ITEX", mIcon); -} + esm.writeHNCString("MODL", mModel); + esm.writeHNCString("FNAM", mName); + esm.writeHNT("AADT", mData, 16); + esm.writeHNOCString("SCRI", mScript); + esm.writeHNCString("ITEX", mIcon); + } void Apparatus::blank() { diff --git a/components/esm/loadappa.hpp b/components/esm/loadappa.hpp index 62d8561a1..2dac37995 100644 --- a/components/esm/loadappa.hpp +++ b/components/esm/loadappa.hpp @@ -40,6 +40,8 @@ struct Apparatus bool mIsDeleted; + Apparatus(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadarmo.cpp b/components/esm/loadarmo.cpp index 626893d00..d23a71cac 100644 --- a/components/esm/loadarmo.cpp +++ b/components/esm/loadarmo.cpp @@ -39,6 +39,10 @@ namespace ESM unsigned int Armor::sRecordId = REC_ARMO; + Armor::Armor() + : mIsDeleted(false) + {} + void Armor::load(ESMReader &esm) { mParts.mParts.clear(); diff --git a/components/esm/loadarmo.hpp b/components/esm/loadarmo.hpp index eb911254f..4ebe181a7 100644 --- a/components/esm/loadarmo.hpp +++ b/components/esm/loadarmo.hpp @@ -98,6 +98,8 @@ struct Armor bool mIsDeleted; + Armor(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadbody.cpp b/components/esm/loadbody.cpp index 644eb3b50..e0ebfd539 100644 --- a/components/esm/loadbody.cpp +++ b/components/esm/loadbody.cpp @@ -9,53 +9,57 @@ namespace ESM { unsigned int BodyPart::sRecordId = REC_BODY; + BodyPart::BodyPart() + : mIsDeleted(false) + {} -void BodyPart::load(ESMReader &esm) -{ - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) + void BodyPart::load(ESMReader &esm) { - return; - } + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } - bool hasData = false; - while (esm.hasMoreSubs()) - { - esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + bool hasData = false; + while (esm.hasMoreSubs()) { - case ESM::FourCC<'M','O','D','L'>::value: - mModel = esm.getHString(); - break; - case ESM::FourCC<'F','N','A','M'>::value: - mRace = esm.getHString(); - break; - case ESM::FourCC<'B','Y','D','T'>::value: - esm.getHT(mData, 4); - hasData = true; - break; - default: - esm.fail("Unknown subrecord"); + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'M','O','D','L'>::value: + mModel = esm.getHString(); + break; + case ESM::FourCC<'F','N','A','M'>::value: + mRace = esm.getHString(); + break; + case ESM::FourCC<'B','Y','D','T'>::value: + esm.getHT(mData, 4); + hasData = true; + break; + default: + esm.fail("Unknown subrecord"); + } } + + if (!hasData) + esm.fail("Missing BYDT subrecord"); } - if (!hasData) - esm.fail("Missing BYDT subrecord"); -} -void BodyPart::save(ESMWriter &esm) const -{ - esm.writeHNCString("NAME", mId); - if (mIsDeleted) + void BodyPart::save(ESMWriter &esm) const { - writeDeleSubRecord(esm); - return; - } + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } - esm.writeHNCString("MODL", mModel); - esm.writeHNOCString("FNAM", mRace); - esm.writeHNT("BYDT", mData, 4); -} + esm.writeHNCString("MODL", mModel); + esm.writeHNOCString("FNAM", mRace); + esm.writeHNT("BYDT", mData, 4); + } void BodyPart::blank() { diff --git a/components/esm/loadbody.hpp b/components/esm/loadbody.hpp index 8e1e81f82..f32d2fb58 100644 --- a/components/esm/loadbody.hpp +++ b/components/esm/loadbody.hpp @@ -62,6 +62,8 @@ struct BodyPart bool mIsDeleted; + BodyPart(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadbook.cpp b/components/esm/loadbook.cpp index aec361873..2824b6200 100644 --- a/components/esm/loadbook.cpp +++ b/components/esm/loadbook.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Book::sRecordId = REC_BOOK; + Book::Book() + : mIsDeleted(false) + {} + void Book::load(ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loadbook.hpp b/components/esm/loadbook.hpp index 2f374c4b2..931f813c0 100644 --- a/components/esm/loadbook.hpp +++ b/components/esm/loadbook.hpp @@ -30,6 +30,8 @@ struct Book bool mIsDeleted; + Book(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadbsgn.cpp b/components/esm/loadbsgn.cpp index 7892bfc68..8cdeed3f6 100644 --- a/components/esm/loadbsgn.cpp +++ b/components/esm/loadbsgn.cpp @@ -9,50 +9,54 @@ namespace ESM { unsigned int BirthSign::sRecordId = REC_BSGN; -void BirthSign::load(ESMReader &esm) -{ - mPowers.mList.clear(); - - mIsDeleted = readDeleSubRecord(esm); - mId = esm.getHNString("NAME"); + BirthSign::BirthSign() + : mIsDeleted(false) + {} - while (esm.hasMoreSubs()) + void BirthSign::load(ESMReader &esm) { - esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + mPowers.mList.clear(); + + mIsDeleted = readDeleSubRecord(esm); + mId = esm.getHNString("NAME"); + + while (esm.hasMoreSubs()) { - case ESM::FourCC<'F','N','A','M'>::value: - mName = esm.getHString(); - break; - case ESM::FourCC<'T','N','A','M'>::value: - mTexture = esm.getHString(); - break; - case ESM::FourCC<'D','E','S','C'>::value: - mDescription = esm.getHString(); - break; - case ESM::FourCC<'N','P','C','S'>::value: - mPowers.add(esm); - break; - default: - esm.fail("Unknown subrecord"); + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'F','N','A','M'>::value: + mName = esm.getHString(); + break; + case ESM::FourCC<'T','N','A','M'>::value: + mTexture = esm.getHString(); + break; + case ESM::FourCC<'D','E','S','C'>::value: + mDescription = esm.getHString(); + break; + case ESM::FourCC<'N','P','C','S'>::value: + mPowers.add(esm); + break; + default: + esm.fail("Unknown subrecord"); + } } } -} -void BirthSign::save(ESMWriter &esm) const -{ - if (mIsDeleted) + void BirthSign::save(ESMWriter &esm) const { - writeDeleSubRecord(esm); - } - esm.writeHNCString("NAME", mId); - esm.writeHNOCString("FNAM", mName); - esm.writeHNOCString("TNAM", mTexture); - esm.writeHNOCString("DESC", mDescription); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + } + esm.writeHNCString("NAME", mId); + esm.writeHNOCString("FNAM", mName); + esm.writeHNOCString("TNAM", mTexture); + esm.writeHNOCString("DESC", mDescription); - mPowers.save(esm); -} + mPowers.save(esm); + } void BirthSign::blank() { diff --git a/components/esm/loadbsgn.hpp b/components/esm/loadbsgn.hpp index 41c70fb24..685ade82f 100644 --- a/components/esm/loadbsgn.hpp +++ b/components/esm/loadbsgn.hpp @@ -24,6 +24,8 @@ struct BirthSign bool mIsDeleted; + BirthSign(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index b313435d6..bf65c5fa8 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -85,7 +85,8 @@ struct Cell mWater(0), mWaterInt(false), mMapColor(0), - mRefNumCounter(0) + mRefNumCounter(0), + mIsDeleted(false) {} // Interior cells are indexed by this (it's the 'id'), for exterior diff --git a/components/esm/loadclas.cpp b/components/esm/loadclas.cpp index df47a1a33..1384a6280 100644 --- a/components/esm/loadclas.cpp +++ b/components/esm/loadclas.cpp @@ -23,6 +23,9 @@ namespace ESM "sSpecializationStealth" }; + Class::Class() + : mIsDeleted(false) + {} int& Class::CLDTstruct::getSkill (int index, bool major) { diff --git a/components/esm/loadclas.hpp b/components/esm/loadclas.hpp index b61913734..399e93c24 100644 --- a/components/esm/loadclas.hpp +++ b/components/esm/loadclas.hpp @@ -75,6 +75,8 @@ struct Class bool mIsDeleted; + Class(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadclot.cpp b/components/esm/loadclot.cpp index 1c73c4f21..88f2e5715 100644 --- a/components/esm/loadclot.cpp +++ b/components/esm/loadclot.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Clothing::sRecordId = REC_CLOT; + Clothing::Clothing() + : mIsDeleted(false) + {} + void Clothing::load(ESMReader &esm) { mParts.mParts.clear(); diff --git a/components/esm/loadclot.hpp b/components/esm/loadclot.hpp index 8b4a8b3bb..202c1ec45 100644 --- a/components/esm/loadclot.hpp +++ b/components/esm/loadclot.hpp @@ -50,6 +50,8 @@ struct Clothing bool mIsDeleted; + Clothing(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadcont.cpp b/components/esm/loadcont.cpp index f54fe66e2..3d3d7fced 100644 --- a/components/esm/loadcont.cpp +++ b/components/esm/loadcont.cpp @@ -25,6 +25,10 @@ namespace ESM unsigned int Container::sRecordId = REC_CONT; + Container::Container() + : mIsDeleted(false) + {} + void Container::load(ESMReader &esm) { mInventory.mList.clear(); diff --git a/components/esm/loadcont.hpp b/components/esm/loadcont.hpp index 51166b8d4..31c7e1815 100644 --- a/components/esm/loadcont.hpp +++ b/components/esm/loadcont.hpp @@ -54,6 +54,8 @@ struct Container bool mIsDeleted; + Container(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index 6da32eed7..57e911e70 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Creature::sRecordId = REC_CREA; + Creature::Creature() + : mIsDeleted(false) + {} + void Creature::load(ESMReader &esm) { mPersistent = (esm.getRecordFlags() & 0x0400) != 0; diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index fb43f6272..22e834e45 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -98,6 +98,8 @@ struct Creature bool mIsDeleted; + Creature(); + const std::vector& getTransport() const; void load(ESMReader &esm); diff --git a/components/esm/loaddial.cpp b/components/esm/loaddial.cpp index 77a04ca01..667afc75c 100644 --- a/components/esm/loaddial.cpp +++ b/components/esm/loaddial.cpp @@ -13,125 +13,128 @@ namespace ESM { unsigned int Dialogue::sRecordId = REC_DIAL; -void Dialogue::load(ESMReader &esm) -{ - mIsDeleted = false; - - mId = esm.getHNString("NAME"); - esm.getSubNameIs("DATA"); - esm.getSubHeader(); - int si = esm.getSubSize(); - if (si == 1) - esm.getT(mType); - else if (si == 4) // The dialogue is deleted - { - int32_t empty; - esm.getT(empty); // Skip an empty DATA - mIsDeleted = readDeleSubRecord(esm); - } - else - esm.fail("Unknown sub record size"); -} + Dialogue::Dialogue() + : mIsDeleted(false) + {} -void Dialogue::save(ESMWriter &esm) const -{ - esm.writeHNCString("NAME", mId); - if (mIsDeleted) + void Dialogue::load(ESMReader &esm) { - esm.writeHNT("DATA", static_cast(0)); - writeDeleSubRecord(esm); - } - else - { - esm.writeHNT("DATA", mType); - } -} - -void Dialogue::blank() -{ - mInfo.clear(); -} - -void Dialogue::readInfo(ESMReader &esm, bool merge) -{ - const std::string& id = esm.getHNOString("INAM"); - - if (!merge || mInfo.empty()) - { - ESM::DialInfo info; - info.mId = id; - info.load(esm); - mLookup[id] = mInfo.insert(mInfo.end(), info); - return; + mIsDeleted = false; + + mId = esm.getHNString("NAME"); + esm.getSubNameIs("DATA"); + esm.getSubHeader(); + int si = esm.getSubSize(); + if (si == 1) + esm.getT(mType); + else if (si == 4) // The dialogue is deleted + { + int32_t empty; + esm.getT(empty); // Skip an empty DATA + mIsDeleted = readDeleSubRecord(esm); + } + else + esm.fail("Unknown sub record size"); } - ESM::Dialogue::InfoContainer::iterator it = mInfo.end(); - - std::map::iterator lookup; - - lookup = mLookup.find(id); - - ESM::DialInfo info; - if (lookup != mLookup.end()) - { - it = lookup->second; - - // Merge with existing record. Only the subrecords that are present in - // the new record will be overwritten. - it->load(esm); - info = *it; - - // Since the record merging may have changed the next/prev linked list connection, we need to re-insert the record - mInfo.erase(it); - mLookup.erase(lookup); - } - else + void Dialogue::save(ESMWriter &esm) const { - info.mId = id; - info.load(esm); + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + esm.writeHNT("DATA", static_cast(0)); + writeDeleSubRecord(esm); + } + else + { + esm.writeHNT("DATA", mType); + } } - if (info.mNext.empty()) + void Dialogue::blank() { - mLookup[id] = mInfo.insert(mInfo.end(), info); - return; - } - if (info.mPrev.empty()) - { - mLookup[id] = mInfo.insert(mInfo.begin(), info); - return; + mInfo.clear(); } - lookup = mLookup.find(info.mPrev); - if (lookup != mLookup.end()) + void Dialogue::readInfo(ESMReader &esm, bool merge) { - it = lookup->second; + const std::string& id = esm.getHNOString("INAM"); - mLookup[id] = mInfo.insert(++it, info); - return; - } + if (!merge || mInfo.empty()) + { + ESM::DialInfo info; + info.mId = id; + info.load(esm); + mLookup[id] = mInfo.insert(mInfo.end(), info); + return; + } - lookup = mLookup.find(info.mNext); - if (lookup != mLookup.end()) - { - it = lookup->second; + ESM::Dialogue::InfoContainer::iterator it = mInfo.end(); - mLookup[id] = mInfo.insert(it, info); - return; - } + std::map::iterator lookup; - std::cerr << "Failed to insert info " << id << std::endl; -} + lookup = mLookup.find(id); -void Dialogue::clearDeletedInfos() -{ - for (InfoContainer::iterator it = mInfo.begin(); it != mInfo.end(); ) - { - if (it->mQuestStatus == DialInfo::QS_Deleted) - it = mInfo.erase(it); + ESM::DialInfo info; + if (lookup != mLookup.end()) + { + it = lookup->second; + + // Merge with existing record. Only the subrecords that are present in + // the new record will be overwritten. + it->load(esm); + info = *it; + + // Since the record merging may have changed the next/prev linked list connection, we need to re-insert the record + mInfo.erase(it); + mLookup.erase(lookup); + } else - ++it; + { + info.mId = id; + info.load(esm); + } + + if (info.mNext.empty()) + { + mLookup[id] = mInfo.insert(mInfo.end(), info); + return; + } + if (info.mPrev.empty()) + { + mLookup[id] = mInfo.insert(mInfo.begin(), info); + return; + } + + lookup = mLookup.find(info.mPrev); + if (lookup != mLookup.end()) + { + it = lookup->second; + + mLookup[id] = mInfo.insert(++it, info); + return; + } + + lookup = mLookup.find(info.mNext); + if (lookup != mLookup.end()) + { + it = lookup->second; + + mLookup[id] = mInfo.insert(it, info); + return; + } + + std::cerr << "Failed to insert info " << id << std::endl; } -} + void Dialogue::clearDeletedInfos() + { + for (InfoContainer::iterator it = mInfo.begin(); it != mInfo.end(); ) + { + if (it->mQuestStatus == DialInfo::QS_Deleted) + it = mInfo.erase(it); + else + ++it; + } + } } diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index ab8cf4bff..5e7d09871 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -47,6 +47,8 @@ struct Dialogue bool mIsDeleted; + Dialogue(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loaddoor.cpp b/components/esm/loaddoor.cpp index 6ee43fd1a..87382fa7b 100644 --- a/components/esm/loaddoor.cpp +++ b/components/esm/loaddoor.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Door::sRecordId = REC_DOOR; + Door::Door() + : mIsDeleted(false) + {} + void Door::load(ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loaddoor.hpp b/components/esm/loaddoor.hpp index b0326a744..546471ed3 100644 --- a/components/esm/loaddoor.hpp +++ b/components/esm/loaddoor.hpp @@ -19,6 +19,8 @@ struct Door bool mIsDeleted; + Door(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadench.cpp b/components/esm/loadench.cpp index 88d9e0f2e..1518e0385 100644 --- a/components/esm/loadench.cpp +++ b/components/esm/loadench.cpp @@ -9,51 +9,55 @@ namespace ESM { unsigned int Enchantment::sRecordId = REC_ENCH; -void Enchantment::load(ESMReader &esm) -{ - mEffects.mList.clear(); + Enchantment::Enchantment() + : mIsDeleted(false) + {} - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) + void Enchantment::load(ESMReader &esm) { - return; - } + mEffects.mList.clear(); - bool hasData = false; - while (esm.hasMoreSubs()) - { - esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + + bool hasData = false; + while (esm.hasMoreSubs()) { - case ESM::FourCC<'E','N','D','T'>::value: - esm.getHT(mData, 16); - hasData = true; - break; - case ESM::FourCC<'E','N','A','M'>::value: - mEffects.add(esm); - break; - default: - esm.fail("Unknown subrecord"); - break; + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'E','N','D','T'>::value: + esm.getHT(mData, 16); + hasData = true; + break; + case ESM::FourCC<'E','N','A','M'>::value: + mEffects.add(esm); + break; + default: + esm.fail("Unknown subrecord"); + break; + } } + if (!hasData) + esm.fail("Missing ENDT subrecord"); } - if (!hasData) - esm.fail("Missing ENDT subrecord"); -} -void Enchantment::save(ESMWriter &esm) const -{ - esm.writeHNCString("NAME", mId); - if (mIsDeleted) + void Enchantment::save(ESMWriter &esm) const { - writeDeleSubRecord(esm); - return; - } + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } - esm.writeHNT("ENDT", mData, 16); - mEffects.save(esm); -} + esm.writeHNT("ENDT", mData, 16); + mEffects.save(esm); + } void Enchantment::blank() { diff --git a/components/esm/loadench.hpp b/components/esm/loadench.hpp index c9b19e31b..6ebe8e940 100644 --- a/components/esm/loadench.hpp +++ b/components/esm/loadench.hpp @@ -44,6 +44,8 @@ struct Enchantment bool mIsDeleted; + Enchantment(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadfact.cpp b/components/esm/loadfact.cpp index 9149c2a30..53f3aa5a6 100644 --- a/components/esm/loadfact.cpp +++ b/components/esm/loadfact.cpp @@ -11,6 +11,10 @@ namespace ESM { unsigned int Faction::sRecordId = REC_FACT; + Faction::Faction() + : mIsDeleted(false) + {} + int& Faction::FADTstruct::getSkill (int index, bool ignored) { if (index<0 || index>=7) @@ -27,82 +31,83 @@ namespace ESM return mSkills[index]; } -void Faction::load(ESMReader &esm) -{ - mReactions.clear(); - for (int i=0;i<10;++i) - mRanks[i].clear(); - - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) + void Faction::load(ESMReader &esm) { - return; - } + mReactions.clear(); + for (int i=0;i<10;++i) + mRanks[i].clear(); - int rankCounter=0; - bool hasData = false; - while (esm.hasMoreSubs()) - { - esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) { - case ESM::FourCC<'F','N','A','M'>::value: - mName = esm.getHString(); - break; - case ESM::FourCC<'R','N','A','M'>::value: - if (rankCounter >= 10) - esm.fail("Rank out of range"); - mRanks[rankCounter++] = esm.getHString(); - break; - case ESM::FourCC<'F','A','D','T'>::value: - esm.getHT(mData, 240); - if (mData.mIsHidden > 1) - esm.fail("Unknown flag!"); - hasData = true; - break; - case ESM::FourCC<'A','N','A','M'>::value: + return; + } + + int rankCounter=0; + bool hasData = false; + while (esm.hasMoreSubs()) + { + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) { - std::string faction = esm.getHString(); - int reaction; - esm.getHNT(reaction, "INTV"); - mReactions[faction] = reaction; - break; + case ESM::FourCC<'F','N','A','M'>::value: + mName = esm.getHString(); + break; + case ESM::FourCC<'R','N','A','M'>::value: + if (rankCounter >= 10) + esm.fail("Rank out of range"); + mRanks[rankCounter++] = esm.getHString(); + break; + case ESM::FourCC<'F','A','D','T'>::value: + esm.getHT(mData, 240); + if (mData.mIsHidden > 1) + esm.fail("Unknown flag!"); + hasData = true; + break; + case ESM::FourCC<'A','N','A','M'>::value: + { + std::string faction = esm.getHString(); + int reaction; + esm.getHNT(reaction, "INTV"); + mReactions[faction] = reaction; + break; + } + default: + esm.fail("Unknown subrecord"); } - default: - esm.fail("Unknown subrecord"); } + if (!hasData) + esm.fail("Missing FADT subrecord"); } - if (!hasData) - esm.fail("Missing FADT subrecord"); -} -void Faction::save(ESMWriter &esm) const -{ - esm.writeHNCString("NAME", mId); - if (mIsDeleted) + + void Faction::save(ESMWriter &esm) const { - writeDeleSubRecord(esm); - return; - } + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } - esm.writeHNOCString("FNAM", mName); + esm.writeHNOCString("FNAM", mName); - for (int i = 0; i < 10; i++) - { - if (mRanks[i].empty()) - break; + for (int i = 0; i < 10; i++) + { + if (mRanks[i].empty()) + break; - esm.writeHNString("RNAM", mRanks[i], 32); - } + esm.writeHNString("RNAM", mRanks[i], 32); + } - esm.writeHNT("FADT", mData, 240); + esm.writeHNT("FADT", mData, 240); - for (std::map::const_iterator it = mReactions.begin(); it != mReactions.end(); ++it) - { - esm.writeHNString("ANAM", it->first); - esm.writeHNT("INTV", it->second); + for (std::map::const_iterator it = mReactions.begin(); it != mReactions.end(); ++it) + { + esm.writeHNString("ANAM", it->first); + esm.writeHNT("INTV", it->second); + } } -} void Faction::blank() { diff --git a/components/esm/loadfact.hpp b/components/esm/loadfact.hpp index fec13b1ca..96c02028b 100644 --- a/components/esm/loadfact.hpp +++ b/components/esm/loadfact.hpp @@ -64,6 +64,8 @@ struct Faction bool mIsDeleted; + Faction(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadglob.cpp b/components/esm/loadglob.cpp index 6cc37d675..392df02b5 100644 --- a/components/esm/loadglob.cpp +++ b/components/esm/loadglob.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Global::sRecordId = REC_GLOB; + Global::Global() + : mIsDeleted(false) + {} + void Global::load (ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loadglob.hpp b/components/esm/loadglob.hpp index 45b47a3bc..c0219c0ba 100644 --- a/components/esm/loadglob.hpp +++ b/components/esm/loadglob.hpp @@ -26,6 +26,8 @@ struct Global bool mIsDeleted; + Global(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index 3b5e0ea3a..4c997213a 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -9,169 +9,173 @@ namespace ESM { unsigned int DialInfo::sRecordId = REC_INFO; -void DialInfo::load(ESMReader &esm) -{ - mQuestStatus = QS_None; - mFactionLess = false; - - mPrev = esm.getHNString("PNAM"); - mNext = esm.getHNString("NNAM"); + DialInfo::DialInfo() + : mIsDeleted(false) + {} - // Since there's no way to mark selects as "deleted", we have to clear the SelectStructs from all previous loadings - mSelects.clear(); - - // If the info is deleted, NAME and DELE sub-records are followed after NNAM - if (esm.isNextSub("NAME")) + void DialInfo::load(ESMReader &esm) { - mResponse = esm.getHString(); - mIsDeleted = readDeleSubRecord(esm); - return; - } - - esm.getSubNameIs("DATA"); - esm.getHT(mData, 12); - - if (!esm.hasMoreSubs()) - return; - - // What follows is somewhat spaghetti-ish, but it's worth if for - // an extra speedup. INFO is by far the most common record type. + mQuestStatus = QS_None; + mFactionLess = false; - // subName is a reference to the original, so it changes whenever - // a new sub name is read. esm.isEmptyOrGetName() will get the - // next name for us, or return true if there are no more records. - esm.getSubName(); - const NAME &subName = esm.retSubName(); + mPrev = esm.getHNString("PNAM"); + mNext = esm.getHNString("NNAM"); - if (subName.val == REC_ONAM) - { - mActor = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } - if (subName.val == REC_RNAM) - { - mRace = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } - if (subName.val == REC_CNAM) - { - mClass = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } + // Since there's no way to mark selects as "deleted", we have to clear the SelectStructs from all previous loadings + mSelects.clear(); - if (subName.val == REC_FNAM) - { - mFaction = esm.getHString(); - if (mFaction == "FFFF") - mFactionLess = true; - if (esm.isEmptyOrGetName()) - return; - } - if (subName.val == REC_ANAM) - { - mCell = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } - if (subName.val == REC_DNAM) - { - mPcFaction = esm.getHString(); - if (esm.isEmptyOrGetName()) + // If the info is deleted, NAME and DELE sub-records are followed after NNAM + if (esm.isNextSub("NAME")) + { + mResponse = esm.getHString(); + mIsDeleted = readDeleSubRecord(esm); return; - } - if (subName.val == REC_SNAM) - { - mSound = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } - if (subName.val == REC_NAME) - { - mResponse = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } + } - while (subName.val == REC_SCVR) - { - SelectStruct ss; - - ss.mSelectRule = esm.getHString(); - - ss.mValue.read (esm, Variant::Format_Info); - - mSelects.push_back(ss); - - if (esm.isEmptyOrGetName()) - return; - } + esm.getSubNameIs("DATA"); + esm.getHT(mData, 12); - if (subName.val == REC_BNAM) - { - mResultScript = esm.getHString(); - if (esm.isEmptyOrGetName()) + if (!esm.hasMoreSubs()) return; - } - if (subName.val == REC_QSTN) - mQuestStatus = QS_Name; - else if (subName.val == REC_QSTF) - mQuestStatus = QS_Finished; - else if (subName.val == REC_QSTR) - mQuestStatus = QS_Restart; - else if (subName.val == REC_DELE) - mQuestStatus = QS_Deleted; - else - esm.fail( - "Don't know what to do with " + subName.toString() - + " in INFO " + mId); - - if (mQuestStatus != QS_None) - // Skip rest of record - esm.skipRecord(); -} - -void DialInfo::save(ESMWriter &esm) const -{ - esm.writeHNCString("PNAM", mPrev); - esm.writeHNCString("NNAM", mNext); - if (mIsDeleted) - { - esm.writeHNCString("NAME", mResponse); - writeDeleSubRecord(esm); - return; + // What follows is somewhat spaghetti-ish, but it's worth if for + // an extra speedup. INFO is by far the most common record type. + + // subName is a reference to the original, so it changes whenever + // a new sub name is read. esm.isEmptyOrGetName() will get the + // next name for us, or return true if there are no more records. + esm.getSubName(); + const NAME &subName = esm.retSubName(); + + if (subName.val == REC_ONAM) + { + mActor = esm.getHString(); + if (esm.isEmptyOrGetName()) + return; + } + if (subName.val == REC_RNAM) + { + mRace = esm.getHString(); + if (esm.isEmptyOrGetName()) + return; + } + if (subName.val == REC_CNAM) + { + mClass = esm.getHString(); + if (esm.isEmptyOrGetName()) + return; + } + + if (subName.val == REC_FNAM) + { + mFaction = esm.getHString(); + if (mFaction == "FFFF") + mFactionLess = true; + if (esm.isEmptyOrGetName()) + return; + } + if (subName.val == REC_ANAM) + { + mCell = esm.getHString(); + if (esm.isEmptyOrGetName()) + return; + } + if (subName.val == REC_DNAM) + { + mPcFaction = esm.getHString(); + if (esm.isEmptyOrGetName()) + return; + } + if (subName.val == REC_SNAM) + { + mSound = esm.getHString(); + if (esm.isEmptyOrGetName()) + return; + } + if (subName.val == REC_NAME) + { + mResponse = esm.getHString(); + if (esm.isEmptyOrGetName()) + return; + } + + while (subName.val == REC_SCVR) + { + SelectStruct ss; + + ss.mSelectRule = esm.getHString(); + + ss.mValue.read (esm, Variant::Format_Info); + + mSelects.push_back(ss); + + if (esm.isEmptyOrGetName()) + return; + } + + if (subName.val == REC_BNAM) + { + mResultScript = esm.getHString(); + if (esm.isEmptyOrGetName()) + return; + } + + if (subName.val == REC_QSTN) + mQuestStatus = QS_Name; + else if (subName.val == REC_QSTF) + mQuestStatus = QS_Finished; + else if (subName.val == REC_QSTR) + mQuestStatus = QS_Restart; + else if (subName.val == REC_DELE) + mQuestStatus = QS_Deleted; + else + esm.fail( + "Don't know what to do with " + subName.toString() + + " in INFO " + mId); + + if (mQuestStatus != QS_None) + // Skip rest of record + esm.skipRecord(); } - esm.writeHNT("DATA", mData, 12); - esm.writeHNOCString("ONAM", mActor); - esm.writeHNOCString("RNAM", mRace); - esm.writeHNOCString("CNAM", mClass); - esm.writeHNOCString("FNAM", mFaction); - esm.writeHNOCString("ANAM", mCell); - esm.writeHNOCString("DNAM", mPcFaction); - esm.writeHNOCString("SNAM", mSound); - esm.writeHNOString("NAME", mResponse); - - for (std::vector::const_iterator it = mSelects.begin(); it != mSelects.end(); ++it) + void DialInfo::save(ESMWriter &esm) const { - esm.writeHNString("SCVR", it->mSelectRule); - it->mValue.write (esm, Variant::Format_Info); - } - - esm.writeHNOString("BNAM", mResultScript); - - switch(mQuestStatus) - { - case QS_Name: esm.writeHNT("QSTN",'\1'); break; - case QS_Finished: esm.writeHNT("QSTF", '\1'); break; - case QS_Restart: esm.writeHNT("QSTR", '\1'); break; - case QS_Deleted: esm.writeHNT("DELE", '\1'); break; - default: break; + esm.writeHNCString("PNAM", mPrev); + esm.writeHNCString("NNAM", mNext); + if (mIsDeleted) + { + esm.writeHNCString("NAME", mResponse); + writeDeleSubRecord(esm); + return; + } + + esm.writeHNT("DATA", mData, 12); + esm.writeHNOCString("ONAM", mActor); + esm.writeHNOCString("RNAM", mRace); + esm.writeHNOCString("CNAM", mClass); + esm.writeHNOCString("FNAM", mFaction); + esm.writeHNOCString("ANAM", mCell); + esm.writeHNOCString("DNAM", mPcFaction); + esm.writeHNOCString("SNAM", mSound); + esm.writeHNOString("NAME", mResponse); + + for (std::vector::const_iterator it = mSelects.begin(); it != mSelects.end(); ++it) + { + esm.writeHNString("SCVR", it->mSelectRule); + it->mValue.write (esm, Variant::Format_Info); + } + + esm.writeHNOString("BNAM", mResultScript); + + switch(mQuestStatus) + { + case QS_Name: esm.writeHNT("QSTN",'\1'); break; + case QS_Finished: esm.writeHNT("QSTF", '\1'); break; + case QS_Restart: esm.writeHNT("QSTR", '\1'); break; + case QS_Deleted: esm.writeHNT("DELE", '\1'); break; + default: break; + } } -} void DialInfo::blank() { diff --git a/components/esm/loadinfo.hpp b/components/esm/loadinfo.hpp index 8b4fae761..fbb7e36a5 100644 --- a/components/esm/loadinfo.hpp +++ b/components/esm/loadinfo.hpp @@ -108,6 +108,8 @@ struct DialInfo bool mIsDeleted; + DialInfo(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadingr.cpp b/components/esm/loadingr.cpp index 8bf0278f7..a7018b36d 100644 --- a/components/esm/loadingr.cpp +++ b/components/esm/loadingr.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Ingredient::sRecordId = REC_INGR; + Ingredient::Ingredient() + : mIsDeleted(false) + {} + void Ingredient::load(ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loadingr.hpp b/components/esm/loadingr.hpp index 69a650180..c92f28f18 100644 --- a/components/esm/loadingr.hpp +++ b/components/esm/loadingr.hpp @@ -33,6 +33,8 @@ struct Ingredient bool mIsDeleted; + Ingredient(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadlevlist.cpp b/components/esm/loadlevlist.cpp index c8cb110a6..1e07086bc 100644 --- a/components/esm/loadlevlist.cpp +++ b/components/esm/loadlevlist.cpp @@ -7,6 +7,9 @@ namespace ESM { + LevelledListBase::LevelledListBase() + : mIsDeleted(false) + {} void LevelledListBase::load(ESMReader &esm) { diff --git a/components/esm/loadlevlist.hpp b/components/esm/loadlevlist.hpp index 4165275b2..14ebc9937 100644 --- a/components/esm/loadlevlist.hpp +++ b/components/esm/loadlevlist.hpp @@ -38,6 +38,8 @@ struct LevelledListBase bool mIsDeleted; + LevelledListBase(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadligh.cpp b/components/esm/loadligh.cpp index bd91e096c..a153d500a 100644 --- a/components/esm/loadligh.cpp +++ b/components/esm/loadligh.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Light::sRecordId = REC_LIGH; + Light::Light() + : mIsDeleted(false) + {} + void Light::load(ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loadligh.hpp b/components/esm/loadligh.hpp index 76274e6f4..d4d3418d8 100644 --- a/components/esm/loadligh.hpp +++ b/components/esm/loadligh.hpp @@ -49,6 +49,8 @@ struct Light bool mIsDeleted; + Light(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadlock.cpp b/components/esm/loadlock.cpp index c1e866b58..3b169af33 100644 --- a/components/esm/loadlock.cpp +++ b/components/esm/loadlock.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Lockpick::sRecordId = REC_LOCK; + Lockpick::Lockpick() + : mIsDeleted(false) + {} + void Lockpick::load(ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loadlock.hpp b/components/esm/loadlock.hpp index af18773ed..ce7de2c06 100644 --- a/components/esm/loadlock.hpp +++ b/components/esm/loadlock.hpp @@ -29,6 +29,8 @@ struct Lockpick bool mIsDeleted; + Lockpick(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadltex.cpp b/components/esm/loadltex.cpp index 0ee30b11c..13315e684 100644 --- a/components/esm/loadltex.cpp +++ b/components/esm/loadltex.cpp @@ -9,29 +9,32 @@ namespace ESM { unsigned int LandTexture::sRecordId = REC_LTEX; -void LandTexture::load(ESMReader &esm) -{ - mIsDeleted = readDeleSubRecord(esm); - mId = esm.getHNString("NAME"); - esm.getHNT(mIndex, "INTV"); - mTexture = esm.getHNString("DATA"); -} -void LandTexture::save(ESMWriter &esm) const -{ - if (mIsDeleted) + LandTexture::LandTexture() + : mIsDeleted(false) + {} + + void LandTexture::load(ESMReader &esm) { - writeDeleSubRecord(esm); + mIsDeleted = readDeleSubRecord(esm); + mId = esm.getHNString("NAME"); + esm.getHNT(mIndex, "INTV"); + mTexture = esm.getHNString("DATA"); + } + void LandTexture::save(ESMWriter &esm) const + { + if (mIsDeleted) + { + writeDeleSubRecord(esm); + } + esm.writeHNCString("NAME", mId); + esm.writeHNT("INTV", mIndex); + esm.writeHNCString("DATA", mTexture); } - esm.writeHNCString("NAME", mId); - esm.writeHNT("INTV", mIndex); - esm.writeHNCString("DATA", mTexture); -} - -void LandTexture::blank() -{ - mTexture.clear(); - mIndex = -1; - mIsDeleted = false; -} + void LandTexture::blank() + { + mTexture.clear(); + mIndex = -1; + mIsDeleted = false; + } } diff --git a/components/esm/loadltex.hpp b/components/esm/loadltex.hpp index e019e269e..33af77612 100644 --- a/components/esm/loadltex.hpp +++ b/components/esm/loadltex.hpp @@ -36,11 +36,13 @@ struct LandTexture bool mIsDeleted; - void blank(); - ///< Set record to default state (does not touch the ID). + LandTexture(); void load(ESMReader &esm); void save(ESMWriter &esm) const; + + void blank(); + ///< Set record to default state (does not touch the ID). }; } #endif diff --git a/components/esm/loadmisc.cpp b/components/esm/loadmisc.cpp index 11d2f2a05..08cbcf741 100644 --- a/components/esm/loadmisc.cpp +++ b/components/esm/loadmisc.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Miscellaneous::sRecordId = REC_MISC; + Miscellaneous::Miscellaneous() + : mIsDeleted(false) + {} + void Miscellaneous::load(ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loadmisc.hpp b/components/esm/loadmisc.hpp index 5d5e9f66f..82018cd72 100644 --- a/components/esm/loadmisc.hpp +++ b/components/esm/loadmisc.hpp @@ -34,6 +34,8 @@ struct Miscellaneous bool mIsDeleted; + Miscellaneous(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index 280db0791..eadf23a21 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int NPC::sRecordId = REC_NPC_; + NPC::NPC() + : mIsDeleted(false) + {} + void NPC::load(ESMReader &esm) { mPersistent = (esm.getRecordFlags() & 0x0400) != 0; diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index 7b75cb178..263752752 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -132,6 +132,8 @@ struct NPC bool mIsDeleted; + NPC(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadprob.cpp b/components/esm/loadprob.cpp index 12f7ad00a..f5287f986 100644 --- a/components/esm/loadprob.cpp +++ b/components/esm/loadprob.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Probe::sRecordId = REC_PROB; + Probe::Probe() + : mIsDeleted(false) + {} + void Probe::load(ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loadprob.hpp b/components/esm/loadprob.hpp index 9daab6b1b..748d498fc 100644 --- a/components/esm/loadprob.hpp +++ b/components/esm/loadprob.hpp @@ -29,6 +29,8 @@ struct Probe bool mIsDeleted; + Probe(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadregn.cpp b/components/esm/loadregn.cpp index b0adc6f58..2d99947b0 100644 --- a/components/esm/loadregn.cpp +++ b/components/esm/loadregn.cpp @@ -9,69 +9,74 @@ namespace ESM { unsigned int Region::sRecordId = REC_REGN; -void Region::load(ESMReader &esm) -{ - mIsDeleted = readDeleSubRecord(esm); - mId = esm.getHNString("NAME"); - mName = esm.getHNOString("FNAM"); + Region::Region() + : mIsDeleted(false) + {} - esm.getSubNameIs("WEAT"); - esm.getSubHeader(); - if (esm.getVer() == VER_12) - { - mData.mA = 0; - mData.mB = 0; - esm.getExact(&mData, sizeof(mData) - 2); - } - else if (esm.getVer() == VER_13) + void Region::load(ESMReader &esm) { - // May include the additional two bytes (but not necessarily) - if (esm.getSubSize() == sizeof(mData)) - esm.getExact(&mData, sizeof(mData)); - else + mIsDeleted = readDeleSubRecord(esm); + mId = esm.getHNString("NAME"); + mName = esm.getHNOString("FNAM"); + + esm.getSubNameIs("WEAT"); + esm.getSubHeader(); + if (esm.getVer() == VER_12) { mData.mA = 0; mData.mB = 0; - esm.getExact(&mData, sizeof(mData)-2); + esm.getExact(&mData, sizeof(mData) - 2); } - } - else - esm.fail("Don't know what to do in this version"); + else if (esm.getVer() == VER_13) + { + // May include the additional two bytes (but not necessarily) + if (esm.getSubSize() == sizeof(mData)) + esm.getExact(&mData, sizeof(mData)); + else + { + mData.mA = 0; + mData.mB = 0; + esm.getExact(&mData, sizeof(mData)-2); + } + } + else + esm.fail("Don't know what to do in this version"); - mSleepList = esm.getHNOString("BNAM"); + mSleepList = esm.getHNOString("BNAM"); - esm.getHNT(mMapColor, "CNAM"); + esm.getHNT(mMapColor, "CNAM"); - mSoundList.clear(); - while (esm.hasMoreSubs()) - { - SoundRef sr; - esm.getHNT(sr, "SNAM", 33); - mSoundList.push_back(sr); + mSoundList.clear(); + while (esm.hasMoreSubs()) + { + SoundRef sr; + esm.getHNT(sr, "SNAM", 33); + mSoundList.push_back(sr); + } } -} -void Region::save(ESMWriter &esm) const -{ - if (mIsDeleted) + + void Region::save(ESMWriter &esm) const { - writeDeleSubRecord(esm); - } - esm.writeHNString("NAME", mId); - esm.writeHNOCString("FNAM", mName); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + } + esm.writeHNString("NAME", mId); + esm.writeHNOCString("FNAM", mName); - if (esm.getVersion() == VER_12) - esm.writeHNT("WEAT", mData, sizeof(mData) - 2); - else - esm.writeHNT("WEAT", mData); + if (esm.getVersion() == VER_12) + esm.writeHNT("WEAT", mData, sizeof(mData) - 2); + else + esm.writeHNT("WEAT", mData); - esm.writeHNOCString("BNAM", mSleepList); + esm.writeHNOCString("BNAM", mSleepList); - esm.writeHNT("CNAM", mMapColor); - for (std::vector::const_iterator it = mSoundList.begin(); it != mSoundList.end(); ++it) - { - esm.writeHNT("SNAM", *it); + esm.writeHNT("CNAM", mMapColor); + for (std::vector::const_iterator it = mSoundList.begin(); it != mSoundList.end(); ++it) + { + esm.writeHNT("SNAM", *it); + } } -} void Region::blank() { diff --git a/components/esm/loadregn.hpp b/components/esm/loadregn.hpp index 921ab887b..9082437fe 100644 --- a/components/esm/loadregn.hpp +++ b/components/esm/loadregn.hpp @@ -53,6 +53,8 @@ struct Region bool mIsDeleted; + Region(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadrepa.cpp b/components/esm/loadrepa.cpp index 608536f02..fb213efd8 100644 --- a/components/esm/loadrepa.cpp +++ b/components/esm/loadrepa.cpp @@ -9,61 +9,65 @@ namespace ESM { unsigned int Repair::sRecordId = REC_REPA; -void Repair::load(ESMReader &esm) -{ - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + Repair::Repair() + : mIsDeleted(false) + {} - bool hasData = true; - while (esm.hasMoreSubs()) + void Repair::load(ESMReader &esm) { - esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) { - case ESM::FourCC<'M','O','D','L'>::value: - mModel = esm.getHString(); - break; - case ESM::FourCC<'F','N','A','M'>::value: - mName = esm.getHString(); - break; - case ESM::FourCC<'R','I','D','T'>::value: - esm.getHT(mData, 16); - hasData = true; - break; - case ESM::FourCC<'S','C','R','I'>::value: - mScript = esm.getHString(); - break; - case ESM::FourCC<'I','T','E','X'>::value: - mIcon = esm.getHString(); - break; - default: - esm.fail("Unknown subrecord"); + return; } + + bool hasData = true; + while (esm.hasMoreSubs()) + { + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'M','O','D','L'>::value: + mModel = esm.getHString(); + break; + case ESM::FourCC<'F','N','A','M'>::value: + mName = esm.getHString(); + break; + case ESM::FourCC<'R','I','D','T'>::value: + esm.getHT(mData, 16); + hasData = true; + break; + case ESM::FourCC<'S','C','R','I'>::value: + mScript = esm.getHString(); + break; + case ESM::FourCC<'I','T','E','X'>::value: + mIcon = esm.getHString(); + break; + default: + esm.fail("Unknown subrecord"); + } + } + if (!hasData) + esm.fail("Missing RIDT subrecord"); } - if (!hasData) - esm.fail("Missing RIDT subrecord"); -} -void Repair::save(ESMWriter &esm) const -{ - esm.writeHNCString("NAME", mId); - if (mIsDeleted) + void Repair::save(ESMWriter &esm) const { - writeDeleSubRecord(esm); - return; - } + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } - esm.writeHNCString("MODL", mModel); - esm.writeHNOCString("FNAM", mName); + esm.writeHNCString("MODL", mModel); + esm.writeHNOCString("FNAM", mName); - esm.writeHNT("RIDT", mData, 16); - esm.writeHNOString("SCRI", mScript); - esm.writeHNOCString("ITEX", mIcon); -} + esm.writeHNT("RIDT", mData, 16); + esm.writeHNOString("SCRI", mScript); + esm.writeHNOCString("ITEX", mIcon); + } void Repair::blank() { diff --git a/components/esm/loadrepa.hpp b/components/esm/loadrepa.hpp index a660574be..1448f9c77 100644 --- a/components/esm/loadrepa.hpp +++ b/components/esm/loadrepa.hpp @@ -29,6 +29,8 @@ struct Repair bool mIsDeleted; + Repair(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index 67c1b8f6f..529f0a66d 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -9,9 +9,12 @@ namespace ESM { - unsigned int Script::sRecordId = REC_SCPT; + Script::Script() + : mIsDeleted(false) + {} + void Script::loadSCVR(ESMReader &esm) { int s = mData.mStringTableSize; diff --git a/components/esm/loadscpt.hpp b/components/esm/loadscpt.hpp index 401dfe105..58b5842e8 100644 --- a/components/esm/loadscpt.hpp +++ b/components/esm/loadscpt.hpp @@ -52,6 +52,8 @@ public: bool mIsDeleted; + Script(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadsndg.cpp b/components/esm/loadsndg.cpp index f92c4eee8..261087be0 100644 --- a/components/esm/loadsndg.cpp +++ b/components/esm/loadsndg.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int SoundGenerator::sRecordId = REC_SNDG; + SoundGenerator::SoundGenerator() + : mIsDeleted(false) + {} + void SoundGenerator::load(ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loadsndg.hpp b/components/esm/loadsndg.hpp index e486976f5..13eb18072 100644 --- a/components/esm/loadsndg.hpp +++ b/components/esm/loadsndg.hpp @@ -38,6 +38,8 @@ struct SoundGenerator bool mIsDeleted; + SoundGenerator(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadsoun.cpp b/components/esm/loadsoun.cpp index 19e8a5d80..9a1a52b1e 100644 --- a/components/esm/loadsoun.cpp +++ b/components/esm/loadsoun.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Sound::sRecordId = REC_SOUN; + Sound::Sound() + : mIsDeleted(false) + {} + void Sound::load(ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loadsoun.hpp b/components/esm/loadsoun.hpp index 95c89b29d..0b40ae751 100644 --- a/components/esm/loadsoun.hpp +++ b/components/esm/loadsoun.hpp @@ -25,6 +25,8 @@ struct Sound bool mIsDeleted; + Sound(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadspel.cpp b/components/esm/loadspel.cpp index cac06b200..d2d8c7d6d 100644 --- a/components/esm/loadspel.cpp +++ b/components/esm/loadspel.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Spell::sRecordId = REC_SPEL; + Spell::Spell() + : mIsDeleted(false) + {} + void Spell::load(ESMReader &esm) { mEffects.mList.clear(); diff --git a/components/esm/loadspel.hpp b/components/esm/loadspel.hpp index 2aba131ad..327e94d8f 100644 --- a/components/esm/loadspel.hpp +++ b/components/esm/loadspel.hpp @@ -47,6 +47,8 @@ struct Spell bool mIsDeleted; + Spell(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadstat.cpp b/components/esm/loadstat.cpp index a49caba89..2fde46bd2 100644 --- a/components/esm/loadstat.cpp +++ b/components/esm/loadstat.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Static::sRecordId = REC_STAT; + Static::Static() + : mIsDeleted(false) + {} + void Static::load(ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loadstat.hpp b/components/esm/loadstat.hpp index c4306ad8f..f88ad671b 100644 --- a/components/esm/loadstat.hpp +++ b/components/esm/loadstat.hpp @@ -30,6 +30,8 @@ struct Static bool mIsDeleted; + Static(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadweap.cpp b/components/esm/loadweap.cpp index 66d65d0f5..38fb94adb 100644 --- a/components/esm/loadweap.cpp +++ b/components/esm/loadweap.cpp @@ -9,6 +9,10 @@ namespace ESM { unsigned int Weapon::sRecordId = REC_WEAP; + Weapon::Weapon() + : mIsDeleted(false) + {} + void Weapon::load(ESMReader &esm) { mId = esm.getHNString("NAME"); diff --git a/components/esm/loadweap.hpp b/components/esm/loadweap.hpp index 30dfbc92a..ce61eeb72 100644 --- a/components/esm/loadweap.hpp +++ b/components/esm/loadweap.hpp @@ -71,6 +71,8 @@ struct Weapon bool mIsDeleted; + Weapon(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; From e0983c815c32c9b79d340100ab2b4b6750820554 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sat, 11 Jul 2015 22:17:53 +0300 Subject: [PATCH 18/49] Some fixes for ESM Dialogues and Infos --- apps/openmw/mwworld/store.hpp | 3 ++- components/esm/loaddial.cpp | 2 ++ components/esm/loaddial.hpp | 3 ++- components/esm/loadinfo.cpp | 3 +++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index c482486d8..ff0ca0159 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -371,7 +371,8 @@ namespace MWWorld } else { - found->second = dialogue; + found->second.mIsDeleted = dialogue.mIsDeleted; + found->second.mType = dialogue.mType; } mLastAddedRecord = dialogue; diff --git a/components/esm/loaddial.cpp b/components/esm/loaddial.cpp index 667afc75c..aeec46872 100644 --- a/components/esm/loaddial.cpp +++ b/components/esm/loaddial.cpp @@ -32,6 +32,7 @@ namespace ESM int32_t empty; esm.getT(empty); // Skip an empty DATA mIsDeleted = readDeleSubRecord(esm); + mType = Unknown; } else esm.fail("Unknown sub record size"); @@ -54,6 +55,7 @@ namespace ESM void Dialogue::blank() { mInfo.clear(); + mIsDeleted = false; } void Dialogue::readInfo(ESMReader &esm, bool merge) diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index 5e7d09871..8fc7e14e9 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -30,7 +30,8 @@ struct Dialogue Voice = 1, Greeting = 2, Persuasion = 3, - Journal = 4 + Journal = 4, + Unknown = -1 // Used for deleted dialogues }; std::string mId; diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index 4c997213a..c1b12e24c 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -17,6 +17,7 @@ namespace ESM { mQuestStatus = QS_None; mFactionLess = false; + mIsDeleted = false; mPrev = esm.getHNString("PNAM"); mNext = esm.getHNString("NNAM"); @@ -142,6 +143,7 @@ namespace ESM { esm.writeHNCString("PNAM", mPrev); esm.writeHNCString("NNAM", mNext); + if (mIsDeleted) { esm.writeHNCString("NAME", mResponse); @@ -200,5 +202,6 @@ namespace ESM mResultScript.clear(); mFactionLess = false; mQuestStatus = QS_None; + mIsDeleted = false; } } From adec0cb61df161e4bb25d0387d7a1ecde21363cb Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 12 Jul 2015 00:19:04 +0300 Subject: [PATCH 19/49] Add removing of deleted Infos to Dialogue::clearDeletedInfos() --- components/esm/loaddial.cpp | 2 +- components/esm/loaddial.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/esm/loaddial.cpp b/components/esm/loaddial.cpp index aeec46872..dfac0ce63 100644 --- a/components/esm/loaddial.cpp +++ b/components/esm/loaddial.cpp @@ -133,7 +133,7 @@ namespace ESM { for (InfoContainer::iterator it = mInfo.begin(); it != mInfo.end(); ) { - if (it->mQuestStatus == DialInfo::QS_Deleted) + if (it->mIsDeleted || it->mQuestStatus == DialInfo::QS_Deleted) it = mInfo.erase(it); else ++it; diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index 8fc7e14e9..e80a7b0b2 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -53,7 +53,7 @@ struct Dialogue void load(ESMReader &esm); void save(ESMWriter &esm) const; - /// Remove all INFOs marked as QS_Deleted from mInfos. + /// Remove all INFOs that are deleted or marked as QS_Deleted from mInfos. void clearDeletedInfos(); /// Read the next info record From c266315a355480ad6e4bc665e5d4150c6c8de8f3 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 12 Jul 2015 15:20:22 +0300 Subject: [PATCH 20/49] Load/read methods in MWWorld::Store return a pair (record ID, deleted flag) --- apps/openmw/mwworld/esmstore.cpp | 18 ++++----- apps/openmw/mwworld/store.cpp | 67 +++++++++++++------------------- apps/openmw/mwworld/store.hpp | 39 ++++++++----------- components/esm/util.hpp | 6 --- 4 files changed, 53 insertions(+), 77 deletions(-) diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 99d32d06b..50324f3e8 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -96,22 +96,21 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener) throw std::runtime_error(error.str()); } } else { - it->second->load(esm); - std::string id = it->second->getLastAddedRecordId(); - if (it->second->isLastAddedRecordDeleted()) + RecordId id = it->second->load(esm); + if (id.mIsDeleted) { - it->second->eraseStatic(id); + it->second->eraseStatic(id.mId); continue; } if (n.val==ESM::REC_DIAL) { - dialogue = const_cast(mDialogs.find(id)); + dialogue = const_cast(mDialogs.find(id.mId)); } else { dialogue = 0; } // Insert the reference into the global lookup - if (!id.empty() && isCacheableRecord(n.val)) { - mIds[Misc::StringUtils::lowerCase (id)] = n.val; + if (!id.mId.empty() && isCacheableRecord(n.val)) { + mIds[Misc::StringUtils::lowerCase (id.mId)] = n.val; } } listener->setProgress(static_cast(esm.getFileOffset() / (float)esm.getFileSize() * 1000)); @@ -184,13 +183,12 @@ void ESMStore::setUp() case ESM::REC_LEVC: { - StoreBase *store = mStores[type]; - store->read (reader); + RecordId id = mStores[type]->read (reader); // FIXME: there might be stale dynamic IDs in mIds from an earlier savegame // that really should be cleared instead of just overwritten - mIds[store->getLastAddedRecordId()] = type; + mIds[id.mId] = type; } if (type==ESM::REC_NPC_) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index aeb96dcab..c8c42d17d 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -44,6 +44,10 @@ namespace namespace MWWorld { + RecordId::RecordId(const std::string &id, bool isDeleted) + : mId(id), mIsDeleted(isDeleted) + {} + template IndexedStore::IndexedStore() { @@ -180,7 +184,7 @@ namespace MWWorld return ptr; } template - void Store::load(ESM::ESMReader &esm) + RecordId Store::load(ESM::ESMReader &esm) { T record; record.load(esm); @@ -190,7 +194,7 @@ namespace MWWorld if (inserted.second) mShared.push_back(&inserted.first->second); - mLastAddedRecord = record; + return RecordId(record.mId, ESM::isRecordDeleted(record)); } template void Store::setUp() @@ -317,25 +321,13 @@ namespace MWWorld } } template - void Store::read(ESM::ESMReader& reader) + RecordId Store::read(ESM::ESMReader& reader) { T record; record.load (reader); insert (record); - mLastAddedRecord = record; - } - - - template - std::string Store::getLastAddedRecordId() const - { - return ESM::getRecordId(mLastAddedRecord); - } - template - bool Store::isLastAddedRecordDeleted() const - { - return ESM::isRecordDeleted(mLastAddedRecord); + return RecordId(record.mId, ESM::isRecordDeleted(record)); } // LandTexture @@ -375,7 +367,7 @@ namespace MWWorld assert(plugin < mStatic.size()); return mStatic[plugin].size(); } - void Store::load(ESM::ESMReader &esm, size_t plugin) + RecordId Store::load(ESM::ESMReader &esm, size_t plugin) { ESM::LandTexture lt; lt.load(esm); @@ -389,11 +381,13 @@ namespace MWWorld ltexl.resize(lt.mIndex+1); // Store it - ltexl[lt.mIndex] = mLastAddedRecord = lt; + ltexl[lt.mIndex] = lt; + + return RecordId(lt.mId, lt.mIsDeleted); } - void Store::load(ESM::ESMReader &esm) + RecordId Store::load(ESM::ESMReader &esm) { - load(esm, esm.getIndex()); + return load(esm, esm.getIndex()); } Store::iterator Store::begin(size_t plugin) const { @@ -405,16 +399,6 @@ namespace MWWorld assert(plugin < mStatic.size()); return mStatic[plugin].end(); } - - std::string Store::getLastAddedRecordId() const - { - return ESM::getRecordId(mLastAddedRecord); - } - - bool Store::isLastAddedRecordDeleted() const - { - return ESM::isRecordDeleted(mLastAddedRecord); - } // Land //========================================================================= @@ -462,7 +446,7 @@ namespace MWWorld } return ptr; } - void Store::load(ESM::ESMReader &esm) + RecordId Store::load(ESM::ESMReader &esm) { ESM::Land *ptr = new ESM::Land(); ptr->load(esm); @@ -480,6 +464,8 @@ namespace MWWorld } mStatic.push_back(ptr); + + return RecordId(); // No ID and can't be deleted (for now) } void Store::setUp() { @@ -622,7 +608,7 @@ namespace MWWorld mSharedExt.push_back(&(it->second)); } } - void Store::load(ESM::ESMReader &esm) + RecordId Store::load(ESM::ESMReader &esm) { // Don't automatically assume that a new cell must be spawned. Multiple plugins write to the same cell, // and we merge all this data into one Cell object. However, we can't simply search for the cell id, @@ -704,6 +690,7 @@ namespace MWWorld mExt[std::make_pair(cell.mData.mX, cell.mData.mY)] = cell; } } + return RecordId("", cell.mIsDeleted); } Store::iterator Store::intBegin() const { @@ -859,7 +846,7 @@ namespace MWWorld { mCells = &cells; } - void Store::load(ESM::ESMReader &esm) + RecordId Store::load(ESM::ESMReader &esm) { ESM::Pathgrid pathgrid; pathgrid.load(esm); @@ -884,6 +871,8 @@ namespace MWWorld if (!ret.second) ret.first->second = pathgrid; } + + return RecordId(); // No ID and can't be deleted (for now) } size_t Store::getSize() const { @@ -1035,7 +1024,7 @@ namespace MWWorld } template <> - inline void Store::load(ESM::ESMReader &esm) { + inline RecordId Store::load(ESM::ESMReader &esm) { // The original letter case of a dialogue ID is saved, because it's printed ESM::Dialogue dialogue; dialogue.load(esm); @@ -1053,7 +1042,7 @@ namespace MWWorld found->second.mType = dialogue.mType; } - mLastAddedRecord = dialogue; + return RecordId(dialogue.mId, dialogue.mIsDeleted); } @@ -1061,7 +1050,7 @@ namespace MWWorld //========================================================================= template <> - inline void Store::load(ESM::ESMReader &esm) { + inline RecordId Store::load(ESM::ESMReader &esm) { ESM::Script script; script.load(esm); Misc::StringUtils::toLower(script.mId); @@ -1072,7 +1061,7 @@ namespace MWWorld else inserted.first->second = script; - mLastAddedRecord = script; + return RecordId(script.mId, script.mIsDeleted); } @@ -1080,7 +1069,7 @@ namespace MWWorld //========================================================================= template <> - inline void Store::load(ESM::ESMReader &esm) + inline RecordId Store::load(ESM::ESMReader &esm) { ESM::StartScript script; script.load(esm); @@ -1092,7 +1081,7 @@ namespace MWWorld else inserted.first->second = script; - mLastAddedRecord = script; + return RecordId(script.mId); } } diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 0fdfffd41..bbbd30cd0 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -19,6 +19,14 @@ namespace Loading namespace MWWorld { + struct RecordId + { + std::string mId; + bool mIsDeleted; + + RecordId(const std::string &id = "", bool isDeleted = false); + }; + struct StoreBase { virtual ~StoreBase() {} @@ -28,19 +36,15 @@ namespace MWWorld virtual size_t getSize() const = 0; virtual int getDynamicSize() const { return 0; } - virtual void load(ESM::ESMReader &esm) = 0; + virtual RecordId load(ESM::ESMReader &esm) = 0; virtual bool eraseStatic(const std::string &id) {return false;} virtual void clearDynamic() {} virtual void write (ESM::ESMWriter& writer, Loading::Listener& progress) const {} - virtual void read (ESM::ESMReader& reader) {} + virtual RecordId read (ESM::ESMReader& reader) { return RecordId(); } ///< Read into dynamic storage - - virtual std::string getLastAddedRecordId() const { return ""; } - ///< Returns the last loaded/read ID or empty string if a loaded record has no ID - virtual bool isLastAddedRecordDeleted() const { return false; } }; template @@ -137,8 +141,6 @@ namespace MWWorld // for heads/hairs in the character creation) std::map mDynamic; - T mLastAddedRecord; - typedef std::map Dynamic; typedef std::map Static; @@ -185,12 +187,9 @@ namespace MWWorld bool erase(const std::string &id); bool erase(const T &item); - void load(ESM::ESMReader &esm); + RecordId load(ESM::ESMReader &esm); void write(ESM::ESMWriter& writer, Loading::Listener& progress) const; - void read(ESM::ESMReader& reader); - - std::string getLastAddedRecordId() const; - bool isLastAddedRecordDeleted() const; + RecordId read(ESM::ESMReader& reader); }; template <> @@ -199,7 +198,6 @@ namespace MWWorld // For multiple ESM/ESP files we need one list per file. typedef std::vector LandTextureList; std::vector mStatic; - ESM::LandTexture mLastAddedRecord; public: Store(); @@ -214,14 +212,11 @@ namespace MWWorld size_t getSize() const; size_t getSize(size_t plugin) const; - void load(ESM::ESMReader &esm, size_t plugin); - void load(ESM::ESMReader &esm); + RecordId load(ESM::ESMReader &esm, size_t plugin); + RecordId load(ESM::ESMReader &esm); iterator begin(size_t plugin) const; iterator end(size_t plugin) const; - - std::string getLastAddedRecordId() const; - bool isLastAddedRecordDeleted() const; }; template <> @@ -243,7 +238,7 @@ namespace MWWorld ESM::Land *search(int x, int y) const; ESM::Land *find(int x, int y) const; - void load(ESM::ESMReader &esm); + RecordId load(ESM::ESMReader &esm); void setUp(); }; @@ -293,7 +288,7 @@ namespace MWWorld void setUp(); - void load(ESM::ESMReader &esm); + RecordId load(ESM::ESMReader &esm); iterator intBegin() const; iterator intEnd() const; @@ -335,7 +330,7 @@ namespace MWWorld Store(); void setCells(Store& cells); - void load(ESM::ESMReader &esm); + RecordId load(ESM::ESMReader &esm); size_t getSize() const; void setUp(); diff --git a/components/esm/util.hpp b/components/esm/util.hpp index 94a7956ef..ca6917fd1 100644 --- a/components/esm/util.hpp +++ b/components/esm/util.hpp @@ -60,12 +60,6 @@ struct Vector3 bool readDeleSubRecord(ESMReader &esm); void writeDeleSubRecord(ESMWriter &esm); -template -std::string getRecordId(const RecordT &record) -{ - return record.mId; -} - template bool isRecordDeleted(const RecordT &record) { From 42f9136141657cbe3fd0801c579e37dd1ff47a30 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 12 Jul 2015 15:22:51 +0300 Subject: [PATCH 21/49] Remove DELE and NAME handling from RefIdCollection and RefIdData --- apps/opencs/model/world/refidcollection.cpp | 56 +----------- apps/opencs/model/world/refiddata.cpp | 12 +-- apps/opencs/model/world/refiddata.hpp | 96 +++++++++++++++++---- 3 files changed, 87 insertions(+), 77 deletions(-) diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 5495926b4..0ca050e18 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -767,61 +767,7 @@ const CSMWorld::RecordBase& CSMWorld::RefIdCollection::getRecord (int index) con void CSMWorld::RefIdCollection::load (ESM::ESMReader& reader, bool base, UniversalId::Type type) { - std::string id = reader.getHNOString ("NAME"); - - int index = searchId (id); - - if (reader.isNextSub ("DELE")) - { - reader.skipRecord(); - - if (index==-1) - { - // deleting a record that does not exist - - // ignore it for now - - /// \todo report the problem to the user - } - else if (base) - { - mData.erase (index, 1); - } - else - { - mData.getRecord (mData.globalToLocalIndex (index)).mState = RecordBase::State_Deleted; - } - } - else - { - if (index==-1) - { - // new record - int index = mData.getAppendIndex (type); - mData.appendRecord (type, id, base); - - RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (index); - - mData.load (localIndex, reader, base); - - mData.getRecord (localIndex).mState = - base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly; - } - else - { - // old record - RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (index); - - if (!base) - if (mData.getRecord (localIndex).mState==RecordBase::State_Erased) - throw std::logic_error ("attempt to access a deleted record"); - - mData.load (localIndex, reader, base); - - if (!base) - mData.getRecord (localIndex).mState = RecordBase::State_Modified; - } - } + mData.load(reader, base, type); } int CSMWorld::RefIdCollection::getAppendIndex (const std::string& id, UniversalId::Type type) const diff --git a/apps/opencs/model/world/refiddata.cpp b/apps/opencs/model/world/refiddata.cpp index 7f5c25f36..68f3fc4ad 100644 --- a/apps/opencs/model/world/refiddata.cpp +++ b/apps/opencs/model/world/refiddata.cpp @@ -161,15 +161,15 @@ int CSMWorld::RefIdData::getAppendIndex (UniversalId::Type type) const return index; } -void CSMWorld::RefIdData::load (const LocalIndex& index, ESM::ESMReader& reader, bool base) +void CSMWorld::RefIdData::load (ESM::ESMReader& reader, bool base, CSMWorld::UniversalId::Type type) { - std::map::iterator iter = - mRecordContainers.find (index.second); + std::map::iterator found = + mRecordContainers.find (type); - if (iter==mRecordContainers.end()) - throw std::logic_error ("invalid local index type"); + if (found == mRecordContainers.end()) + throw std::logic_error ("Invalid type for an Object (Reference ID)"); - iter->second->load (index.first, reader, base); + found->second->load(reader, base); } void CSMWorld::RefIdData::erase (const LocalIndex& index, int count) diff --git a/apps/opencs/model/world/refiddata.hpp b/apps/opencs/model/world/refiddata.hpp index 85d16a6eb..17d913911 100644 --- a/apps/opencs/model/world/refiddata.hpp +++ b/apps/opencs/model/world/refiddata.hpp @@ -49,7 +49,7 @@ namespace CSMWorld virtual void insertRecord (RecordBase& record) = 0; - virtual void load (int index, ESM::ESMReader& reader, bool base) = 0; + virtual void load (ESM::ESMReader& reader, bool base) = 0; virtual void erase (int index, int count) = 0; @@ -73,7 +73,7 @@ namespace CSMWorld virtual void insertRecord (RecordBase& record); - virtual void load (int index, ESM::ESMReader& reader, bool base); + virtual void load (ESM::ESMReader& reader, bool base); virtual void erase (int index, int count); @@ -122,9 +122,67 @@ namespace CSMWorld } template - void RefIdDataContainer::load (int index, ESM::ESMReader& reader, bool base) + void RefIdDataContainer::load (ESM::ESMReader& reader, bool base) { - (base ? mContainer.at (index).mBase : mContainer.at (index).mModified).load (reader); + RecordT record; + record.load(reader); + + typename std::vector >::iterator found = mContainer.begin(); + for (; found != mContainer.end(); ++found) + { + if (found->get().mId == record.mId) + { + break; + } + } + + if (record.mIsDeleted) + { + if (found == mContainer.end()) + { + // deleting a record that does not exist + // ignore it for now + /// \todo report the problem to the user + return; + } + + if (base) + { + mContainer.erase(found); + } + else + { + found->mState = RecordBase::State_Deleted; + } + } + else + { + if (found == mContainer.end()) + { + appendRecord(record.mId, base); + if (base) + { + mContainer.back().mBase = record; + } + else + { + mContainer.back().mModified = record; + } + } + else + { + if (!base) + { + if (found->mState == RecordBase::State_Erased) + { + throw std::logic_error("Attempt to access a deleted record"); + } + + found->mState = RecordBase::State_Modified; + found->mModified = record; + } + } + } } template @@ -145,20 +203,26 @@ namespace CSMWorld template void RefIdDataContainer::save (int index, ESM::ESMWriter& writer) const { - CSMWorld::RecordBase::State state = mContainer.at (index).mState; + Record record = mContainer.at(index); + RecordT esmRecord; - if (state==CSMWorld::RecordBase::State_Modified || - state==CSMWorld::RecordBase::State_ModifiedOnly) + switch (record.mState) { - writer.startRecord (mContainer.at (index).mModified.sRecordId); - writer.writeHNCString ("NAME", getId (index)); - mContainer.at (index).mModified.save (writer); - writer.endRecord (mContainer.at (index).mModified.sRecordId); - } - else if (state==CSMWorld::RecordBase::State_Deleted) - { - /// \todo write record with delete flag + case RecordBase::State_Modified: + case RecordBase::State_ModifiedOnly: + esmRecord = record.mModified; + break; + case RecordBase::State_Deleted: + esmRecord = record.mBase; + esmRecord.mIsDeleted = true; + break; + default: + break; } + + writer.startRecord(esmRecord.sRecordId); + esmRecord.save(writer); + writer.endRecord(esmRecord.sRecordId); } @@ -220,7 +284,7 @@ namespace CSMWorld int getAppendIndex (UniversalId::Type type) const; - void load (const LocalIndex& index, ESM::ESMReader& reader, bool base); + void load (ESM::ESMReader& reader, bool base, UniversalId::Type type); int getSize() const; From 74a055f3ccbe25e50d2947d6fe639a84e3138ec7 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Mon, 13 Jul 2015 10:40:11 +0300 Subject: [PATCH 22/49] Remove NAME and DELE handling from IdCollection --- apps/opencs/model/world/cell.cpp | 5 +- apps/opencs/model/world/data.cpp | 32 +++++------ apps/opencs/model/world/idcollection.hpp | 69 ++++++++---------------- apps/opencs/model/world/land.hpp | 10 ++++ apps/opencs/model/world/pathgrid.hpp | 10 ++++ components/esm/util.cpp | 36 +++++++++++++ components/esm/util.hpp | 24 +++++++++ 7 files changed, 119 insertions(+), 67 deletions(-) diff --git a/apps/opencs/model/world/cell.cpp b/apps/opencs/model/world/cell.cpp index 40520a9ba..8816cd35e 100644 --- a/apps/opencs/model/world/cell.cpp +++ b/apps/opencs/model/world/cell.cpp @@ -5,16 +5,13 @@ void CSMWorld::Cell::load (ESM::ESMReader &esm) { - mName = mId; - ESM::Cell::load (esm, false); + mId = mName; if (!(mData.mFlags & Interior)) { std::ostringstream stream; - stream << "#" << mData.mX << " " << mData.mY; - mId = stream.str(); } } diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index a92a7ad79..348656a7c 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -988,41 +988,41 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Messages& messages) case ESM::REC_DIAL: { - std::string id = mReader->getHNOString ("NAME"); - ESM::Dialogue record; - record.mId = id; record.load (*mReader); - if (record.mType==ESM::Dialogue::Journal) - { - mJournals.load (record, mBase); - mDialogue = &mJournals.getRecord (id).get(); - } - else if (record.mType==ESM::Dialogue::Deleted) + if (record.mIsDeleted) { - mDialogue = 0; // record vector can be shuffled around which would make pointer - // to record invalid + // record vector can be shuffled around which would make pointer to record invalid + mDialogue = 0; - if (mJournals.tryDelete (id)) + if (mJournals.tryDelete (record.mId)) { /// \todo handle info records } - else if (mTopics.tryDelete (id)) + else if (mTopics.tryDelete (record.mId)) { /// \todo handle info records } else { messages.add (UniversalId::Type_None, - "Trying to delete dialogue record " + id + " which does not exist", + "Trying to delete dialogue record " + record.mId + " which does not exist", "", CSMDoc::Message::Severity_Warning); } } else { - mTopics.load (record, mBase); - mDialogue = &mTopics.getRecord (id).get(); + if (record.mType == ESM::Dialogue::Journal) + { + mJournals.load (record, mBase); + mDialogue = &mJournals.getRecord (record.mId).get(); + } + else + { + mTopics.load (record, mBase); + mDialogue = &mTopics.getRecord (record.mId).get(); + } } break; diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 4eafc59bd..41ce59702 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -2,6 +2,7 @@ #define CSM_WOLRD_IDCOLLECTION_H #include +#include #include "collection.hpp" @@ -41,69 +42,43 @@ namespace CSMWorld template int IdCollection::load (ESM::ESMReader& reader, bool base) { - std::string id = reader.getHNOString ("NAME"); + ESXRecordT record; + loadRecord (record, reader); - if (reader.isNextSub ("DELE")) - { - int index = Collection::searchId (id); - - reader.skipRecord(); + std::string id = IdAccessorT().getId (record); + int index = searchId (id); + if (ESM::isRecordDeleted (record)) + { if (index==-1) { // deleting a record that does not exist - // ignore it for now - /// \todo report the problem to the user + return -1; } - else if (base) + + if (base) { - Collection::removeRows (index, 1); + removeRows (index, 1); } else { - Record record = Collection::getRecord (index); - record.mState = RecordBase::State_Deleted; - this->setRecord (index, record); + Record baseRecord = getRecord (index); + baseRecord.mState = RecordBase::State_Deleted; + this->setRecord (index, baseRecord); } return -1; } - else - { - ESXRecordT record; - - // Sometimes id (i.e. NAME of the cell) may be different to the id we stored - // earlier. e.g. NAME == "Vivec, Arena" but id == "#-4 11". Sometime NAME is - // missing altogether for scripts or cells. - // - // In such cases the returned index will be -1. We then try updating the - // IdAccessor's id manually (e.g. set mId of the record to "Vivec, Arena") - // and try getting the index once more after loading the record. The mId of the - // record would have changed to "#-4 11" after the load, and searchId() should find - // it (if this is a modify) - int index = this->searchId (id); - - if (index==-1) - IdAccessorT().getId (record) = id; - else - { - record = this->getRecord (index).get(); - } - - loadRecord (record, reader); - - if (index==-1) - { - std::string newId = IdAccessorT().getId(record); - int newIndex = this->searchId(newId); - if (newIndex != -1 && id != newId) - index = newIndex; - } - - return load (record, base, index); - } + // + //if (index != -1) + //{ + // ESXRecordT existedRecord = getRecord(index).get(); + // IdAccessorT().getId(record) = IdAccessorT().getId(existedRecord); + //} + + return load (record, base, index); } template diff --git a/apps/opencs/model/world/land.hpp b/apps/opencs/model/world/land.hpp index e97a2d7dd..adf5c0331 100644 --- a/apps/opencs/model/world/land.hpp +++ b/apps/opencs/model/world/land.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace CSMWorld { @@ -26,4 +27,13 @@ namespace CSMWorld }; } +namespace ESM +{ + template <> + bool isRecordDeleted(const CSMWorld::Land &land) + { + return false; + } +} + #endif diff --git a/apps/opencs/model/world/pathgrid.hpp b/apps/opencs/model/world/pathgrid.hpp index 7e7b7c3bb..cd5e472c8 100644 --- a/apps/opencs/model/world/pathgrid.hpp +++ b/apps/opencs/model/world/pathgrid.hpp @@ -5,6 +5,7 @@ #include #include +#include namespace CSMWorld { @@ -26,4 +27,13 @@ namespace CSMWorld }; } +namespace ESM +{ + template <> + bool isRecordDeleted(const CSMWorld::Pathgrid &pgrd) + { + return false; + } +} + #endif diff --git a/components/esm/util.cpp b/components/esm/util.cpp index 4cfe644e8..a5ec377a3 100644 --- a/components/esm/util.cpp +++ b/components/esm/util.cpp @@ -36,4 +36,40 @@ namespace ESM { return false; } + + template <> + bool isRecordDeleted(const Skill &skill) + { + return false; + } + + template <> + bool isRecordDeleted(const MagicEffect &mgef) + { + return false; + } + + template <> + bool isRecordDeleted(const Pathgrid &pgrd) + { + return false; + } + + template <> + bool isRecordDeleted(const Land &land) + { + return false; + } + + template <> + bool isRecordDeleted(const DebugProfile &profile) + { + return false; + } + + template <> + bool isRecordDeleted(const Filter &filter) + { + return false; + } } diff --git a/components/esm/util.hpp b/components/esm/util.hpp index ca6917fd1..531e7eb76 100644 --- a/components/esm/util.hpp +++ b/components/esm/util.hpp @@ -12,6 +12,12 @@ #include "loadglob.hpp" #include "loadrace.hpp" #include "loadgmst.hpp" +#include "loadskil.hpp" +#include "loadmgef.hpp" +#include "loadland.hpp" +#include "loadpgrd.hpp" +#include "debugprofile.hpp" +#include "filter.hpp" namespace ESM { @@ -76,6 +82,24 @@ bool isRecordDeleted(const Race &race); template <> bool isRecordDeleted(const GameSetting &gmst); +template <> +bool isRecordDeleted(const Skill &skill); + +template <> +bool isRecordDeleted(const MagicEffect &mgef); + +template <> +bool isRecordDeleted(const Pathgrid &pgrd); + +template <> +bool isRecordDeleted(const Land &land); + +template <> +bool isRecordDeleted(const DebugProfile &profile); + +template <> +bool isRecordDeleted(const Filter &filter); + } #endif From c8c79dc1efa5682c52ead7221628812638a55fed Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Mon, 13 Jul 2015 10:53:31 +0300 Subject: [PATCH 23/49] Move ID loading into a separate method for Dialogue and DialInfo records --- apps/openmw/mwworld/store.cpp | 8 +++---- components/esm/loaddial.cpp | 39 ++++++++++++++++++++--------------- components/esm/loaddial.hpp | 6 ++++++ components/esm/loadinfo.cpp | 14 ++++++++++++- components/esm/loadinfo.hpp | 6 ++++++ 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index c8c42d17d..8f55bb466 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -1027,19 +1027,19 @@ namespace MWWorld inline RecordId Store::load(ESM::ESMReader &esm) { // The original letter case of a dialogue ID is saved, because it's printed ESM::Dialogue dialogue; - dialogue.load(esm); + dialogue.loadId(esm); std::string idLower = Misc::StringUtils::lowerCase(dialogue.mId); std::map::iterator found = mStatic.find(idLower); if (found == mStatic.end()) { + dialogue.loadData(esm); mStatic.insert(std::make_pair(idLower, dialogue)); } else { - // Update only read fields (don't touching the Info list) - found->second.mIsDeleted = dialogue.mIsDeleted; - found->second.mType = dialogue.mType; + found->second.loadData(esm); + dialogue = found->second; } return RecordId(dialogue.mId, dialogue.mIsDeleted); diff --git a/components/esm/loaddial.cpp b/components/esm/loaddial.cpp index dfac0ce63..fcdb57c8d 100644 --- a/components/esm/loaddial.cpp +++ b/components/esm/loaddial.cpp @@ -19,9 +19,18 @@ namespace ESM void Dialogue::load(ESMReader &esm) { - mIsDeleted = false; + loadId(esm); + loadData(esm); + } + void Dialogue::loadId(ESMReader &esm) + { + mIsDeleted = false; mId = esm.getHNString("NAME"); + } + + void Dialogue::loadData(ESMReader &esm) + { esm.getSubNameIs("DATA"); esm.getSubHeader(); int si = esm.getSubSize(); @@ -60,31 +69,28 @@ namespace ESM void Dialogue::readInfo(ESMReader &esm, bool merge) { - const std::string& id = esm.getHNOString("INAM"); + ESM::DialInfo info; + info.loadId(esm); if (!merge || mInfo.empty()) { - ESM::DialInfo info; - info.mId = id; - info.load(esm); - mLookup[id] = mInfo.insert(mInfo.end(), info); + info.loadInfo(esm); + mLookup[info.mId] = mInfo.insert(mInfo.end(), info); return; } ESM::Dialogue::InfoContainer::iterator it = mInfo.end(); std::map::iterator lookup; + lookup = mLookup.find(info.mId); - lookup = mLookup.find(id); - - ESM::DialInfo info; if (lookup != mLookup.end()) { it = lookup->second; // Merge with existing record. Only the subrecords that are present in // the new record will be overwritten. - it->load(esm); + it->loadInfo(esm); info = *it; // Since the record merging may have changed the next/prev linked list connection, we need to re-insert the record @@ -93,18 +99,17 @@ namespace ESM } else { - info.mId = id; - info.load(esm); + info.loadInfo(esm); } if (info.mNext.empty()) { - mLookup[id] = mInfo.insert(mInfo.end(), info); + mLookup[info.mId] = mInfo.insert(mInfo.end(), info); return; } if (info.mPrev.empty()) { - mLookup[id] = mInfo.insert(mInfo.begin(), info); + mLookup[info.mId] = mInfo.insert(mInfo.begin(), info); return; } @@ -113,7 +118,7 @@ namespace ESM { it = lookup->second; - mLookup[id] = mInfo.insert(++it, info); + mLookup[info.mId] = mInfo.insert(++it, info); return; } @@ -122,11 +127,11 @@ namespace ESM { it = lookup->second; - mLookup[id] = mInfo.insert(it, info); + mLookup[info.mId] = mInfo.insert(it, info); return; } - std::cerr << "Failed to insert info " << id << std::endl; + std::cerr << "Failed to insert info " << info.mId << std::endl; } void Dialogue::clearDeletedInfos() diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index e80a7b0b2..73bf16974 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -51,6 +51,12 @@ struct Dialogue Dialogue(); void load(ESMReader &esm); + ///< Loads all sub-records of Dialogue record + void loadId(ESMReader &esm); + ///< Loads NAME sub-record of Dialogue record + void loadData(ESMReader &esm); + ///< Loads all sub-records of Dialogue record, except NAME sub-record + void save(ESMWriter &esm) const; /// Remove all INFOs that are deleted or marked as QS_Deleted from mInfos. diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index c1b12e24c..8f5f0f28b 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -14,10 +14,21 @@ namespace ESM {} void DialInfo::load(ESMReader &esm) + { + loadId(esm); + loadInfo(esm); + } + + void DialInfo::loadId(ESMReader &esm) + { + mIsDeleted = false; + mId = esm.getHNString("INAM"); + } + + void DialInfo::loadInfo(ESMReader &esm) { mQuestStatus = QS_None; mFactionLess = false; - mIsDeleted = false; mPrev = esm.getHNString("PNAM"); mNext = esm.getHNString("NNAM"); @@ -141,6 +152,7 @@ namespace ESM void DialInfo::save(ESMWriter &esm) const { + esm.writeHNCString("INAM", mId); esm.writeHNCString("PNAM", mPrev); esm.writeHNCString("NNAM", mNext); diff --git a/components/esm/loadinfo.hpp b/components/esm/loadinfo.hpp index fbb7e36a5..c243cd50e 100644 --- a/components/esm/loadinfo.hpp +++ b/components/esm/loadinfo.hpp @@ -111,6 +111,12 @@ struct DialInfo DialInfo(); void load(ESMReader &esm); + ///< Loads all sub-records of Info record + void loadId(ESMReader &esm); + ///< Loads only Id of Info record (INAM sub-record) + void loadInfo(ESMReader &esm); + ///< Loads all sub-records of Info record, except INAM sub-record + void save(ESMWriter &esm) const; void blank(); From 71e5fc7f0458f77e94879399a39e36393ed19409 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Mon, 13 Jul 2015 11:19:14 +0300 Subject: [PATCH 24/49] Remove INAM handling from InfoCollection --- apps/opencs/model/world/infocollection.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/apps/opencs/model/world/infocollection.cpp b/apps/opencs/model/world/infocollection.cpp index 560be8131..1b95c1505 100644 --- a/apps/opencs/model/world/infocollection.cpp +++ b/apps/opencs/model/world/infocollection.cpp @@ -107,21 +107,18 @@ bool CSMWorld::InfoCollection::reorderRows (int baseIndex, const std::vector Date: Mon, 13 Jul 2015 22:37:14 +0300 Subject: [PATCH 25/49] Add NAME handling to DebugProfile and Filter records --- components/esm/debugprofile.cpp | 2 ++ components/esm/filter.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/components/esm/debugprofile.cpp b/components/esm/debugprofile.cpp index 6c05fac2a..9c8164d29 100644 --- a/components/esm/debugprofile.cpp +++ b/components/esm/debugprofile.cpp @@ -9,6 +9,7 @@ unsigned int ESM::DebugProfile::sRecordId = REC_DBGP; void ESM::DebugProfile::load (ESMReader& esm) { + mId = esm.getHNString ("NAME"); mDescription = esm.getHNString ("DESC"); mScriptText = esm.getHNString ("SCRP"); esm.getHNT (mFlags, "FLAG"); @@ -16,6 +17,7 @@ void ESM::DebugProfile::load (ESMReader& esm) void ESM::DebugProfile::save (ESMWriter& esm) const { + esm.writeHNCString ("NAME", mId); esm.writeHNCString ("DESC", mDescription); esm.writeHNCString ("SCRP", mScriptText); esm.writeHNT ("FLAG", mFlags); diff --git a/components/esm/filter.cpp b/components/esm/filter.cpp index a80427bbe..ee2c67869 100644 --- a/components/esm/filter.cpp +++ b/components/esm/filter.cpp @@ -9,12 +9,14 @@ unsigned int ESM::Filter::sRecordId = REC_FILT; void ESM::Filter::load (ESMReader& esm) { + mId = esm.getHNString ("NAME"); mFilter = esm.getHNString ("FILT"); mDescription = esm.getHNString ("DESC"); } void ESM::Filter::save (ESMWriter& esm) const { + esm.writeHNCString ("NAME", mId); esm.writeHNCString ("FILT", mFilter); esm.writeHNCString ("DESC", mDescription); } From 5e623a2a1d06d5679f214cad95123a1d3bd88b34 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 14 Jul 2015 16:18:33 +0300 Subject: [PATCH 26/49] Rework RefIdData code. Update the index map when a new record is loaded --- apps/opencs/model/world/refiddata.cpp | 30 +++++++++-- apps/opencs/model/world/refiddata.hpp | 73 +++++++++++---------------- 2 files changed, 55 insertions(+), 48 deletions(-) diff --git a/apps/opencs/model/world/refiddata.cpp b/apps/opencs/model/world/refiddata.cpp index 68f3fc4ad..e7b36015e 100644 --- a/apps/opencs/model/world/refiddata.cpp +++ b/apps/opencs/model/world/refiddata.cpp @@ -3,10 +3,20 @@ #include -#include - CSMWorld::RefIdDataContainerBase::~RefIdDataContainerBase() {} + +std::string CSMWorld::RefIdData::getRecordId(const CSMWorld::RefIdData::LocalIndex &index) const +{ + std::map::const_iterator found = + mRecordContainers.find (index.second); + + if (found == mRecordContainers.end()) + throw std::logic_error ("invalid local index type"); + + return found->second->getId(index.first); +} + CSMWorld::RefIdData::RefIdData() { mRecordContainers.insert (std::make_pair (UniversalId::Type_Activator, &mActivators)); @@ -167,9 +177,21 @@ void CSMWorld::RefIdData::load (ESM::ESMReader& reader, bool base, CSMWorld::Uni mRecordContainers.find (type); if (found == mRecordContainers.end()) - throw std::logic_error ("Invalid type for an Object (Reference ID)"); + throw std::logic_error ("Invalid Referenceable ID type"); - found->second->load(reader, base); + int index = found->second->load(reader, base); + if (index != -1) + { + LocalIndex localIndex = LocalIndex(index, type); + if (base && getRecord(localIndex).mState == RecordBase::State_Deleted) + { + erase(localIndex, 1); + } + else + { + mIndex[Misc::StringUtils::lowerCase(getRecordId(localIndex))] = localIndex; + } + } } void CSMWorld::RefIdData::erase (const LocalIndex& index, int count) diff --git a/apps/opencs/model/world/refiddata.hpp b/apps/opencs/model/world/refiddata.hpp index 17d913911..195244ba8 100644 --- a/apps/opencs/model/world/refiddata.hpp +++ b/apps/opencs/model/world/refiddata.hpp @@ -25,6 +25,8 @@ #include #include +#include + #include "record.hpp" #include "universalid.hpp" @@ -49,7 +51,8 @@ namespace CSMWorld virtual void insertRecord (RecordBase& record) = 0; - virtual void load (ESM::ESMReader& reader, bool base) = 0; + virtual int load (ESM::ESMReader& reader, bool base) = 0; + ///< \return index of a loaded record or -1 if no record was loaded virtual void erase (int index, int count) = 0; @@ -73,7 +76,8 @@ namespace CSMWorld virtual void insertRecord (RecordBase& record); - virtual void load (ESM::ESMReader& reader, bool base); + virtual int load (ESM::ESMReader& reader, bool base); + ///< \return index of a loaded record or -1 if no record was loaded virtual void erase (int index, int count); @@ -122,15 +126,16 @@ namespace CSMWorld } template - void RefIdDataContainer::load (ESM::ESMReader& reader, bool base) + int RefIdDataContainer::load (ESM::ESMReader& reader, bool base) { RecordT record; record.load(reader); - typename std::vector >::iterator found = mContainer.begin(); - for (; found != mContainer.end(); ++found) + int index = 0; + int numRecords = static_cast(mContainer.size()); + for (; index < numRecords; ++index) { - if (found->get().mId == record.mId) + if (Misc::StringUtils::ciEqual(mContainer[index].get().mId, record.mId)) { break; } @@ -138,26 +143,21 @@ namespace CSMWorld if (record.mIsDeleted) { - if (found == mContainer.end()) + if (index == numRecords) { // deleting a record that does not exist // ignore it for now /// \todo report the problem to the user - return; + return -1; } - if (base) - { - mContainer.erase(found); - } - else - { - found->mState = RecordBase::State_Deleted; - } + // Flag the record as Deleted even for a base content file. + // RefIdData is responsible for its erasure. + mContainer[index].mState = RecordBase::State_Deleted; } else { - if (found == mContainer.end()) + if (index == numRecords) { appendRecord(record.mId, base); if (base) @@ -169,20 +169,13 @@ namespace CSMWorld mContainer.back().mModified = record; } } - else + else if (!base) { - if (!base) - { - if (found->mState == RecordBase::State_Erased) - { - throw std::logic_error("Attempt to access a deleted record"); - } - - found->mState = RecordBase::State_Modified; - found->mModified = record; - } + mContainer[index].setModified(record); } } + + return index; } template @@ -204,25 +197,15 @@ namespace CSMWorld void RefIdDataContainer::save (int index, ESM::ESMWriter& writer) const { Record record = mContainer.at(index); - RecordT esmRecord; + RecordT esmRecord = record.get(); - switch (record.mState) + if (record.isModified() || record.mState == RecordBase::State_Deleted) { - case RecordBase::State_Modified: - case RecordBase::State_ModifiedOnly: - esmRecord = record.mModified; - break; - case RecordBase::State_Deleted: - esmRecord = record.mBase; - esmRecord.mIsDeleted = true; - break; - default: - break; + esmRecord.mIsDeleted = (record.mState == RecordBase::State_Deleted); + writer.startRecord(esmRecord.sRecordId); + esmRecord.save(writer); + writer.endRecord(esmRecord.sRecordId); } - - writer.startRecord(esmRecord.sRecordId); - esmRecord.save(writer); - writer.endRecord(esmRecord.sRecordId); } @@ -262,6 +245,8 @@ namespace CSMWorld void erase (const LocalIndex& index, int count); ///< Must not spill over into another type. + std::string getRecordId(const LocalIndex &index) const; + public: RefIdData(); From a1389b87bacd08f54c4c146c7a0b6d1ed51edc54 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 14 Jul 2015 23:31:16 +0300 Subject: [PATCH 27/49] Return a correct index for a loaded record that was deleted --- apps/opencs/model/world/idcollection.hpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 41ce59702..d08abce5b 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -61,22 +61,14 @@ namespace CSMWorld if (base) { removeRows (index, 1); - } - else - { - Record baseRecord = getRecord (index); - baseRecord.mState = RecordBase::State_Deleted; - this->setRecord (index, baseRecord); + return -1; } - return -1; + Record baseRecord = getRecord (index); + baseRecord.mState = RecordBase::State_Deleted; + setRecord (index, baseRecord); + return index; } - // - //if (index != -1) - //{ - // ESXRecordT existedRecord = getRecord(index).get(); - // IdAccessorT().getId(record) = IdAccessorT().getId(existedRecord); - //} return load (record, base, index); } From e8a9567be30fb35e78e252bf52e95bcebe76a109 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Wed, 15 Jul 2015 19:39:01 +0300 Subject: [PATCH 28/49] Move DELE handling to CellRef record --- apps/openmw/mwworld/cellreflist.hpp | 2 +- apps/openmw/mwworld/cellstore.cpp | 58 ++++++++++++++--------------- apps/openmw/mwworld/cellstore.hpp | 2 +- components/esm/cellref.cpp | 21 +++++++++++ components/esm/cellref.hpp | 4 ++ components/esm/loadcell.cpp | 12 ++---- components/esm/loadcell.hpp | 3 +- 7 files changed, 59 insertions(+), 43 deletions(-) diff --git a/apps/openmw/mwworld/cellreflist.hpp b/apps/openmw/mwworld/cellreflist.hpp index 49197d167..0ce603224 100644 --- a/apps/openmw/mwworld/cellreflist.hpp +++ b/apps/openmw/mwworld/cellreflist.hpp @@ -22,7 +22,7 @@ namespace MWWorld /// and the build will fail with an ugly three-way cyclic header dependence /// so we need to pass the instantiation of the method to the linker, when /// all methods are known. - void load (ESM::CellRef &ref, bool deleted, const MWWorld::ESMStore &esmStore); + void load (ESM::CellRef &ref, const MWWorld::ESMStore &esmStore); LiveRef *find (const std::string& name) { diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index b33a6f8db..a51672581 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -147,7 +147,7 @@ namespace MWWorld { template - void CellRefList::load(ESM::CellRef &ref, bool deleted, const MWWorld::ESMStore &esmStore) + void CellRefList::load(ESM::CellRef &ref, const MWWorld::ESMStore &esmStore) { const MWWorld::Store &store = esmStore.get(); @@ -158,7 +158,7 @@ namespace MWWorld LiveRef liveCellRef (ref, ptr); - if (deleted) + if (ref.mIsDeleted) liveCellRef.mData.setDeleted(true); if (iter != mList.end()) @@ -374,10 +374,9 @@ namespace MWWorld ESM::CellRef ref; // Get each reference in turn - bool deleted = false; - while (mCell->getNextRef (esm[index], ref, deleted)) + while (mCell->getNextRef (esm[index], ref)) { - if (deleted) + if (ref.mIsDeleted) continue; // Don't list reference if it was moved to a different cell. @@ -420,8 +419,7 @@ namespace MWWorld ref.mRefNum.mContentFile = ESM::RefNum::RefNum_NoContentFile; // Get each reference in turn - bool deleted = false; - while(mCell->getNextRef(esm[index], ref, deleted)) + while(mCell->getNextRef(esm[index], ref)) { // Don't load reference if it was moved to a different cell. ESM::MovedCellRefTracker::const_iterator iter = @@ -430,7 +428,7 @@ namespace MWWorld continue; } - loadRef (ref, deleted, store); + loadRef (ref, store); } } @@ -439,7 +437,7 @@ namespace MWWorld { ESM::CellRef &ref = const_cast(*it); - loadRef (ref, false, store); + loadRef (ref, store); } } @@ -468,32 +466,32 @@ namespace MWWorld return Ptr(); } - void CellStore::loadRef (ESM::CellRef& ref, bool deleted, const ESMStore& store) + void CellStore::loadRef (ESM::CellRef& ref, const ESMStore& store) { Misc::StringUtils::toLower (ref.mRefID); switch (store.find (ref.mRefID)) { - case ESM::REC_ACTI: mActivators.load(ref, deleted, store); break; - case ESM::REC_ALCH: mPotions.load(ref, deleted, store); break; - case ESM::REC_APPA: mAppas.load(ref, deleted, store); break; - case ESM::REC_ARMO: mArmors.load(ref, deleted, store); break; - case ESM::REC_BOOK: mBooks.load(ref, deleted, store); break; - case ESM::REC_CLOT: mClothes.load(ref, deleted, store); break; - case ESM::REC_CONT: mContainers.load(ref, deleted, store); break; - case ESM::REC_CREA: mCreatures.load(ref, deleted, store); break; - case ESM::REC_DOOR: mDoors.load(ref, deleted, store); break; - case ESM::REC_INGR: mIngreds.load(ref, deleted, store); break; - case ESM::REC_LEVC: mCreatureLists.load(ref, deleted, store); break; - case ESM::REC_LEVI: mItemLists.load(ref, deleted, store); break; - case ESM::REC_LIGH: mLights.load(ref, deleted, store); break; - case ESM::REC_LOCK: mLockpicks.load(ref, deleted, store); break; - case ESM::REC_MISC: mMiscItems.load(ref, deleted, store); break; - case ESM::REC_NPC_: mNpcs.load(ref, deleted, store); break; - case ESM::REC_PROB: mProbes.load(ref, deleted, store); break; - case ESM::REC_REPA: mRepairs.load(ref, deleted, store); break; - case ESM::REC_STAT: mStatics.load(ref, deleted, store); break; - case ESM::REC_WEAP: mWeapons.load(ref, deleted, store); break; + case ESM::REC_ACTI: mActivators.load(ref, store); break; + case ESM::REC_ALCH: mPotions.load(ref,store); break; + case ESM::REC_APPA: mAppas.load(ref, store); break; + case ESM::REC_ARMO: mArmors.load(ref, store); break; + case ESM::REC_BOOK: mBooks.load(ref, store); break; + case ESM::REC_CLOT: mClothes.load(ref, store); break; + case ESM::REC_CONT: mContainers.load(ref, store); break; + case ESM::REC_CREA: mCreatures.load(ref, store); break; + case ESM::REC_DOOR: mDoors.load(ref, store); break; + case ESM::REC_INGR: mIngreds.load(ref, store); break; + case ESM::REC_LEVC: mCreatureLists.load(ref, store); break; + case ESM::REC_LEVI: mItemLists.load(ref, store); break; + case ESM::REC_LIGH: mLights.load(ref, store); break; + case ESM::REC_LOCK: mLockpicks.load(ref, store); break; + case ESM::REC_MISC: mMiscItems.load(ref, store); break; + case ESM::REC_NPC_: mNpcs.load(ref, store); break; + case ESM::REC_PROB: mProbes.load(ref, store); break; + case ESM::REC_REPA: mRepairs.load(ref, store); break; + case ESM::REC_STAT: mStatics.load(ref, store); break; + case ESM::REC_WEAP: mWeapons.load(ref, store); break; case 0: std::cerr << "Cell reference " + ref.mRefID + " not found!\n"; break; diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index f879343d9..5caa4eeea 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -214,7 +214,7 @@ namespace MWWorld void loadRefs(const MWWorld::ESMStore &store, std::vector &esm); - void loadRef (ESM::CellRef& ref, bool deleted, const ESMStore& store); + void loadRef (ESM::CellRef& ref, const ESMStore& store); ///< Make case-adjustments to \a ref and insert it into the respective container. /// /// Invalid \a ref objects are silently dropped. diff --git a/components/esm/cellref.cpp b/components/esm/cellref.cpp index c3b889df5..e43a37b66 100644 --- a/components/esm/cellref.cpp +++ b/components/esm/cellref.cpp @@ -3,6 +3,17 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include "util.hpp" + +ESM::CellRef::CellRef() + : mScale(1.0f), + mFactionRank(-2), + mEnchantmentCharge(-1), + mGoldValue(1), + mChargeInt(-1), + mLockLevel(0), + mIsDeleted(false) +{} void ESM::RefNum::load (ESMReader& esm, bool wide) { @@ -27,6 +38,7 @@ void ESM::RefNum::save (ESMWriter &esm, bool wide, const std::string& tag) const void ESM::CellRef::load (ESMReader& esm, bool wideRefNum) { + mIsDeleted = false; loadId(esm, wideRefNum); loadData(esm); } @@ -97,6 +109,8 @@ void ESM::CellRef::loadData(ESMReader &esm) if (esm.isNextSub("NAM0")) esm.skipHSub(); + + mIsDeleted = readDeleSubRecord (esm); } void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory) const @@ -149,6 +163,11 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory) cons if (!inInventory) esm.writeHNT("DATA", mPos, 24); + + if (mIsDeleted) + { + writeDeleSubRecord(esm); + } } void ESM::CellRef::blank() @@ -178,6 +197,8 @@ void ESM::CellRef::blank() mPos.pos[i] = 0; mPos.rot[i] = 0; } + + mIsDeleted = false; } bool ESM::operator== (const RefNum& left, const RefNum& right) diff --git a/components/esm/cellref.hpp b/components/esm/cellref.hpp index e9959611b..553dbaae3 100644 --- a/components/esm/cellref.hpp +++ b/components/esm/cellref.hpp @@ -99,6 +99,10 @@ namespace ESM // Position and rotation of this object within the cell Position mPos; + bool mIsDeleted; + + CellRef(); + /// Calls loadId and loadData void load (ESMReader& esm, bool wideRefNum = false); diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 86b4e4edb..67701a5b7 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -177,7 +177,7 @@ std::string Cell::getDescription() const } } -bool Cell::getNextRef(ESMReader &esm, CellRef &ref, bool& deleted, bool ignoreMoves, MovedCellRef *mref) +bool Cell::getNextRef(ESMReader &esm, CellRef &ref, bool ignoreMoves, MovedCellRef *mref) { // TODO: Try and document reference numbering, I don't think this has been done anywhere else. if (!esm.hasMoreSubs()) @@ -206,14 +206,6 @@ bool Cell::getNextRef(ESMReader &esm, CellRef &ref, bool& deleted, bool ignoreMo // Identify references belonging to a parent file and adapt the ID accordingly. adjustRefNum (ref.mRefNum, esm); - if (esm.isNextSub("DELE")) - { - esm.skipHSub(); - deleted = true; - } - else - deleted = false; - return true; } @@ -244,6 +236,8 @@ bool Cell::getNextMVRF(ESMReader &esm, MovedCellRef &mref) mAmbi.mSunlight = 0; mAmbi.mFog = 0; mAmbi.mFogDensity = 0; + + mIsDeleted = false; } CellId Cell::getCellId() const diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index bf65c5fa8..a1a758e3b 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -163,8 +163,7 @@ struct Cell reuse one memory location without blanking it between calls. */ /// \param ignoreMoves ignore MVRF record and read reference like a regular CellRef. - static bool getNextRef(ESMReader &esm, - CellRef &ref, bool& deleted, bool ignoreMoves = false, MovedCellRef *mref = 0); + static bool getNextRef(ESMReader &esm, CellRef &ref, bool ignoreMoves = false, MovedCellRef *mref = 0); /* This fetches an MVRF record, which is used to track moved references. * Since they are comparably rare, we use a separate method for this. From 3ba73f5fd9feb9727b56f32767c848e520d9a94c Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Wed, 15 Jul 2015 20:53:08 +0300 Subject: [PATCH 29/49] Handle deleted records in RefCollection --- apps/opencs/model/world/refcollection.cpp | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp index ff30dafae..d32f21d0a 100644 --- a/apps/opencs/model/world/refcollection.cpp +++ b/apps/opencs/model/world/refcollection.cpp @@ -20,12 +20,10 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool Cell& cell2 = base ? cell.mBase : cell.mModified; CellRef ref; - - bool deleted = false; ESM::MovedCellRef mref; // hack to initialise mindex - while (!(mref.mRefNum.mIndex = 0) && ESM::Cell::getNextRef(reader, ref, deleted, true, &mref)) + while (!(mref.mRefNum.mIndex = 0) && ESM::Cell::getNextRef(reader, ref, true, &mref)) { // Keep mOriginalCell empty when in modified (as an indicator that the // original cell will always be equal the current cell). @@ -50,17 +48,6 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool // https://forum.openmw.org/viewtopic.php?f=6&t=577&start=30 ref.mOriginalCell = cell2.mId; - if (deleted) - { - // FIXME: how to mark the record deleted? - CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Cell, - mCells.getId (cellIndex)); - - messages.add (id, "Moved reference "+ref.mRefID+" is in DELE state"); - - continue; - } - // It is not always possibe to ignore moved references sub-record and // calculate from coordinates. Some mods may place the ref in positions // outside normal bounds, resulting in non sensical cell id's. This often @@ -92,7 +79,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool break; } - if (deleted) + if (ref.mIsDeleted) { if (iter==cache.end()) { @@ -100,7 +87,6 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool mCells.getId (cellIndex)); messages.add (id, "Attempt to delete a non-existing reference"); - continue; } @@ -108,7 +94,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool Record record = getRecord (index); - if (record.mState==RecordBase::State_BaseOnly) + if (base) { removeRows (index, 1); cache.erase (iter); From ad353e6dd0b41e388e2ec3fbcc4bf15d1ef71e57 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Thu, 16 Jul 2015 19:52:31 +0300 Subject: [PATCH 30/49] Refine DELE handling in ESM records. Add position-independent DELE search --- components/esm/cellref.cpp | 126 +++++++++++++--------- components/esm/esmreader.cpp | 5 + components/esm/esmreader.hpp | 3 + components/esm/loadacti.cpp | 23 ++-- components/esm/loadalch.cpp | 28 +++-- components/esm/loadappa.cpp | 27 +++-- components/esm/loadarmo.cpp | 26 +++-- components/esm/loadbody.cpp | 24 +++-- components/esm/loadbook.cpp | 25 +++-- components/esm/loadbsgn.cpp | 20 +++- components/esm/loadclas.cpp | 25 +++-- components/esm/loadclot.cpp | 26 +++-- components/esm/loadcont.cpp | 32 ++++-- components/esm/loadcrea.cpp | 33 ++++-- components/esm/loaddial.cpp | 46 +++++--- components/esm/loaddoor.cpp | 23 ++-- components/esm/loadench.cpp | 25 +++-- components/esm/loadfact.cpp | 28 +++-- components/esm/loadglob.cpp | 29 +++-- components/esm/loadinfo.cpp | 189 +++++++++++++-------------------- components/esm/loadinfo.hpp | 3 +- components/esm/loadingr.cpp | 24 +++-- components/esm/loadlevlist.cpp | 85 +++++++++------ components/esm/loadligh.cpp | 25 +++-- components/esm/loadlock.cpp | 26 +++-- components/esm/loadltex.cpp | 43 ++++++-- components/esm/loadmisc.cpp | 27 +++-- components/esm/loadnpc.cpp | 34 +++--- components/esm/loadprob.cpp | 27 +++-- components/esm/loadregn.cpp | 101 ++++++++++++------ components/esm/loadrepa.cpp | 27 +++-- components/esm/loadscpt.cpp | 29 +++-- components/esm/loadsndg.cpp | 38 ++++--- components/esm/loadsoun.cpp | 27 +++-- components/esm/loadspel.cpp | 30 ++++-- components/esm/loadstat.cpp | 39 +++++-- components/esm/loadweap.cpp | 24 +++-- 37 files changed, 857 insertions(+), 515 deletions(-) diff --git a/components/esm/cellref.cpp b/components/esm/cellref.cpp index e43a37b66..c6fb899b3 100644 --- a/components/esm/cellref.cpp +++ b/components/esm/cellref.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" -#include "util.hpp" ESM::CellRef::CellRef() : mScale(1.0f), @@ -38,7 +37,6 @@ void ESM::RefNum::save (ESMWriter &esm, bool wide, const std::string& tag) const void ESM::CellRef::load (ESMReader& esm, bool wideRefNum) { - mIsDeleted = false; loadId(esm, wideRefNum); loadData(esm); } @@ -55,62 +53,90 @@ void ESM::CellRef::loadId (ESMReader& esm, bool wideRefNum) mRefNum.load (esm, wideRefNum); mRefID = esm.getHNString ("NAME"); + mIsDeleted = false; } void ESM::CellRef::loadData(ESMReader &esm) { - // Again, UNAM sometimes appears after NAME and sometimes later. - // Or perhaps this UNAM means something different? - mReferenceBlocked = -1; - esm.getHNOT (mReferenceBlocked, "UNAM"); - - mScale = 1.0; - esm.getHNOT (mScale, "XSCL"); - - mOwner = esm.getHNOString ("ANAM"); - mGlobalVariable = esm.getHNOString ("BNAM"); - mSoul = esm.getHNOString ("XSOL"); - - mFaction = esm.getHNOString ("CNAM"); + mScale = 1.0f; mFactionRank = -2; - esm.getHNOT (mFactionRank, "INDX"); - - mGoldValue = 1; mChargeInt = -1; mEnchantmentCharge = -1; + mGoldValue = 1; + mLockLevel = 0; + mReferenceBlocked = -1; + mTeleport = false; + mIsDeleted = false; - esm.getHNOT (mEnchantmentCharge, "XCHG"); - - esm.getHNOT (mChargeInt, "INTV"); - - esm.getHNOT (mGoldValue, "NAM9"); - - // Present for doors that teleport you to another cell. - if (esm.isNextSub ("DODT")) + bool isLoaded = false; + while (!isLoaded && esm.hasMoreSubs()) { - mTeleport = true; - esm.getHT (mDoorDest); - mDestCell = esm.getHNOString ("DNAM"); + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'U','N','A','M'>::value: + esm.getHT(mReferenceBlocked); + break; + case ESM::FourCC<'X','S','C','L'>::value: + esm.getHT(mScale); + break; + case ESM::FourCC<'A','N','A','M'>::value: + mOwner = esm.getHString(); + break; + case ESM::FourCC<'B','N','A','M'>::value: + mGlobalVariable = esm.getHString(); + break; + case ESM::FourCC<'X','S','O','L'>::value: + mSoul = esm.getHString(); + break; + case ESM::FourCC<'C','N','A','M'>::value: + mFaction = esm.getHString(); + break; + case ESM::FourCC<'I','N','D','X'>::value: + esm.getHT(mFactionRank); + break; + case ESM::FourCC<'X','C','H','G'>::value: + esm.getHT(mEnchantmentCharge); + break; + case ESM::FourCC<'I','N','T','V'>::value: + esm.getHT(mChargeInt); + break; + case ESM::FourCC<'N','A','M','9'>::value: + esm.getHT(mGoldValue); + break; + case ESM::FourCC<'D','O','D','T'>::value: + esm.getHT(mDoorDest); + mTeleport = true; + break; + case ESM::FourCC<'D','N','A','M'>::value: + mDestCell = esm.getHString(); + break; + case ESM::FourCC<'F','L','T','V'>::value: + esm.getHT(mLockLevel); + break; + case ESM::FourCC<'K','N','A','M'>::value: + mKey = esm.getHString(); + break; + case ESM::FourCC<'T','N','A','M'>::value: + mTrap = esm.getHString(); + break; + case ESM::FourCC<'D','A','T','A'>::value: + esm.getHT(mPos, 24); + break; + case ESM::FourCC<'N','A','M','0'>::value: + esm.skipHSub(); + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; + default: + esm.cacheSubName(); + isLoaded = true; + break; + } } - else - mTeleport = false; - - mLockLevel = 0; //Set to 0 to indicate no lock - esm.getHNOT (mLockLevel, "FLTV"); - - mKey = esm.getHNOString ("KNAM"); - mTrap = esm.getHNOString ("TNAM"); - - esm.getHNOT (mReferenceBlocked, "UNAM"); - if (esm.isNextSub("FLTV")) // no longer used - esm.skipHSub(); - - esm.getHNOT(mPos, "DATA", 24); - - if (esm.isNextSub("NAM0")) - esm.skipHSub(); - - mIsDeleted = readDeleSubRecord (esm); } void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory) const @@ -149,7 +175,7 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory) cons } if (!inInventory && mLockLevel != 0) { - esm.writeHNT("FLTV", mLockLevel); + esm.writeHNT("FLTV", mLockLevel); } if (!inInventory) @@ -166,7 +192,7 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory) cons if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); } } diff --git a/components/esm/esmreader.cpp b/components/esm/esmreader.cpp index 4be334970..1bf176842 100644 --- a/components/esm/esmreader.cpp +++ b/components/esm/esmreader.cpp @@ -187,6 +187,11 @@ bool ESMReader::peekNextSub(const char *name) return mCtx.subName == name; } +void ESMReader::cacheSubName() +{ + mCtx.subCached = true; +} + // Read subrecord name. This gets called a LOT, so I've optimized it // slightly. void ESMReader::getSubName() diff --git a/components/esm/esmreader.hpp b/components/esm/esmreader.hpp index c3e6bbbd3..4772aeb6f 100644 --- a/components/esm/esmreader.hpp +++ b/components/esm/esmreader.hpp @@ -185,6 +185,9 @@ public: bool peekNextSub(const char* name); + // Store the current subrecord name for the next call of getSubName() + void cacheSubName(); + // Read subrecord name. This gets called a LOT, so I've optimized it // slightly. void getSubName(); diff --git a/components/esm/loadacti.cpp b/components/esm/loadacti.cpp index 14a3abe54..c32cea1a6 100644 --- a/components/esm/loadacti.cpp +++ b/components/esm/loadacti.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,18 +14,23 @@ namespace ESM void Activator::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; + bool hasName = false; while (esm.hasMoreSubs()) { esm.getSubName(); uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -38,15 +42,20 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } + + if (!hasName) + esm.fail("Missing NAME subrecord"); } void Activator::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadalch.cpp b/components/esm/loadalch.cpp index 5faeb99e1..c1213583d 100644 --- a/components/esm/loadalch.cpp +++ b/components/esm/loadalch.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -16,13 +15,9 @@ namespace ESM void Potion::load(ESMReader &esm) { mEffects.mList.clear(); + mIsDeleted = false; - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } - + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -30,6 +25,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -51,17 +54,22 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) - esm.fail("Missing ALDT"); + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) + esm.fail("Missing ALDT subrecord"); } void Potion::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadappa.cpp b/components/esm/loadappa.cpp index ea375aa7f..edf1f473b 100644 --- a/components/esm/loadappa.cpp +++ b/components/esm/loadappa.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,12 +14,9 @@ namespace ESM void Apparatus::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -28,6 +24,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -46,18 +50,23 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) - esm.fail("Missing AADT"); + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) + esm.fail("Missing AADT subrecord"); } void Apparatus::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadarmo.cpp b/components/esm/loadarmo.cpp index d23a71cac..d5b9fdd44 100644 --- a/components/esm/loadarmo.cpp +++ b/components/esm/loadarmo.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -46,13 +45,9 @@ namespace ESM void Armor::load(ESMReader &esm) { mParts.mParts.clear(); + mIsDeleted = false; - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } - + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -60,6 +55,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -84,18 +87,23 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing CTDT subrecord"); } void Armor::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadbody.cpp b/components/esm/loadbody.cpp index e0ebfd539..e2c6ad7b2 100644 --- a/components/esm/loadbody.cpp +++ b/components/esm/loadbody.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,12 +14,9 @@ namespace ESM void BodyPart::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -28,6 +24,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -40,19 +44,23 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing BYDT subrecord"); } void BodyPart::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadbook.cpp b/components/esm/loadbook.cpp index 2824b6200..2d0d3ce75 100644 --- a/components/esm/loadbook.cpp +++ b/components/esm/loadbook.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,12 +14,9 @@ namespace ESM void Book::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -28,6 +24,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -52,17 +56,22 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing BKDT subrecord"); } void Book::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadbsgn.cpp b/components/esm/loadbsgn.cpp index 8cdeed3f6..9f5cd7270 100644 --- a/components/esm/loadbsgn.cpp +++ b/components/esm/loadbsgn.cpp @@ -16,16 +16,23 @@ namespace ESM void BirthSign::load(ESMReader &esm) { mPowers.mList.clear(); + mIsDeleted = false; - mIsDeleted = readDeleSubRecord(esm); - mId = esm.getHNString("NAME"); - + bool hasName = false; while (esm.hasMoreSubs()) { esm.getSubName(); uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); break; @@ -40,16 +47,21 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } + + if (!hasName) + esm.fail("Missing NAME subrecord"); } void BirthSign::save(ESMWriter &esm) const { if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); } + esm.writeHNCString("NAME", mId); esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("TNAM", mTexture); diff --git a/components/esm/loadclas.cpp b/components/esm/loadclas.cpp index 1384a6280..b58c35d90 100644 --- a/components/esm/loadclas.cpp +++ b/components/esm/loadclas.cpp @@ -5,7 +5,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -45,12 +44,9 @@ namespace ESM void Class::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -58,6 +54,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); break; @@ -72,17 +76,22 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing CLDT subrecord"); } void Class::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadclot.cpp b/components/esm/loadclot.cpp index 88f2e5715..18f7cd44f 100644 --- a/components/esm/loadclot.cpp +++ b/components/esm/loadclot.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -16,13 +15,9 @@ namespace ESM void Clothing::load(ESMReader &esm) { mParts.mParts.clear(); + mIsDeleted = false; - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } - + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -30,6 +25,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -54,18 +57,23 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing CTDT subrecord"); } void Clothing::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadcont.cpp b/components/esm/loadcont.cpp index 3d3d7fced..fadfe5f0f 100644 --- a/components/esm/loadcont.cpp +++ b/components/esm/loadcont.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -26,19 +25,17 @@ namespace ESM unsigned int Container::sRecordId = REC_CONT; Container::Container() - : mIsDeleted(false) + : mWeight(0), + mFlags(0x8), + mIsDeleted(false) {} void Container::load(ESMReader &esm) { mInventory.mList.clear(); + mIsDeleted = false; - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } - + bool hasName = false; bool hasWeight = false; bool hasFlags = false; while (esm.hasMoreSubs()) @@ -47,6 +44,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -73,20 +78,25 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasWeight) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasWeight && !mIsDeleted) esm.fail("Missing CNDT subrecord"); - if (!hasFlags) + if (!hasFlags && !mIsDeleted) esm.fail("Missing FLAG subrecord"); } void Container::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index 57e911e70..f360c8748 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -3,14 +3,15 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { unsigned int Creature::sRecordId = REC_CREA; Creature::Creature() - : mIsDeleted(false) + : mFlags(0), + mScale(0.0f), + mIsDeleted(false) {} void Creature::load(ESMReader &esm) @@ -22,14 +23,11 @@ namespace ESM { mSpells.mList.clear(); mTransport.mList.clear(); - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } - mScale = 1.f; mHasAI = false; + mIsDeleted = false; + + bool hasName = false; bool hasNpdt = false; bool hasFlags = false; while (esm.hasMoreSubs()) @@ -38,6 +36,14 @@ namespace ESM { uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -85,20 +91,25 @@ namespace ESM { break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasNpdt) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasNpdt && !mIsDeleted) esm.fail("Missing NPDT subrecord"); - if (!hasFlags) + if (!hasFlags && !mIsDeleted) esm.fail("Missing FLAG subrecord"); } void Creature::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loaddial.cpp b/components/esm/loaddial.cpp index fcdb57c8d..c517dc722 100644 --- a/components/esm/loaddial.cpp +++ b/components/esm/loaddial.cpp @@ -7,7 +7,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -31,20 +30,36 @@ namespace ESM void Dialogue::loadData(ESMReader &esm) { - esm.getSubNameIs("DATA"); - esm.getSubHeader(); - int si = esm.getSubSize(); - if (si == 1) - esm.getT(mType); - else if (si == 4) // The dialogue is deleted + while (esm.hasMoreSubs()) { - int32_t empty; - esm.getT(empty); // Skip an empty DATA - mIsDeleted = readDeleSubRecord(esm); - mType = Unknown; + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'D','A','T','A'>::value: + { + esm.getSubHeader(); + int size = esm.getSubSize(); + if (size == 1) + { + esm.getT(mType); + } + else + { + esm.skip(size); + } + break; + } + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mType = Unknown; + mIsDeleted = true; + break; + default: + esm.fail("Unknown subrecord"); + break; + } } - else - esm.fail("Unknown sub record size"); } void Dialogue::save(ESMWriter &esm) const @@ -52,8 +67,7 @@ namespace ESM esm.writeHNCString("NAME", mId); if (mIsDeleted) { - esm.writeHNT("DATA", static_cast(0)); - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); } else { @@ -138,7 +152,7 @@ namespace ESM { for (InfoContainer::iterator it = mInfo.begin(); it != mInfo.end(); ) { - if (it->mIsDeleted || it->mQuestStatus == DialInfo::QS_Deleted) + if (it->mIsDeleted) it = mInfo.erase(it); else ++it; diff --git a/components/esm/loaddoor.cpp b/components/esm/loaddoor.cpp index 87382fa7b..4f58a4261 100644 --- a/components/esm/loaddoor.cpp +++ b/components/esm/loaddoor.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,18 +14,23 @@ namespace ESM void Door::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; + bool hasName = false; while (esm.hasMoreSubs()) { esm.getSubName(); uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -44,16 +48,21 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } + + if (!hasName) + esm.fail("Missing NAME subrecord"); } void Door::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadench.cpp b/components/esm/loadench.cpp index 1518e0385..0e480c379 100644 --- a/components/esm/loadench.cpp +++ b/components/esm/loadench.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -16,13 +15,9 @@ namespace ESM void Enchantment::load(ESMReader &esm) { mEffects.mList.clear(); + mIsDeleted = false; - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } - + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -30,6 +25,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'E','N','D','T'>::value: esm.getHT(mData, 16); hasData = true; @@ -42,16 +45,20 @@ namespace ESM break; } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing ENDT subrecord"); } void Enchantment::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadfact.cpp b/components/esm/loadfact.cpp index 53f3aa5a6..8538b0b95 100644 --- a/components/esm/loadfact.cpp +++ b/components/esm/loadfact.cpp @@ -5,7 +5,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -33,17 +32,13 @@ namespace ESM void Faction::load(ESMReader &esm) { + mIsDeleted = false; mReactions.clear(); for (int i=0;i<10;++i) mRanks[i].clear(); - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } - - int rankCounter=0; + int rankCounter = 0; + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -51,6 +46,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); break; @@ -75,18 +78,23 @@ namespace ESM } default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing FADT subrecord"); } void Faction::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadglob.cpp b/components/esm/loadglob.cpp index 392df02b5..5f96aff1f 100644 --- a/components/esm/loadglob.cpp +++ b/components/esm/loadglob.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,30 +14,38 @@ namespace ESM void Global::load (ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) + mIsDeleted = false; + mId = esm.getHNString ("NAME"); + + if (esm.isNextSub ("DELE")) { - return; + esm.skipHSub(); + mIsDeleted = true; + } + else + { + mValue.read (esm, ESM::Variant::Format_Global); } - - mValue.read (esm, ESM::Variant::Format_Global); } void Global::save (ESMWriter &esm) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString ("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); - return; + esm.writeHNCString ("DELE", ""); + } + else + { + mValue.write (esm, ESM::Variant::Format_Global); } - - mValue.write (esm, ESM::Variant::Format_Global); } void Global::blank() { mValue.setType (ESM::VT_None); + mIsDeleted = false; } bool operator== (const Global& left, const Global& right) diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index 8f5f0f28b..89fd4e0cd 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -3,14 +3,15 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { unsigned int DialInfo::sRecordId = REC_INFO; DialInfo::DialInfo() - : mIsDeleted(false) + : mFactionLess(false), + mQuestStatus(QS_None), + mIsDeleted(false) {} void DialInfo::load(ESMReader &esm) @@ -29,6 +30,7 @@ namespace ESM { mQuestStatus = QS_None; mFactionLess = false; + mIsDeleted = false; mPrev = esm.getHNString("PNAM"); mNext = esm.getHNString("NNAM"); @@ -36,118 +38,77 @@ namespace ESM // Since there's no way to mark selects as "deleted", we have to clear the SelectStructs from all previous loadings mSelects.clear(); - // If the info is deleted, NAME and DELE sub-records are followed after NNAM - if (esm.isNextSub("NAME")) - { - mResponse = esm.getHString(); - mIsDeleted = readDeleSubRecord(esm); - return; - } - - esm.getSubNameIs("DATA"); - esm.getHT(mData, 12); - - if (!esm.hasMoreSubs()) - return; - - // What follows is somewhat spaghetti-ish, but it's worth if for - // an extra speedup. INFO is by far the most common record type. - - // subName is a reference to the original, so it changes whenever - // a new sub name is read. esm.isEmptyOrGetName() will get the - // next name for us, or return true if there are no more records. - esm.getSubName(); - const NAME &subName = esm.retSubName(); - - if (subName.val == REC_ONAM) - { - mActor = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } - if (subName.val == REC_RNAM) - { - mRace = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } - if (subName.val == REC_CNAM) - { - mClass = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } - - if (subName.val == REC_FNAM) - { - mFaction = esm.getHString(); - if (mFaction == "FFFF") - mFactionLess = true; - if (esm.isEmptyOrGetName()) - return; - } - if (subName.val == REC_ANAM) - { - mCell = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } - if (subName.val == REC_DNAM) - { - mPcFaction = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } - if (subName.val == REC_SNAM) - { - mSound = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } - if (subName.val == REC_NAME) - { - mResponse = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } - - while (subName.val == REC_SCVR) + while (esm.hasMoreSubs()) { - SelectStruct ss; - - ss.mSelectRule = esm.getHString(); - - ss.mValue.read (esm, Variant::Format_Info); - - mSelects.push_back(ss); - - if (esm.isEmptyOrGetName()) - return; + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; + case ESM::FourCC<'D','A','T','A'>::value: + esm.getHT(mData, 12); + break; + case ESM::FourCC<'O','N','A','M'>::value: + mActor = esm.getHString(); + break; + case ESM::FourCC<'R','N','A','M'>::value: + mRace = esm.getHString(); + break; + case ESM::FourCC<'C','N','A','M'>::value: + mClass = esm.getHString(); + break; + case ESM::FourCC<'F','N','A','M'>::value: + { + mFaction = esm.getHString(); + if (mFaction == "FFFF") + { + mFactionLess = true; + } + break; + } + case ESM::FourCC<'A','N','A','M'>::value: + mCell = esm.getHString(); + break; + case ESM::FourCC<'D','N','A','M'>::value: + mPcFaction = esm.getHString(); + break; + case ESM::FourCC<'S','N','A','M'>::value: + mSound = esm.getHString(); + break; + case ESM::FourCC<'N','A','M','E'>::value: + mResponse = esm.getHString(); + break; + case ESM::FourCC<'S','C','V','R'>::value: + { + SelectStruct ss; + ss.mSelectRule = esm.getHString(); + ss.mValue.read(esm, Variant::Format_Info); + mSelects.push_back(ss); + break; + } + case ESM::FourCC<'B','N','A','M'>::value: + mResultScript = esm.getHString(); + break; + case ESM::FourCC<'Q','S','T','N'>::value: + mQuestStatus = QS_Name; + esm.skipRecord(); + break; + case ESM::FourCC<'Q','S','T','F'>::value: + mQuestStatus = QS_Finished; + esm.skipRecord(); + break; + case ESM::FourCC<'Q','S','T','R'>::value: + mQuestStatus = QS_Restart; + esm.skipRecord(); + break; + default: + esm.fail("Unknown subrecord"); + break; + } } - - if (subName.val == REC_BNAM) - { - mResultScript = esm.getHString(); - if (esm.isEmptyOrGetName()) - return; - } - - if (subName.val == REC_QSTN) - mQuestStatus = QS_Name; - else if (subName.val == REC_QSTF) - mQuestStatus = QS_Finished; - else if (subName.val == REC_QSTR) - mQuestStatus = QS_Restart; - else if (subName.val == REC_DELE) - mQuestStatus = QS_Deleted; - else - esm.fail( - "Don't know what to do with " + subName.toString() - + " in INFO " + mId); - - if (mQuestStatus != QS_None) - // Skip rest of record - esm.skipRecord(); } void DialInfo::save(ESMWriter &esm) const @@ -158,8 +119,7 @@ namespace ESM if (mIsDeleted) { - esm.writeHNCString("NAME", mResponse); - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } @@ -186,7 +146,6 @@ namespace ESM case QS_Name: esm.writeHNT("QSTN",'\1'); break; case QS_Finished: esm.writeHNT("QSTF", '\1'); break; case QS_Restart: esm.writeHNT("QSTR", '\1'); break; - case QS_Deleted: esm.writeHNT("DELE", '\1'); break; default: break; } } diff --git a/components/esm/loadinfo.hpp b/components/esm/loadinfo.hpp index c243cd50e..65363d1be 100644 --- a/components/esm/loadinfo.hpp +++ b/components/esm/loadinfo.hpp @@ -59,8 +59,7 @@ struct DialInfo QS_None = 0, QS_Name = 1, QS_Finished = 2, - QS_Restart = 3, - QS_Deleted + QS_Restart = 3 }; // Rules for when to include this item in the final list of options diff --git a/components/esm/loadingr.cpp b/components/esm/loadingr.cpp index a7018b36d..51a1f4805 100644 --- a/components/esm/loadingr.cpp +++ b/components/esm/loadingr.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,12 +14,9 @@ namespace ESM void Ingredient::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -28,6 +24,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -46,10 +50,13 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing IRDT subrecord"); // horrible hack to fix broken data in records @@ -79,9 +86,10 @@ namespace ESM void Ingredient::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadlevlist.cpp b/components/esm/loadlevlist.cpp index 1e07086bc..9c34ef657 100644 --- a/components/esm/loadlevlist.cpp +++ b/components/esm/loadlevlist.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -13,49 +12,67 @@ namespace ESM void LevelledListBase::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } - - esm.getHNT(mFlags, "DATA"); - esm.getHNT(mChanceNone, "NNAM"); + mIsDeleted = false; - if (esm.isNextSub("INDX")) - { - int len; - esm.getHT(len); - mList.resize(len); - } - else + bool hasName = false; + while (esm.hasMoreSubs()) { - // Original engine ignores rest of the record, even if there are items following - mList.clear(); - esm.skipRecord(); - return; - } + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; + case ESM::FourCC<'D','A','T','A'>::value: + esm.getHT(mFlags); + break; + case ESM::FourCC<'N','N','A','M'>::value: + esm.getHT(mChanceNone); + break; + case ESM::FourCC<'I','N','D','X'>::value: + { + int length = 0; + esm.getHT(length); + mList.resize(length); - // If this levelled list was already loaded by a previous content file, - // we overwrite the list. Merging lists should probably be left to external tools, - // with the limited amount of information there is in the records, all merging methods - // will be flawed in some way. For a proper fix the ESM format would have to be changed - // to actually track list changes instead of including the whole list for every file - // that does something with that list. - - for (size_t i = 0; i < mList.size(); i++) - { - LevelItem &li = mList[i]; - li.mId = esm.getHNString(mRecName); - esm.getHNT(li.mLevel, "INTV"); + // If this levelled list was already loaded by a previous content file, + // we overwrite the list. Merging lists should probably be left to external tools, + // with the limited amount of information there is in the records, all merging methods + // will be flawed in some way. For a proper fix the ESM format would have to be changed + // to actually track list changes instead of including the whole list for every file + // that does something with that list. + for (size_t i = 0; i < mList.size(); i++) + { + LevelItem &li = mList[i]; + li.mId = esm.getHNString(mRecName); + esm.getHNT(li.mLevel, "INTV"); + } + break; + } + default: + mList.clear(); + esm.skipRecord(); + break; + } } + + if (!hasName) + esm.fail("Missing NAME subrecord"); } + void LevelledListBase::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadligh.cpp b/components/esm/loadligh.cpp index a153d500a..441e96d0a 100644 --- a/components/esm/loadligh.cpp +++ b/components/esm/loadligh.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,12 +14,9 @@ namespace ESM void Light::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -28,6 +24,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -49,17 +53,22 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing LHDT subrecord"); } void Light::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadlock.cpp b/components/esm/loadlock.cpp index 3b169af33..5ee041dab 100644 --- a/components/esm/loadlock.cpp +++ b/components/esm/loadlock.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,19 +14,23 @@ namespace ESM void Lockpick::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; - bool hasData = true; + bool hasName = false; + bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -46,18 +49,23 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing LKDT subrecord"); } void Lockpick::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadltex.cpp b/components/esm/loadltex.cpp index 13315e684..7c14536ed 100644 --- a/components/esm/loadltex.cpp +++ b/components/esm/loadltex.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,17 +14,49 @@ namespace ESM void LandTexture::load(ESMReader &esm) { - mIsDeleted = readDeleSubRecord(esm); - mId = esm.getHNString("NAME"); - esm.getHNT(mIndex, "INTV"); - mTexture = esm.getHNString("DATA"); + mIsDeleted = false; + + bool hasName = false; + bool hasIndex = false; + while (esm.hasMoreSubs()) + { + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = false; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; + case ESM::FourCC<'I','N','T','V'>::value: + esm.getHT(mIndex); + hasIndex = true; + break; + case ESM::FourCC<'D','A','T','A'>::value: + mTexture = esm.getHString(); + break; + default: + esm.fail("Unknown subrecord"); + break; + } + } + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasIndex) + esm.fail("Missing INTV subrecord"); } void LandTexture::save(ESMWriter &esm) const { if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); } + esm.writeHNCString("NAME", mId); esm.writeHNT("INTV", mIndex); esm.writeHNCString("DATA", mTexture); diff --git a/components/esm/loadmisc.cpp b/components/esm/loadmisc.cpp index 08cbcf741..de9ccdd6a 100644 --- a/components/esm/loadmisc.cpp +++ b/components/esm/loadmisc.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,12 +14,9 @@ namespace ESM void Miscellaneous::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -28,6 +24,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -44,18 +48,25 @@ namespace ESM case ESM::FourCC<'I','T','E','X'>::value: mIcon = esm.getHString(); break; + default: + esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing MCDT subrecord"); } void Miscellaneous::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index eadf23a21..ff3213ee9 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -3,40 +3,45 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { unsigned int NPC::sRecordId = REC_NPC_; NPC::NPC() - : mIsDeleted(false) + : mFlags(0), + mHasAI(false), + mIsDeleted(false) {} void NPC::load(ESMReader &esm) { + mIsDeleted = false; mPersistent = (esm.getRecordFlags() & 0x0400) != 0; mSpells.mList.clear(); mInventory.mList.clear(); mTransport.mList.clear(); mAiPackage.mList.clear(); + mHasAI = false; - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } - + bool hasName = false; bool hasNpdt = false; bool hasFlags = false; - mHasAI = false; while (esm.hasMoreSubs()) { esm.getSubName(); uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -105,19 +110,24 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasNpdt) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasNpdt && !mIsDeleted) esm.fail("Missing NPDT subrecord"); - if (!hasFlags) + if (!hasFlags && !mIsDeleted) esm.fail("Missing FLAG subrecord"); } void NPC::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadprob.cpp b/components/esm/loadprob.cpp index f5287f986..4ce9b9d9c 100644 --- a/components/esm/loadprob.cpp +++ b/components/esm/loadprob.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,19 +14,24 @@ namespace ESM void Probe::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; - bool hasData = true; + bool hasName = false; + bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -46,18 +50,23 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing PBDT subrecord"); } void Probe::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadregn.cpp b/components/esm/loadregn.cpp index 2d99947b0..b48ffa4b7 100644 --- a/components/esm/loadregn.cpp +++ b/components/esm/loadregn.cpp @@ -3,64 +3,95 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { unsigned int Region::sRecordId = REC_REGN; Region::Region() - : mIsDeleted(false) + : mMapColor(0), + mIsDeleted(false) {} void Region::load(ESMReader &esm) { - mIsDeleted = readDeleSubRecord(esm); - mId = esm.getHNString("NAME"); - mName = esm.getHNOString("FNAM"); + mIsDeleted = false; - esm.getSubNameIs("WEAT"); - esm.getSubHeader(); - if (esm.getVer() == VER_12) - { - mData.mA = 0; - mData.mB = 0; - esm.getExact(&mData, sizeof(mData) - 2); - } - else if (esm.getVer() == VER_13) + bool hasName = false; + while (esm.hasMoreSubs()) { - // May include the additional two bytes (but not necessarily) - if (esm.getSubSize() == sizeof(mData)) - esm.getExact(&mData, sizeof(mData)); - else + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) { - mData.mA = 0; - mData.mB = 0; - esm.getExact(&mData, sizeof(mData)-2); + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; + case ESM::FourCC<'F','N','A','M'>::value: + mName = esm.getHString(); + break; + case ESM::FourCC<'W','E','A','T'>::value: + { + esm.getSubHeader(); + if (esm.getVer() == VER_12) + { + mData.mA = 0; + mData.mB = 0; + esm.getExact(&mData, sizeof(mData) - 2); + } + else if (esm.getVer() == VER_13) + { + // May include the additional two bytes (but not necessarily) + if (esm.getSubSize() == sizeof(mData)) + { + esm.getExact(&mData, sizeof(mData)); + } + else + { + mData.mA = 0; + mData.mB = 0; + esm.getExact(&mData, sizeof(mData)-2); + } + } + else + { + esm.fail("Don't know what to do in this version"); + } + break; + } + case ESM::FourCC<'B','N','A','M'>::value: + mSleepList = esm.getHString(); + break; + case ESM::FourCC<'C','N','A','M'>::value: + esm.getHT(mMapColor); + break; + case ESM::FourCC<'S','N','A','M'>::value: + SoundRef sr; + esm.getHT(sr, 33); + mSoundList.push_back(sr); + break; + default: + esm.fail("Unknown subrecord"); + break; } } - else - esm.fail("Don't know what to do in this version"); - - mSleepList = esm.getHNOString("BNAM"); - esm.getHNT(mMapColor, "CNAM"); - - mSoundList.clear(); - while (esm.hasMoreSubs()) - { - SoundRef sr; - esm.getHNT(sr, "SNAM", 33); - mSoundList.push_back(sr); - } + if (!hasName) + esm.fail("Missing NAME subrecord"); } void Region::save(ESMWriter &esm) const { if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); } + esm.writeHNString("NAME", mId); esm.writeHNOCString("FNAM", mName); diff --git a/components/esm/loadrepa.cpp b/components/esm/loadrepa.cpp index fb213efd8..74e682d63 100644 --- a/components/esm/loadrepa.cpp +++ b/components/esm/loadrepa.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,19 +14,24 @@ namespace ESM void Repair::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; - bool hasData = true; + bool hasName = false; + bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -46,18 +50,23 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing RIDT subrecord"); } void Repair::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index 529f0a66d..333389ba4 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" #include @@ -64,23 +63,27 @@ namespace ESM void Script::load(ESMReader &esm) { - SCHD data; - esm.getHNT(data, "SCHD", 52); - mData = data.mData; - mId = data.mName.toString(); - - // In scripts DELE sub-record appears after a header. - // The script data is following after DELE in this case. - mIsDeleted = readDeleSubRecord(esm); - mVarNames.clear(); + mIsDeleted = false; + bool hasHeader = false; while (esm.hasMoreSubs()) { esm.getSubName(); uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'S','C','H','D'>::value: + SCHD data; + esm.getHT(data, 52); + mData = data.mData; + mId = data.mName.toString(); + hasHeader = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'S','C','V','R'>::value: // list of local variables loadSCVR(esm); @@ -95,8 +98,12 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } + + if (!hasHeader) + esm.fail("Missing SCHD subrecord"); } void Script::save(ESMWriter &esm) const @@ -116,7 +123,7 @@ namespace ESM if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); } if (!mVarNames.empty()) diff --git a/components/esm/loadsndg.cpp b/components/esm/loadsndg.cpp index 261087be0..a20e6ee51 100644 --- a/components/esm/loadsndg.cpp +++ b/components/esm/loadsndg.cpp @@ -3,24 +3,21 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { unsigned int SoundGenerator::sRecordId = REC_SNDG; SoundGenerator::SoundGenerator() - : mIsDeleted(false) + : mType(LeftFoot), + mIsDeleted(false) {} void SoundGenerator::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -28,6 +25,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'D','A','T','A'>::value: esm.getHT(mType, 4); hasData = true; @@ -40,23 +45,26 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) - esm.fail("Missing DATA"); + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) + esm.fail("Missing DATA subrecord"); } void SoundGenerator::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) - { - writeDeleSubRecord(esm); - return; - } - esm.writeHNT("DATA", mType, 4); esm.writeHNOCString("CNAM", mCreature); esm.writeHNOCString("SNAM", mSound); + + if (mIsDeleted) + { + esm.writeHNCString("DELE", ""); + } } void SoundGenerator::blank() diff --git a/components/esm/loadsoun.cpp b/components/esm/loadsoun.cpp index 9a1a52b1e..55fe69292 100644 --- a/components/esm/loadsoun.cpp +++ b/components/esm/loadsoun.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,12 +14,9 @@ namespace ESM void Sound::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -28,6 +24,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'F','N','A','M'>::value: mSound = esm.getHString(); break; @@ -37,18 +41,23 @@ namespace ESM break; default: esm.fail("Unknown subrecord"); + break; } } - if (!hasData) - esm.fail("Missing DATA"); + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) + esm.fail("Missing DATA subrecord"); } void Sound::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } diff --git a/components/esm/loadspel.cpp b/components/esm/loadspel.cpp index d2d8c7d6d..28feffd20 100644 --- a/components/esm/loadspel.cpp +++ b/components/esm/loadspel.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -16,13 +15,9 @@ namespace ESM void Spell::load(ESMReader &esm) { mEffects.mList.clear(); + mIsDeleted = false; - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } - + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -31,6 +26,14 @@ namespace ESM switch (val) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); break; @@ -43,18 +46,25 @@ namespace ESM esm.getHT(s, 24); mEffects.mList.push_back(s); break; + default: + esm.fail("Unknown subrecord"); + break; } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing SPDT subrecord"); } void Spell::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } @@ -70,9 +80,7 @@ namespace ESM mData.mFlags = 0; mName.clear(); - mEffects.mList.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadstat.cpp b/components/esm/loadstat.cpp index 2fde46bd2..9a146a370 100644 --- a/components/esm/loadstat.cpp +++ b/components/esm/loadstat.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,24 +14,46 @@ namespace ESM void Static::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) + mIsDeleted = false; + + bool hasName = false; + while (esm.hasMoreSubs()) { - return; + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; + case ESM::FourCC<'M','O','D','L'>::value: + mModel = esm.getHString(); + break; + default: + esm.fail("Unknown subrecord"); + break; + } } - mModel = esm.getHNString("MODL"); + if (!hasName) + esm.fail("Missing NAME subrecord"); } void Static::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); if (mIsDeleted) { - writeDeleSubRecord(esm); - return; + esm.writeHNCString("DELE", ""); + } + else + { + esm.writeHNCString("MODL", mModel); } - - esm.writeHNCString("MODL", mModel); } void Static::blank() diff --git a/components/esm/loadweap.cpp b/components/esm/loadweap.cpp index 38fb94adb..98302c13d 100644 --- a/components/esm/loadweap.cpp +++ b/components/esm/loadweap.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { @@ -15,12 +14,9 @@ namespace ESM void Weapon::load(ESMReader &esm) { - mId = esm.getHNString("NAME"); - if (mIsDeleted = readDeleSubRecord(esm)) - { - return; - } + mIsDeleted = false; + bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { @@ -28,6 +24,14 @@ namespace ESM uint32_t name = esm.retSubName().val; switch (name) { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -51,15 +55,19 @@ namespace ESM esm.fail("Unknown subrecord"); } } - if (!hasData) + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) esm.fail("Missing WPDT subrecord"); } void Weapon::save(ESMWriter &esm) const { esm.writeHNCString("NAME", mId); + if (mIsDeleted) { - writeDeleSubRecord(esm); + esm.writeHNCString("DELE", ""); return; } From e65ff723ce6e71da7d00e68820250682512418c1 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Thu, 16 Jul 2015 22:17:49 +0300 Subject: [PATCH 31/49] More ESM records have DELE handling. Changed records: Race, Land, Pathgrid, StartScript, DebugProfile, Filter --- components/esm/debugprofile.cpp | 45 +++- components/esm/debugprofile.hpp | 4 + components/esm/filter.cpp | 41 +++- components/esm/filter.hpp | 4 + components/esm/loadland.cpp | 361 +++++++++++++++++--------------- components/esm/loadland.hpp | 4 +- components/esm/loadpgrd.cpp | 186 +++++++++------- components/esm/loadpgrd.hpp | 4 + components/esm/loadrace.cpp | 92 ++++---- components/esm/loadrace.hpp | 4 + components/esm/loadsscr.cpp | 18 ++ components/esm/loadsscr.hpp | 4 + 12 files changed, 482 insertions(+), 285 deletions(-) diff --git a/components/esm/debugprofile.cpp b/components/esm/debugprofile.cpp index 9c8164d29..d1e27debc 100644 --- a/components/esm/debugprofile.cpp +++ b/components/esm/debugprofile.cpp @@ -7,17 +7,53 @@ unsigned int ESM::DebugProfile::sRecordId = REC_DBGP; +ESM::DebugProfile::DebugProfile() + : mIsDeleted(false) +{} + void ESM::DebugProfile::load (ESMReader& esm) { - mId = esm.getHNString ("NAME"); - mDescription = esm.getHNString ("DESC"); - mScriptText = esm.getHNString ("SCRP"); - esm.getHNT (mFlags, "FLAG"); + mIsDeleted = false; + + while (esm.hasMoreSubs()) + { + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; + case ESM::FourCC<'D','E','S','C'>::value: + mDescription = esm.getHString(); + break; + case ESM::FourCC<'S','C','R','P'>::value: + mScriptText = esm.getHString(); + break; + case ESM::FourCC<'F','L','A','G'>::value: + esm.getHT(mFlags); + break; + default: + esm.fail("Unknown subrecord"); + break; + } + } } void ESM::DebugProfile::save (ESMWriter& esm) const { esm.writeHNCString ("NAME", mId); + + if (mIsDeleted) + { + esm.writeHNCString("DELE", ""); + return; + } + esm.writeHNCString ("DESC", mDescription); esm.writeHNCString ("SCRP", mScriptText); esm.writeHNT ("FLAG", mFlags); @@ -28,4 +64,5 @@ void ESM::DebugProfile::blank() mDescription.clear(); mScriptText.clear(); mFlags = 0; + mIsDeleted = false; } diff --git a/components/esm/debugprofile.hpp b/components/esm/debugprofile.hpp index b54e8ff5f..1709136f5 100644 --- a/components/esm/debugprofile.hpp +++ b/components/esm/debugprofile.hpp @@ -27,6 +27,10 @@ namespace ESM unsigned int mFlags; + bool mIsDeleted; + + DebugProfile(); + void load (ESMReader& esm); void save (ESMWriter& esm) const; diff --git a/components/esm/filter.cpp b/components/esm/filter.cpp index ee2c67869..57cb59454 100644 --- a/components/esm/filter.cpp +++ b/components/esm/filter.cpp @@ -7,16 +7,50 @@ unsigned int ESM::Filter::sRecordId = REC_FILT; +ESM::Filter::Filter() + : mIsDeleted(false) +{} + void ESM::Filter::load (ESMReader& esm) { - mId = esm.getHNString ("NAME"); - mFilter = esm.getHNString ("FILT"); - mDescription = esm.getHNString ("DESC"); + mIsDeleted = false; + + while (esm.hasMoreSubs()) + { + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; + case ESM::FourCC<'F','I','L','T'>::value: + mFilter = esm.getHString(); + break; + case ESM::FourCC<'D','E','S','C'>::value: + mDescription = esm.getHString(); + break; + default: + esm.fail("Unknown subrecord"); + break; + } + } } void ESM::Filter::save (ESMWriter& esm) const { esm.writeHNCString ("NAME", mId); + + if (mIsDeleted) + { + esm.writeHNCString("DELE", ""); + return; + } + esm.writeHNCString ("FILT", mFilter); esm.writeHNCString ("DESC", mDescription); } @@ -25,4 +59,5 @@ void ESM::Filter::blank() { mFilter.clear(); mDescription.clear(); + mIsDeleted = false; } diff --git a/components/esm/filter.hpp b/components/esm/filter.hpp index bc3dd7bdc..1a8af9229 100644 --- a/components/esm/filter.hpp +++ b/components/esm/filter.hpp @@ -18,6 +18,10 @@ namespace ESM std::string mFilter; + bool mIsDeleted; + + Filter(); + void load (ESMReader& esm); void save (ESMWriter& esm) const; diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index b0897ec67..6acaa6e6a 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -8,211 +8,234 @@ namespace ESM { unsigned int Land::sRecordId = REC_LAND; -void Land::LandData::save(ESMWriter &esm) -{ - if (mDataTypes & Land::DATA_VNML) { - esm.writeHNT("VNML", mNormals, sizeof(mNormals)); - } - if (mDataTypes & Land::DATA_VHGT) { - VHGT offsets; - offsets.mHeightOffset = mHeights[0] / HEIGHT_SCALE; - offsets.mUnk1 = mUnk1; - offsets.mUnk2 = mUnk2; - - float prevY = mHeights[0]; - int number = 0; // avoid multiplication - for (int i = 0; i < LAND_SIZE; ++i) { - float diff = (mHeights[number] - prevY) / HEIGHT_SCALE; - offsets.mHeightData[number] = - (diff >= 0) ? (int8_t) (diff + 0.5) : (int8_t) (diff - 0.5); - - float prevX = prevY = mHeights[number]; - ++number; - - for (int j = 1; j < LAND_SIZE; ++j) { - diff = (mHeights[number] - prevX) / HEIGHT_SCALE; + void Land::LandData::save(ESMWriter &esm) + { + if (mDataTypes & Land::DATA_VNML) { + esm.writeHNT("VNML", mNormals, sizeof(mNormals)); + } + if (mDataTypes & Land::DATA_VHGT) { + VHGT offsets; + offsets.mHeightOffset = mHeights[0] / HEIGHT_SCALE; + offsets.mUnk1 = mUnk1; + offsets.mUnk2 = mUnk2; + + float prevY = mHeights[0]; + int number = 0; // avoid multiplication + for (int i = 0; i < LAND_SIZE; ++i) { + float diff = (mHeights[number] - prevY) / HEIGHT_SCALE; offsets.mHeightData[number] = (diff >= 0) ? (int8_t) (diff + 0.5) : (int8_t) (diff - 0.5); - prevX = mHeights[number]; + float prevX = prevY = mHeights[number]; ++number; + + for (int j = 1; j < LAND_SIZE; ++j) { + diff = (mHeights[number] - prevX) / HEIGHT_SCALE; + offsets.mHeightData[number] = + (diff >= 0) ? (int8_t) (diff + 0.5) : (int8_t) (diff - 0.5); + + prevX = mHeights[number]; + ++number; + } } + esm.writeHNT("VHGT", offsets, sizeof(VHGT)); + } + if (mDataTypes & Land::DATA_WNAM) { + esm.writeHNT("WNAM", mWnam, 81); + } + if (mDataTypes & Land::DATA_VCLR) { + esm.writeHNT("VCLR", mColours, 3*LAND_NUM_VERTS); + } + if (mDataTypes & Land::DATA_VTEX) { + static uint16_t vtex[LAND_NUM_TEXTURES]; + transposeTextureData(mTextures, vtex); + esm.writeHNT("VTEX", vtex, sizeof(vtex)); } - esm.writeHNT("VHGT", offsets, sizeof(VHGT)); - } - if (mDataTypes & Land::DATA_WNAM) { - esm.writeHNT("WNAM", mWnam, 81); - } - if (mDataTypes & Land::DATA_VCLR) { - esm.writeHNT("VCLR", mColours, 3*LAND_NUM_VERTS); - } - if (mDataTypes & Land::DATA_VTEX) { - static uint16_t vtex[LAND_NUM_TEXTURES]; - transposeTextureData(mTextures, vtex); - esm.writeHNT("VTEX", vtex, sizeof(vtex)); } -} - -void Land::LandData::transposeTextureData(uint16_t *in, uint16_t *out) -{ - int readPos = 0; //bit ugly, but it works - for ( int y1 = 0; y1 < 4; y1++ ) - for ( int x1 = 0; x1 < 4; x1++ ) - for ( int y2 = 0; y2 < 4; y2++) - for ( int x2 = 0; x2 < 4; x2++ ) - out[(y1*4+y2)*16+(x1*4+x2)] = in[readPos++]; -} - -Land::Land() - : mFlags(0) - , mX(0) - , mY(0) - , mPlugin(0) - , mEsm(NULL) - , mDataTypes(0) - , mDataLoaded(false) - , mLandData(NULL) -{ -} -Land::~Land() -{ - delete mLandData; -} - -void Land::load(ESMReader &esm) -{ - mEsm = &esm; - mPlugin = mEsm->getIndex(); - - // Get the grid location - esm.getSubNameIs("INTV"); - esm.getSubHeaderIs(8); - esm.getT(mX); - esm.getT(mY); - - esm.getHNT(mFlags, "DATA"); - - // Store the file position - mContext = esm.getContext(); - - // Skip these here. Load the actual data when the cell is loaded. - if (esm.isNextSub("VNML")) - { - esm.skipHSubSize(12675); - mDataTypes |= DATA_VNML; - } - if (esm.isNextSub("VHGT")) + void Land::LandData::transposeTextureData(uint16_t *in, uint16_t *out) { - esm.skipHSubSize(4232); - mDataTypes |= DATA_VHGT; - } - if (esm.isNextSub("WNAM")) + int readPos = 0; //bit ugly, but it works + for ( int y1 = 0; y1 < 4; y1++ ) + for ( int x1 = 0; x1 < 4; x1++ ) + for ( int y2 = 0; y2 < 4; y2++) + for ( int x2 = 0; x2 < 4; x2++ ) + out[(y1*4+y2)*16+(x1*4+x2)] = in[readPos++]; + } + + Land::Land() + : mFlags(0) + , mX(0) + , mY(0) + , mPlugin(0) + , mEsm(NULL) + , mDataTypes(0) + , mDataLoaded(false) + , mLandData(NULL) + , mIsDeleted(false) { - esm.skipHSubSize(81); - mDataTypes |= DATA_WNAM; } - if (esm.isNextSub("VCLR")) + + Land::~Land() { - esm.skipHSubSize(12675); - mDataTypes |= DATA_VCLR; + delete mLandData; } - if (esm.isNextSub("VTEX")) + + void Land::load(ESMReader &esm) { - esm.skipHSubSize(512); - mDataTypes |= DATA_VTEX; + mEsm = &esm; + mPlugin = mEsm->getIndex(); + mIsDeleted = false; + + // Get the grid location + esm.getSubNameIs("INTV"); + esm.getSubHeaderIs(8); + esm.getT(mX); + esm.getT(mY); + + esm.getHNT(mFlags, "DATA"); + + if (esm.isNextSub("DELE")) + { + esm.skipHSub(); + mIsDeleted = true; + } + + // Store the file position + mContext = esm.getContext(); + + // Skip these here. Load the actual data when the cell is loaded. + if (esm.isNextSub("VNML")) + { + esm.skipHSubSize(12675); + mDataTypes |= DATA_VNML; + } + if (esm.isNextSub("VHGT")) + { + esm.skipHSubSize(4232); + mDataTypes |= DATA_VHGT; + } + if (esm.isNextSub("WNAM")) + { + esm.skipHSubSize(81); + mDataTypes |= DATA_WNAM; + } + if (esm.isNextSub("VCLR")) + { + esm.skipHSubSize(12675); + mDataTypes |= DATA_VCLR; + } + if (esm.isNextSub("VTEX")) + { + esm.skipHSubSize(512); + mDataTypes |= DATA_VTEX; + } + + mDataLoaded = 0; + mLandData = NULL; } - mDataLoaded = 0; - mLandData = NULL; -} + void Land::save(ESMWriter &esm) const + { + esm.startSubRecord("INTV"); + esm.writeT(mX); + esm.writeT(mY); + esm.endRecord("INTV"); -void Land::save(ESMWriter &esm) const -{ - esm.startSubRecord("INTV"); - esm.writeT(mX); - esm.writeT(mY); - esm.endRecord("INTV"); + esm.writeHNT("DATA", mFlags); - esm.writeHNT("DATA", mFlags); -} + if (mIsDeleted) + { + esm.writeHNCString("DELE", ""); + } -void Land::loadData(int flags) -{ - // Try to load only available data - flags = flags & mDataTypes; - // Return if all required data is loaded - if ((mDataLoaded & flags) == flags) { - return; - } - // Create storage if nothing is loaded - if (mLandData == NULL) { - mLandData = new LandData; - mLandData->mDataTypes = mDataTypes; + if (mLandData != NULL) + { + mLandData->save(esm); + } } - mEsm->restoreContext(mContext); - if (mEsm->isNextSub("VNML")) { - condLoad(flags, DATA_VNML, mLandData->mNormals, sizeof(mLandData->mNormals)); + void Land::blank() + { + mIsDeleted = false; } - if (mEsm->isNextSub("VHGT")) { - static VHGT vhgt; - if (condLoad(flags, DATA_VHGT, &vhgt, sizeof(vhgt))) { - float rowOffset = vhgt.mHeightOffset; - for (int y = 0; y < LAND_SIZE; y++) { - rowOffset += vhgt.mHeightData[y * LAND_SIZE]; + void Land::loadData(int flags) + { + // Try to load only available data + flags = flags & mDataTypes; + // Return if all required data is loaded + if ((mDataLoaded & flags) == flags) { + return; + } + // Create storage if nothing is loaded + if (mLandData == NULL) { + mLandData = new LandData; + mLandData->mDataTypes = mDataTypes; + } + mEsm->restoreContext(mContext); + + if (mEsm->isNextSub("VNML")) { + condLoad(flags, DATA_VNML, mLandData->mNormals, sizeof(mLandData->mNormals)); + } + + if (mEsm->isNextSub("VHGT")) { + static VHGT vhgt; + if (condLoad(flags, DATA_VHGT, &vhgt, sizeof(vhgt))) { + float rowOffset = vhgt.mHeightOffset; + for (int y = 0; y < LAND_SIZE; y++) { + rowOffset += vhgt.mHeightData[y * LAND_SIZE]; - mLandData->mHeights[y * LAND_SIZE] = rowOffset * HEIGHT_SCALE; + mLandData->mHeights[y * LAND_SIZE] = rowOffset * HEIGHT_SCALE; - float colOffset = rowOffset; - for (int x = 1; x < LAND_SIZE; x++) { - colOffset += vhgt.mHeightData[y * LAND_SIZE + x]; - mLandData->mHeights[x + y * LAND_SIZE] = colOffset * HEIGHT_SCALE; + float colOffset = rowOffset; + for (int x = 1; x < LAND_SIZE; x++) { + colOffset += vhgt.mHeightData[y * LAND_SIZE + x]; + mLandData->mHeights[x + y * LAND_SIZE] = colOffset * HEIGHT_SCALE; + } } + mLandData->mUnk1 = vhgt.mUnk1; + mLandData->mUnk2 = vhgt.mUnk2; } - mLandData->mUnk1 = vhgt.mUnk1; - mLandData->mUnk2 = vhgt.mUnk2; } - } - if (mEsm->isNextSub("WNAM")) { - condLoad(flags, DATA_WNAM, mLandData->mWnam, 81); - } - if (mEsm->isNextSub("VCLR")) - condLoad(flags, DATA_VCLR, mLandData->mColours, 3 * LAND_NUM_VERTS); - if (mEsm->isNextSub("VTEX")) { - static uint16_t vtex[LAND_NUM_TEXTURES]; - if (condLoad(flags, DATA_VTEX, vtex, sizeof(vtex))) { - LandData::transposeTextureData(vtex, mLandData->mTextures); + if (mEsm->isNextSub("WNAM")) { + condLoad(flags, DATA_WNAM, mLandData->mWnam, 81); + } + if (mEsm->isNextSub("VCLR")) + condLoad(flags, DATA_VCLR, mLandData->mColours, 3 * LAND_NUM_VERTS); + if (mEsm->isNextSub("VTEX")) { + static uint16_t vtex[LAND_NUM_TEXTURES]; + if (condLoad(flags, DATA_VTEX, vtex, sizeof(vtex))) { + LandData::transposeTextureData(vtex, mLandData->mTextures); + } } } -} -void Land::unloadData() -{ - if (mDataLoaded) + void Land::unloadData() { - delete mLandData; - mLandData = NULL; - mDataLoaded = 0; + if (mDataLoaded) + { + delete mLandData; + mLandData = NULL; + mDataLoaded = 0; + } } -} -bool Land::condLoad(int flags, int dataFlag, void *ptr, unsigned int size) -{ - if ((mDataLoaded & dataFlag) == 0 && (flags & dataFlag) != 0) { - mEsm->getHExact(ptr, size); - mDataLoaded |= dataFlag; - return true; + bool Land::condLoad(int flags, int dataFlag, void *ptr, unsigned int size) + { + if ((mDataLoaded & dataFlag) == 0 && (flags & dataFlag) != 0) { + mEsm->getHExact(ptr, size); + mDataLoaded |= dataFlag; + return true; + } + mEsm->skipHSubSize(size); + return false; } - mEsm->skipHSubSize(size); - return false; -} -bool Land::isDataLoaded(int flags) const -{ - return (mDataLoaded & flags) == (flags & mDataTypes); -} + bool Land::isDataLoaded(int flags) const + { + return (mDataLoaded & flags) == (flags & mDataTypes); + } } diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index 61ce4855e..d9ee0015a 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -97,10 +97,12 @@ struct Land LandData *mLandData; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; - void blank() {} + void blank(); /** * Actually loads data diff --git a/components/esm/loadpgrd.cpp b/components/esm/loadpgrd.cpp index fc0974c9d..5e8de9d57 100644 --- a/components/esm/loadpgrd.cpp +++ b/components/esm/loadpgrd.cpp @@ -32,98 +32,137 @@ namespace ESM { } -void Pathgrid::load(ESMReader &esm) -{ - esm.getHNT(mData, "DATA", 12); - mCell = esm.getHNString("NAME"); + Pathgrid::Pathgrid() + : mIsDeleted(false) + {} - mPoints.clear(); - mEdges.clear(); + void Pathgrid::load(ESMReader &esm) + { + mPoints.clear(); + mEdges.clear(); - // keep track of total connections so we can reserve edge vector size - int edgeCount = 0; + // keep track of total connections so we can reserve edge vector size + int edgeCount = 0; - if (esm.isNextSub("PGRP")) - { - esm.getSubHeader(); - int size = esm.getSubSize(); - // Check that the sizes match up. Size = 16 * s2 (path points) - if (size != static_cast (sizeof(Point) * mData.mS2)) - esm.fail("Path point subrecord size mismatch"); - else + bool hasData = false; + bool hasName = false; + while (esm.hasMoreSubs()) { - int pointCount = mData.mS2; - mPoints.reserve(pointCount); - for (int i = 0; i < pointCount; ++i) + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) { - Point p; - esm.getExact(&p, sizeof(Point)); - mPoints.push_back(p); - edgeCount += p.mConnectionNum; + case ESM::FourCC<'D','A','T','A'>::value: + esm.getHT(mData, 12); + hasData = true; + break; + case ESM::FourCC<'N','A','M','E'>::value: + mCell = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'P','G','R','P'>::value: + { + esm.getSubHeader(); + int size = esm.getSubSize(); + // Check that the sizes match up. Size = 16 * s2 (path points) + if (size != static_cast (sizeof(Point) * mData.mS2)) + esm.fail("Path point subrecord size mismatch"); + else + { + int pointCount = mData.mS2; + mPoints.reserve(pointCount); + for (int i = 0; i < pointCount; ++i) + { + Point p; + esm.getExact(&p, sizeof(Point)); + mPoints.push_back(p); + edgeCount += p.mConnectionNum; + } + } + break; + } + case ESM::FourCC<'P','G','R','C'>::value: + { + esm.getSubHeader(); + int size = esm.getSubSize(); + if (size % sizeof(int) != 0) + esm.fail("PGRC size not a multiple of 4"); + else + { + int rawConnNum = size / sizeof(int); + std::vector rawConnections; + rawConnections.reserve(rawConnNum); + for (int i = 0; i < rawConnNum; ++i) + { + int currentValue; + esm.getT(currentValue); + rawConnections.push_back(currentValue); + } + + std::vector::const_iterator rawIt = rawConnections.begin(); + int pointIndex = 0; + mEdges.reserve(edgeCount); + for(PointList::const_iterator it = mPoints.begin(); it != mPoints.end(); ++it, ++pointIndex) + { + unsigned char connectionNum = (*it).mConnectionNum; + for (int i = 0; i < connectionNum; ++i) { + Edge edge; + edge.mV0 = pointIndex; + edge.mV1 = *rawIt; + ++rawIt; + mEdges.push_back(edge); + } + } + } + break; + } + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; + default: + esm.fail("Unknown subrecord"); + break; } } + + if (!hasData) + esm.fail("Missing DATA subrecord"); + if (!hasName) + esm.fail("Missing NAME subrecord"); } - if (esm.isNextSub("PGRC")) + void Pathgrid::save(ESMWriter &esm) const { - esm.getSubHeader(); - int size = esm.getSubSize(); - if (size % sizeof(int) != 0) - esm.fail("PGRC size not a multiple of 4"); - else - { - int rawConnNum = size / sizeof(int); - std::vector rawConnections; - rawConnections.reserve(rawConnNum); - for (int i = 0; i < rawConnNum; ++i) - { - int currentValue; - esm.getT(currentValue); - rawConnections.push_back(currentValue); - } + esm.writeHNT("DATA", mData, 12); + esm.writeHNCString("NAME", mCell); - std::vector::const_iterator rawIt = rawConnections.begin(); - int pointIndex = 0; - mEdges.reserve(edgeCount); - for(PointList::const_iterator it = mPoints.begin(); it != mPoints.end(); ++it, ++pointIndex) - { - unsigned char connectionNum = (*it).mConnectionNum; - for (int i = 0; i < connectionNum; ++i) { - Edge edge; - edge.mV0 = pointIndex; - edge.mV1 = *rawIt; - ++rawIt; - mEdges.push_back(edge); - } - } + if (mIsDeleted) + { + esm.writeHNCString("DELE", ""); + return; } - } -} -void Pathgrid::save(ESMWriter &esm) const -{ - esm.writeHNT("DATA", mData, 12); - esm.writeHNCString("NAME", mCell); - if (!mPoints.empty()) - { - esm.startSubRecord("PGRP"); - for (PointList::const_iterator it = mPoints.begin(); it != mPoints.end(); ++it) + if (!mPoints.empty()) { - esm.writeT(*it); + esm.startSubRecord("PGRP"); + for (PointList::const_iterator it = mPoints.begin(); it != mPoints.end(); ++it) + { + esm.writeT(*it); + } + esm.endRecord("PGRP"); } - esm.endRecord("PGRP"); - } - if (!mEdges.empty()) - { - esm.startSubRecord("PGRC"); - for (std::vector::const_iterator it = mEdges.begin(); it != mEdges.end(); ++it) + if (!mEdges.empty()) { - esm.writeT(it->mV1); + esm.startSubRecord("PGRC"); + for (std::vector::const_iterator it = mEdges.begin(); it != mEdges.end(); ++it) + { + esm.writeT(it->mV1); + } + esm.endRecord("PGRC"); } - esm.endRecord("PGRC"); } -} void Pathgrid::blank() { @@ -134,5 +173,6 @@ void Pathgrid::save(ESMWriter &esm) const mData.mS2 = 0; mPoints.clear(); mEdges.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadpgrd.hpp b/components/esm/loadpgrd.hpp index f33ccbedf..4b82d9571 100644 --- a/components/esm/loadpgrd.hpp +++ b/components/esm/loadpgrd.hpp @@ -53,6 +53,10 @@ struct Pathgrid typedef std::vector EdgeList; EdgeList mEdges; + bool mIsDeleted; + + Pathgrid(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadrace.cpp b/components/esm/loadrace.cpp index 3feb06c92..12762bda3 100644 --- a/components/esm/loadrace.cpp +++ b/components/esm/loadrace.cpp @@ -8,6 +8,10 @@ namespace ESM { unsigned int Race::sRecordId = REC_RACE; + Race::Race() + : mIsDeleted(false) + {} + int Race::MaleFemale::getValue (bool male) const { return male ? mMale : mFemale; @@ -18,47 +22,65 @@ namespace ESM return static_cast(male ? mMale : mFemale); } -void Race::load(ESMReader &esm) -{ - mPowers.mList.clear(); + void Race::load(ESMReader &esm) + { + mPowers.mList.clear(); + mIsDeleted = false; - mId = esm.getHNString("NAME"); + bool hasName = false; + bool hasData = false; + while (esm.hasMoreSubs()) + { + esm.getSubName(); + uint32_t name = esm.retSubName().val; + switch (name) + { + case ESM::FourCC<'N','A','M','E'>::value: + mId = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; + case ESM::FourCC<'F','N','A','M'>::value: + mName = esm.getHString(); + break; + case ESM::FourCC<'R','A','D','T'>::value: + esm.getHT(mData, 140); + hasData = true; + break; + case ESM::FourCC<'D','E','S','C'>::value: + mDescription = esm.getHString(); + break; + case ESM::FourCC<'N','P','C','S'>::value: + mPowers.add(esm); + break; + default: + esm.fail("Unknown subrecord"); + } + } - bool hasData = false; - while (esm.hasMoreSubs()) + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData && !mIsDeleted) + esm.fail("Missing RADT subrecord"); + } + void Race::save(ESMWriter &esm) const { - esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + esm.writeHNCString("NAME", mId); + + if (mIsDeleted) { - case ESM::FourCC<'F','N','A','M'>::value: - mName = esm.getHString(); - break; - case ESM::FourCC<'R','A','D','T'>::value: - esm.getHT(mData, 140); - hasData = true; - break; - case ESM::FourCC<'D','E','S','C'>::value: - mDescription = esm.getHString(); - break; - case ESM::FourCC<'N','P','C','S'>::value: - mPowers.add(esm); - break; - default: - esm.fail("Unknown subrecord"); + esm.writeHNCString("DELE", ""); + return; } + + esm.writeHNOCString("FNAM", mName); + esm.writeHNT("RADT", mData, 140); + mPowers.save(esm); + esm.writeHNOString("DESC", mDescription); } - if (!hasData) - esm.fail("Missing RADT subrecord"); -} -void Race::save(ESMWriter &esm) const -{ - esm.writeHNCString("NAME", mId); - esm.writeHNOCString("FNAM", mName); - esm.writeHNT("RADT", mData, 140); - mPowers.save(esm); - esm.writeHNOString("DESC", mDescription); -} void Race::blank() { diff --git a/components/esm/loadrace.hpp b/components/esm/loadrace.hpp index 553d2e68b..e8e9a442b 100644 --- a/components/esm/loadrace.hpp +++ b/components/esm/loadrace.hpp @@ -68,6 +68,10 @@ struct Race std::string mId, mName, mDescription; SpellList mPowers; + bool mIsDeleted; + + Race(); + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadsscr.cpp b/components/esm/loadsscr.cpp index 7380dd0a7..076f73742 100644 --- a/components/esm/loadsscr.cpp +++ b/components/esm/loadsscr.cpp @@ -8,8 +8,14 @@ namespace ESM { unsigned int StartScript::sRecordId = REC_SSCR; + StartScript::StartScript() + : mIsDeleted(false) + {} + void StartScript::load(ESMReader &esm) { + mIsDeleted = false; + bool hasData = false; bool hasName = false; while (esm.hasMoreSubs()) @@ -26,10 +32,16 @@ namespace ESM mId = esm.getHString(); hasName = true; break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + mIsDeleted = true; + break; default: esm.fail("Unknown subrecord"); + break; } } + if (!hasData) esm.fail("Missing DATA"); if (!hasName) @@ -39,10 +51,16 @@ namespace ESM { esm.writeHNString("DATA", mData); esm.writeHNString("NAME", mId); + + if (mIsDeleted) + { + esm.writeHNCString("DELE", ""); + } } void StartScript::blank() { mData.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadsscr.hpp b/components/esm/loadsscr.hpp index dc7ad6a42..e475abd86 100644 --- a/components/esm/loadsscr.hpp +++ b/components/esm/loadsscr.hpp @@ -26,6 +26,10 @@ struct StartScript std::string mData; std::string mId; + bool mIsDeleted; + + StartScript(); + // Load a record and add it to the list void load(ESMReader &esm); void save(ESMWriter &esm) const; From 5fd48efd28e45336a03f5ee2f5b68f799159650e Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Thu, 16 Jul 2015 22:31:59 +0300 Subject: [PATCH 32/49] Some refactoring. Remove unused code --- apps/openmw/mwworld/store.cpp | 33 ++++- components/esm/loadbsgn.cpp | 1 - components/esm/loadcell.cpp | 258 +++++++++++++++++----------------- components/esm/loadlock.cpp | 1 + components/esm/loadltex.cpp | 2 +- components/esm/util.cpp | 75 ---------- components/esm/util.hpp | 47 ------- 7 files changed, 165 insertions(+), 252 deletions(-) delete mode 100644 components/esm/util.cpp diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 8f55bb466..55fb43e00 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -194,7 +194,7 @@ namespace MWWorld if (inserted.second) mShared.push_back(&inserted.first->second); - return RecordId(record.mId, ESM::isRecordDeleted(record)); + return RecordId(record.mId, record.mIsDeleted); } template void Store::setUp() @@ -327,7 +327,7 @@ namespace MWWorld record.load (reader); insert (record); - return RecordId(record.mId, ESM::isRecordDeleted(record)); + return RecordId(record.mId, record.mIsDeleted); } // LandTexture @@ -1083,6 +1083,35 @@ namespace MWWorld return RecordId(script.mId); } + + // GameSetting + // Need to specialize load() and read() methods, because GameSetting can't + // be deleted (has no mIsDeleted flag) + //========================================================================= + + template <> + inline RecordId Store::load(ESM::ESMReader &reader) + { + ESM::GameSetting setting; + setting.load(reader); + Misc::StringUtils::toLower(setting.mId); + + std::pair inserted = mStatic.insert(std::make_pair(setting.mId, setting)); + if (inserted.second) + mShared.push_back(&inserted.first->second); + + return RecordId(setting.mId); + } + + template <> + inline RecordId Store::read(ESM::ESMReader &reader) + { + ESM::GameSetting setting; + setting.load(reader); + insert(setting); + + return RecordId(setting.mId); + } } template class MWWorld::Store; diff --git a/components/esm/loadbsgn.cpp b/components/esm/loadbsgn.cpp index 9f5cd7270..54de009aa 100644 --- a/components/esm/loadbsgn.cpp +++ b/components/esm/loadbsgn.cpp @@ -3,7 +3,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" -#include "util.hpp" namespace ESM { diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 67701a5b7..7e02f0f85 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -12,7 +12,6 @@ #include "esmwriter.hpp" #include "defs.hpp" #include "cellid.hpp" -#include "util.hpp" namespace { @@ -53,171 +52,178 @@ namespace ESM return ref.mRefNum == refNum; } -void Cell::load(ESMReader &esm, bool saveContext) -{ - loadName(esm); - loadData(esm); - loadCell(esm, saveContext); -} + void Cell::load(ESMReader &esm, bool saveContext) + { + loadName(esm); + loadData(esm); + loadCell(esm, saveContext); + } -void Cell::loadName(ESMReader &esm) -{ - mName = esm.getHNString("NAME"); - mIsDeleted = readDeleSubRecord(esm); -} + void Cell::loadName(ESMReader &esm) + { + mName = esm.getHNString("NAME"); -void Cell::loadCell(ESMReader &esm, bool saveContext) -{ - mRefNumCounter = 0; + mIsDeleted = false; + if (esm.isNextSub("DELE")) + { + esm.skipHSub(); + mIsDeleted = true; + } + } - if (mData.mFlags & Interior) + void Cell::loadCell(ESMReader &esm, bool saveContext) { - // Interior cells - if (esm.isNextSub("INTV")) + mRefNumCounter = 0; + + if (mData.mFlags & Interior) { - int waterl; - esm.getHT(waterl); - mWater = (float) waterl; - mWaterInt = true; + // Interior cells + if (esm.isNextSub("INTV")) + { + int waterl; + esm.getHT(waterl); + mWater = (float) waterl; + mWaterInt = true; + } + else if (esm.isNextSub("WHGT")) + { + esm.getHT(mWater); + } + + // Quasi-exterior cells have a region (which determines the + // weather), pure interior cells have ambient lighting + // instead. + if (mData.mFlags & QuasiEx) + mRegion = esm.getHNOString("RGNN"); + else if (esm.isNextSub("AMBI")) + esm.getHT(mAmbi); } - else if (esm.isNextSub("WHGT")) + else { - esm.getHT(mWater); + // Exterior cells + mRegion = esm.getHNOString("RGNN"); + + mMapColor = 0; + esm.getHNOT(mMapColor, "NAM5"); + } + if (esm.isNextSub("NAM0")) { + esm.getHT(mRefNumCounter); } - // Quasi-exterior cells have a region (which determines the - // weather), pure interior cells have ambient lighting - // instead. - if (mData.mFlags & QuasiEx) - mRegion = esm.getHNOString("RGNN"); - else if (esm.isNextSub("AMBI")) - esm.getHT(mAmbi); + if (saveContext) { + mContextList.push_back(esm.getContext()); + esm.skipRecord(); + } } - else - { - // Exterior cells - mRegion = esm.getHNOString("RGNN"); - mMapColor = 0; - esm.getHNOT(mMapColor, "NAM5"); - } - if (esm.isNextSub("NAM0")) { - esm.getHT(mRefNumCounter); + void Cell::loadData(ESMReader &esm) + { + esm.getHNT(mData, "DATA", 12); } - if (saveContext) { + void Cell::postLoad(ESMReader &esm) + { + // Save position of the cell references and move on mContextList.push_back(esm.getContext()); esm.skipRecord(); } -} -void Cell::loadData(ESMReader &esm) -{ - esm.getHNT(mData, "DATA", 12); -} - -void Cell::postLoad(ESMReader &esm) -{ - // Save position of the cell references and move on - mContextList.push_back(esm.getContext()); - esm.skipRecord(); -} - -void Cell::save(ESMWriter &esm) const -{ - esm.writeHNCString("NAME", mName); - if (mIsDeleted) + void Cell::save(ESMWriter &esm) const { - writeDeleSubRecord(esm); - } + esm.writeHNCString("NAME", mName); - esm.writeHNT("DATA", mData, 12); - if (mData.mFlags & Interior) - { - if (mWaterInt) { - int water = - (mWater >= 0) ? (int) (mWater + 0.5) : (int) (mWater - 0.5); - esm.writeHNT("INTV", water); - } else { - esm.writeHNT("WHGT", mWater); + if (mIsDeleted) + { + esm.writeHNCString("DELE", ""); } - if (mData.mFlags & QuasiEx) - esm.writeHNOCString("RGNN", mRegion); + esm.writeHNT("DATA", mData, 12); + if (mData.mFlags & Interior) + { + if (mWaterInt) { + int water = + (mWater >= 0) ? (int) (mWater + 0.5) : (int) (mWater - 0.5); + esm.writeHNT("INTV", water); + } else { + esm.writeHNT("WHGT", mWater); + } + + if (mData.mFlags & QuasiEx) + esm.writeHNOCString("RGNN", mRegion); + else + esm.writeHNT("AMBI", mAmbi, 16); + } else - esm.writeHNT("AMBI", mAmbi, 16); - } - else - { - esm.writeHNOCString("RGNN", mRegion); - if (mMapColor != 0) - esm.writeHNT("NAM5", mMapColor); - } - - if (mRefNumCounter != 0 && !mIsDeleted) - esm.writeHNT("NAM0", mRefNumCounter); -} - -void Cell::restore(ESMReader &esm, int iCtx) const -{ - esm.restoreContext(mContextList.at (iCtx)); -} + { + esm.writeHNOCString("RGNN", mRegion); + if (mMapColor != 0) + esm.writeHNT("NAM5", mMapColor); + } -std::string Cell::getDescription() const -{ - if (mData.mFlags & Interior) - { - return mName; + if (mRefNumCounter != 0) + esm.writeHNT("NAM0", mRefNumCounter); } - else + + void Cell::restore(ESMReader &esm, int iCtx) const { - std::ostringstream stream; - stream << mData.mX << ", " << mData.mY; - return stream.str(); + esm.restoreContext(mContextList.at (iCtx)); } -} -bool Cell::getNextRef(ESMReader &esm, CellRef &ref, bool ignoreMoves, MovedCellRef *mref) -{ - // TODO: Try and document reference numbering, I don't think this has been done anywhere else. - if (!esm.hasMoreSubs()) - return false; - - // NOTE: We should not need this check. It is a safety check until we have checked - // more plugins, and how they treat these moved references. - if (esm.isNextSub("MVRF")) + std::string Cell::getDescription() const { - if (ignoreMoves) + if (mData.mFlags & Interior) { - esm.getHT (mref->mRefNum.mIndex); - esm.getHNOT (mref->mTarget, "CNDT"); - adjustRefNum (mref->mRefNum, esm); + return mName; } else { - // skip rest of cell record (moved references), they are handled elsewhere - esm.skipRecord(); // skip MVRF, CNDT - return false; + std::ostringstream stream; + stream << mData.mX << ", " << mData.mY; + return stream.str(); } } - ref.load (esm); + bool Cell::getNextRef(ESMReader &esm, CellRef &ref, bool ignoreMoves, MovedCellRef *mref) + { + // TODO: Try and document reference numbering, I don't think this has been done anywhere else. + if (!esm.hasMoreSubs()) + return false; - // Identify references belonging to a parent file and adapt the ID accordingly. - adjustRefNum (ref.mRefNum, esm); + // NOTE: We should not need this check. It is a safety check until we have checked + // more plugins, and how they treat these moved references. + if (esm.isNextSub("MVRF")) + { + if (ignoreMoves) + { + esm.getHT (mref->mRefNum.mIndex); + esm.getHNOT (mref->mTarget, "CNDT"); + adjustRefNum (mref->mRefNum, esm); + } + else + { + // skip rest of cell record (moved references), they are handled elsewhere + esm.skipRecord(); // skip MVRF, CNDT + return false; + } + } - return true; -} + ref.load (esm); -bool Cell::getNextMVRF(ESMReader &esm, MovedCellRef &mref) -{ - esm.getHT(mref.mRefNum.mIndex); - esm.getHNOT(mref.mTarget, "CNDT"); + // Identify references belonging to a parent file and adapt the ID accordingly. + adjustRefNum (ref.mRefNum, esm); - adjustRefNum (mref.mRefNum, esm); + return true; + } - return true; -} + bool Cell::getNextMVRF(ESMReader &esm, MovedCellRef &mref) + { + esm.getHT(mref.mRefNum.mIndex); + esm.getHNOT(mref.mTarget, "CNDT"); + + adjustRefNum (mref.mRefNum, esm); + + return true; + } void Cell::blank() { diff --git a/components/esm/loadlock.cpp b/components/esm/loadlock.cpp index 5ee041dab..2cfe43743 100644 --- a/components/esm/loadlock.cpp +++ b/components/esm/loadlock.cpp @@ -26,6 +26,7 @@ namespace ESM { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); + hasName = true; break; case ESM::FourCC<'D','E','L','E'>::value: esm.skipHSub(); diff --git a/components/esm/loadltex.cpp b/components/esm/loadltex.cpp index 7c14536ed..6bd48d801 100644 --- a/components/esm/loadltex.cpp +++ b/components/esm/loadltex.cpp @@ -26,7 +26,7 @@ namespace ESM { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); - hasName = false; + hasName = true; break; case ESM::FourCC<'D','E','L','E'>::value: esm.skipHSub(); diff --git a/components/esm/util.cpp b/components/esm/util.cpp deleted file mode 100644 index a5ec377a3..000000000 --- a/components/esm/util.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "util.hpp" - -#include - -namespace ESM -{ - bool readDeleSubRecord(ESMReader &esm) - { - if (esm.isNextSub("DELE")) - { - esm.skipHSub(); - return true; - } - return false; - } - - void writeDeleSubRecord(ESMWriter &esm) - { - esm.writeHNT("DELE", static_cast(0)); - } - - template <> - bool isRecordDeleted(const StartScript &script) - { - return false; - } - - template <> - bool isRecordDeleted(const Race &race) - { - return false; - } - - template <> - bool isRecordDeleted(const GameSetting &gmst) - { - return false; - } - - template <> - bool isRecordDeleted(const Skill &skill) - { - return false; - } - - template <> - bool isRecordDeleted(const MagicEffect &mgef) - { - return false; - } - - template <> - bool isRecordDeleted(const Pathgrid &pgrd) - { - return false; - } - - template <> - bool isRecordDeleted(const Land &land) - { - return false; - } - - template <> - bool isRecordDeleted(const DebugProfile &profile) - { - return false; - } - - template <> - bool isRecordDeleted(const Filter &filter) - { - return false; - } -} diff --git a/components/esm/util.hpp b/components/esm/util.hpp index 531e7eb76..e16603b84 100644 --- a/components/esm/util.hpp +++ b/components/esm/util.hpp @@ -8,16 +8,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" -#include "loadsscr.hpp" -#include "loadglob.hpp" -#include "loadrace.hpp" -#include "loadgmst.hpp" -#include "loadskil.hpp" -#include "loadmgef.hpp" -#include "loadland.hpp" -#include "loadpgrd.hpp" -#include "debugprofile.hpp" -#include "filter.hpp" namespace ESM { @@ -63,43 +53,6 @@ struct Vector3 } }; -bool readDeleSubRecord(ESMReader &esm); -void writeDeleSubRecord(ESMWriter &esm); - -template -bool isRecordDeleted(const RecordT &record) -{ - return record.mIsDeleted; -} - -// The following records can't be deleted (for now) -template <> -bool isRecordDeleted(const StartScript &script); - -template <> -bool isRecordDeleted(const Race &race); - -template <> -bool isRecordDeleted(const GameSetting &gmst); - -template <> -bool isRecordDeleted(const Skill &skill); - -template <> -bool isRecordDeleted(const MagicEffect &mgef); - -template <> -bool isRecordDeleted(const Pathgrid &pgrd); - -template <> -bool isRecordDeleted(const Land &land); - -template <> -bool isRecordDeleted(const DebugProfile &profile); - -template <> -bool isRecordDeleted(const Filter &filter); - } #endif From a4d3e59e5c7380ffb27b4d17d4574009e2b45379 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sat, 18 Jul 2015 15:55:24 +0300 Subject: [PATCH 33/49] Add a separate method to check whether a record is deleted or not for IdCollection --- apps/opencs/model/world/idcollection.cpp | 3 +++ apps/opencs/model/world/idcollection.hpp | 4 ++-- apps/opencs/model/world/land.hpp | 10 ---------- apps/opencs/model/world/pathgrid.hpp | 10 ---------- apps/opencs/model/world/record.cpp | 24 ++++++++++++++++++++++++ apps/opencs/model/world/record.hpp | 23 +++++++++++++++++++++++ 6 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 apps/opencs/model/world/idcollection.cpp diff --git a/apps/opencs/model/world/idcollection.cpp b/apps/opencs/model/world/idcollection.cpp new file mode 100644 index 000000000..9571ed773 --- /dev/null +++ b/apps/opencs/model/world/idcollection.cpp @@ -0,0 +1,3 @@ +#include "idcollection.hpp" + + diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index d08abce5b..4acfdc474 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -2,9 +2,9 @@ #define CSM_WOLRD_IDCOLLECTION_H #include -#include #include "collection.hpp" +#include "record.hpp" namespace CSMWorld { @@ -48,7 +48,7 @@ namespace CSMWorld std::string id = IdAccessorT().getId (record); int index = searchId (id); - if (ESM::isRecordDeleted (record)) + if (isRecordDeleted(record)) { if (index==-1) { diff --git a/apps/opencs/model/world/land.hpp b/apps/opencs/model/world/land.hpp index adf5c0331..e97a2d7dd 100644 --- a/apps/opencs/model/world/land.hpp +++ b/apps/opencs/model/world/land.hpp @@ -4,7 +4,6 @@ #include #include #include -#include namespace CSMWorld { @@ -27,13 +26,4 @@ namespace CSMWorld }; } -namespace ESM -{ - template <> - bool isRecordDeleted(const CSMWorld::Land &land) - { - return false; - } -} - #endif diff --git a/apps/opencs/model/world/pathgrid.hpp b/apps/opencs/model/world/pathgrid.hpp index cd5e472c8..7e7b7c3bb 100644 --- a/apps/opencs/model/world/pathgrid.hpp +++ b/apps/opencs/model/world/pathgrid.hpp @@ -5,7 +5,6 @@ #include #include -#include namespace CSMWorld { @@ -27,13 +26,4 @@ namespace CSMWorld }; } -namespace ESM -{ - template <> - bool isRecordDeleted(const CSMWorld::Pathgrid &pgrd) - { - return false; - } -} - #endif diff --git a/apps/opencs/model/world/record.cpp b/apps/opencs/model/world/record.cpp index ef2f4d320..87f5090fe 100644 --- a/apps/opencs/model/world/record.cpp +++ b/apps/opencs/model/world/record.cpp @@ -19,3 +19,27 @@ bool CSMWorld::RecordBase::isModified() const { return mState==State_Modified || mState==State_ModifiedOnly; } + +template<> +bool CSMWorld::isRecordDeleted(const CSMWorld::Land &land) +{ + return land.mLand->mIsDeleted; +} + +template<> +bool CSMWorld::isRecordDeleted(const ESM::GameSetting &setting) +{ + return false; +} + +template<> +bool CSMWorld::isRecordDeleted(const ESM::MagicEffect &effect) +{ + return false; +} + +template<> +bool CSMWorld::isRecordDeleted(const ESM::Skill &skill) +{ + return false; +} diff --git a/apps/opencs/model/world/record.hpp b/apps/opencs/model/world/record.hpp index 3362f9f96..c43a8b6ca 100644 --- a/apps/opencs/model/world/record.hpp +++ b/apps/opencs/model/world/record.hpp @@ -3,6 +3,12 @@ #include +#include +#include +#include + +#include "land.hpp" + namespace CSMWorld { struct RecordBase @@ -154,6 +160,23 @@ namespace CSMWorld mState = State_Erased; } } + + // Not all records can be deleted (may be changed in the future), + // so we need to use a separate method to check whether a record is deleted or not. + template + bool isRecordDeleted(const ESXRecordT &record) + { + return record.mIsDeleted; + } + + template<> + bool isRecordDeleted(const Land &land); + template<> + bool isRecordDeleted(const ESM::GameSetting &setting); + template<> + bool isRecordDeleted(const ESM::MagicEffect &effect); + template<> + bool isRecordDeleted(const ESM::Skill &skill); } #endif From e04e32bcffa3c95f7c2a007d5fcf09641fff0b03 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sat, 18 Jul 2015 20:32:10 +0300 Subject: [PATCH 34/49] Delete infos of deleted dialogue when loading a content file --- apps/opencs/model/world/data.cpp | 4 +-- apps/opencs/model/world/infocollection.cpp | 36 ++++++++++++++++++++++ apps/opencs/model/world/infocollection.hpp | 2 ++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 348656a7c..91ccda73c 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -998,11 +998,11 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Messages& messages) if (mJournals.tryDelete (record.mId)) { - /// \todo handle info records + mJournalInfos.removeDialogueInfos(record.mId); } else if (mTopics.tryDelete (record.mId)) { - /// \todo handle info records + mTopicInfos.removeDialogueInfos(record.mId); } else { diff --git a/apps/opencs/model/world/infocollection.cpp b/apps/opencs/model/world/infocollection.cpp index 1b95c1505..665b497d0 100644 --- a/apps/opencs/model/world/infocollection.cpp +++ b/apps/opencs/model/world/infocollection.cpp @@ -188,3 +188,39 @@ CSMWorld::InfoCollection::Range CSMWorld::InfoCollection::getTopicRange (const s return Range (begin, end); } + +void CSMWorld::InfoCollection::removeDialogueInfos(const std::string& dialogueId) +{ + std::string id = Misc::StringUtils::lowerCase(dialogueId); + std::vector erasedRecords; + + std::map::const_iterator current = getIdMap().lower_bound(id); + std::map::const_iterator end = getIdMap().end(); + for (; current != end; ++current) + { + Record record = getRecord(current->second); + + if (Misc::StringUtils::ciEqual(dialogueId, record.get().mTopicId)) + { + if (record.mState == RecordBase::State_ModifiedOnly) + { + erasedRecords.push_back(current->second); + } + else + { + record.mState = RecordBase::State_Deleted; + setRecord(current->second, record); + } + } + else + { + break; + } + } + + while (!erasedRecords.empty()) + { + removeRows(erasedRecords.back(), 1); + erasedRecords.pop_back(); + } +} diff --git a/apps/opencs/model/world/infocollection.hpp b/apps/opencs/model/world/infocollection.hpp index 6db47373d..e5a5575c7 100644 --- a/apps/opencs/model/world/infocollection.hpp +++ b/apps/opencs/model/world/infocollection.hpp @@ -44,6 +44,8 @@ namespace CSMWorld Range getTopicRange (const std::string& topic) const; ///< Return iterators that point to the beginning and past the end of the range for /// the given topic. + + void removeDialogueInfos(const std::string& dialogueId); }; } From 8e6a7be6f543a112c6aa3e814f572a9d2839ab15 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 19 Jul 2015 11:42:05 +0300 Subject: [PATCH 35/49] Implement saving of deleted records --- apps/opencs/model/doc/savingstages.cpp | 176 ++++++++++--------------- apps/opencs/model/doc/savingstages.hpp | 26 ++-- apps/opencs/model/world/collection.hpp | 6 + apps/opencs/model/world/record.cpp | 24 ++++ apps/opencs/model/world/record.hpp | 16 +++ 5 files changed, 125 insertions(+), 123 deletions(-) diff --git a/apps/opencs/model/doc/savingstages.cpp b/apps/opencs/model/doc/savingstages.cpp index f78c57ecd..dbfa4651b 100644 --- a/apps/opencs/model/doc/savingstages.cpp +++ b/apps/opencs/model/doc/savingstages.cpp @@ -100,84 +100,72 @@ int CSMDoc::WriteDialogueCollectionStage::setup() void CSMDoc::WriteDialogueCollectionStage::perform (int stage, Messages& messages) { + ESM::ESMWriter& writer = mState.getWriter(); const CSMWorld::Record& topic = mTopics.getRecord (stage); - CSMWorld::RecordBase::State state = topic.mState; - - if (state==CSMWorld::RecordBase::State_Deleted) + if (topic.mState == CSMWorld::RecordBase::State_Deleted) { // if the topic is deleted, we do not need to bother with INFO records. + ESM::Dialogue dialogue = topic.get(); + dialogue.mIsDeleted = true; - /// \todo wrote record with delete flag - + writer.startRecord(dialogue.sRecordId); + dialogue.save(writer); + writer.endRecord(dialogue.sRecordId); return; } // Test, if we need to save anything associated info records. bool infoModified = false; - CSMWorld::InfoCollection::Range range = mInfos.getTopicRange (topic.get().mId); for (CSMWorld::InfoCollection::RecordConstIterator iter (range.first); iter!=range.second; ++iter) { - CSMWorld::RecordBase::State state = iter->mState; - - if (state==CSMWorld::RecordBase::State_Modified || - state==CSMWorld::RecordBase::State_ModifiedOnly || - state==CSMWorld::RecordBase::State_Deleted) + if (topic.isModified() || iter->mState == CSMWorld::RecordBase::State_Deleted) { infoModified = true; break; } } - if (state==CSMWorld::RecordBase::State_Modified || - state==CSMWorld::RecordBase::State_ModifiedOnly || - infoModified) + if (topic.isModified() || infoModified) { - mState.getWriter().startRecord (topic.mModified.sRecordId); - mState.getWriter().writeHNCString ("NAME", topic.mModified.mId); - topic.mModified.save (mState.getWriter()); - mState.getWriter().endRecord (topic.mModified.sRecordId); + ESM::Dialogue dialogue = topic.get(); + + writer.startRecord (dialogue.sRecordId); + dialogue.save (writer); + writer.endRecord (dialogue.sRecordId); // write modified selected info records - for (CSMWorld::InfoCollection::RecordConstIterator iter (range.first); iter!=range.second; - ++iter) + for (CSMWorld::InfoCollection::RecordConstIterator iter (range.first); iter!=range.second; ++iter) { - CSMWorld::RecordBase::State state = iter->mState; - - if (state==CSMWorld::RecordBase::State_Deleted) - { - /// \todo wrote record with delete flag - } - else if (state==CSMWorld::RecordBase::State_Modified || - state==CSMWorld::RecordBase::State_ModifiedOnly) + if (iter->isModified() || iter->mState == CSMWorld::RecordBase::State_Deleted) { ESM::DialInfo info = iter->get(); info.mId = info.mId.substr (info.mId.find_last_of ('#')+1); + info.mIsDeleted = (iter->mState == CSMWorld::RecordBase::State_Deleted); + info.mPrev = ""; if (iter!=range.first) { CSMWorld::InfoCollection::RecordConstIterator prev = iter; --prev; - info.mPrev = - prev->mModified.mId.substr (prev->mModified.mId.find_last_of ('#')+1); + info.mPrev = prev->get().mId.substr (prev->get().mId.find_last_of ('#')+1); } CSMWorld::InfoCollection::RecordConstIterator next = iter; ++next; + info.mNext = ""; if (next!=range.second) { - info.mNext = - next->mModified.mId.substr (next->mModified.mId.find_last_of ('#')+1); + info.mNext = next->get().mId.substr (next->get().mId.find_last_of ('#')+1); } - mState.getWriter().startRecord (info.sRecordId); - mState.getWriter().writeHNCString ("INAM", info.mId); - info.save (mState.getWriter()); - mState.getWriter().endRecord (info.sRecordId); + writer.startRecord (info.sRecordId); + info.save (writer); + writer.endRecord (info.sRecordId); } } } @@ -269,36 +257,35 @@ int CSMDoc::WriteCellCollectionStage::setup() void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages) { - const CSMWorld::Record& cell = - mDocument.getData().getCells().getRecord (stage); + ESM::ESMWriter& writer = mState.getWriter(); + const CSMWorld::Record& cell = mDocument.getData().getCells().getRecord (stage); std::map >::const_iterator references = mState.getSubRecords().find (Misc::StringUtils::lowerCase (cell.get().mId)); - if (cell.mState==CSMWorld::RecordBase::State_Modified || - cell.mState==CSMWorld::RecordBase::State_ModifiedOnly || + if (cell.isModified() || + cell.mState == CSMWorld::RecordBase::State_Deleted || references!=mState.getSubRecords().end()) { - bool interior = cell.get().mId.substr (0, 1)!="#"; + CSMWorld::Cell cellRecord = cell.get(); + bool interior = cellRecord.mId.substr (0, 1)!="#"; // write cell data - mState.getWriter().startRecord (cell.mModified.sRecordId); - - mState.getWriter().writeHNOCString ("NAME", cell.get().mName); - - ESM::Cell cell2 = cell.get(); + writer.startRecord (cellRecord.sRecordId); if (interior) - cell2.mData.mFlags |= ESM::Cell::Interior; + cellRecord.mData.mFlags |= ESM::Cell::Interior; else { - cell2.mData.mFlags &= ~ESM::Cell::Interior; + cellRecord.mData.mFlags &= ~ESM::Cell::Interior; - std::istringstream stream (cell.get().mId.c_str()); + std::istringstream stream (cellRecord.mId.c_str()); char ignore; - stream >> ignore >> cell2.mData.mX >> cell2.mData.mY; + stream >> ignore >> cellRecord.mData.mX >> cellRecord.mData.mY; } - cell2.save (mState.getWriter()); + + cellRecord.mIsDeleted = (cell.mState == CSMWorld::RecordBase::State_Deleted); + cellRecord.save (writer); // write references if (references!=mState.getSubRecords().end()) @@ -309,24 +296,25 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages) const CSMWorld::Record& ref = mDocument.getData().getReferences().getRecord (*iter); - if (ref.mState==CSMWorld::RecordBase::State_Modified || - ref.mState==CSMWorld::RecordBase::State_ModifiedOnly) + if (ref.isModified() || ref.mState == CSMWorld::RecordBase::State_Deleted) { + CSMWorld::CellRef refRecord = ref.get(); + // recalculate the ref's cell location std::ostringstream stream; if (!interior) { - std::pair index = ref.get().getCellIndex(); + std::pair index = refRecord.getCellIndex(); stream << "#" << index.first << " " << index.second; } // An empty mOriginalCell is meant to indicate that it is the same as // the current cell. It is possible that a moved ref is moved again. - if ((ref.get().mOriginalCell.empty() ? ref.get().mCell : ref.get().mOriginalCell) + if ((refRecord.mOriginalCell.empty() ? refRecord.mCell : refRecord.mOriginalCell) != stream.str() && !interior) { ESM::MovedCellRef moved; - moved.mRefNum = ref.get().mRefNum; + moved.mRefNum = refRecord.mRefNum; // Need to fill mTarget with the ref's new position. std::istringstream istream (stream.str().c_str()); @@ -334,24 +322,17 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages) char ignore; istream >> ignore >> moved.mTarget[0] >> moved.mTarget[1]; - ref.get().mRefNum.save (mState.getWriter(), false, "MVRF"); - mState.getWriter().writeHNT ("CNDT", moved.mTarget, 8); + refRecord.mRefNum.save (writer, false, "MVRF"); + writer.writeHNT ("CNDT", moved.mTarget, 8); } - ref.get().save (mState.getWriter()); - } - else if (ref.mState==CSMWorld::RecordBase::State_Deleted) - { - /// \todo write record with delete flag + refRecord.mIsDeleted = (ref.mState == CSMWorld::RecordBase::State_Deleted); + refRecord.save (writer); } } } - mState.getWriter().endRecord (cell.mModified.sRecordId); - } - else if (cell.mState==CSMWorld::RecordBase::State_Deleted) - { - /// \todo write record with delete flag + writer.endRecord (cellRecord.sRecordId); } } @@ -368,11 +349,11 @@ int CSMDoc::WritePathgridCollectionStage::setup() void CSMDoc::WritePathgridCollectionStage::perform (int stage, Messages& messages) { - const CSMWorld::Record& pathgrid = + ESM::ESMWriter& writer = mState.getWriter(); + const CSMWorld::Record& pathgrid = mDocument.getData().getPathgrids().getRecord (stage); - if (pathgrid.mState==CSMWorld::RecordBase::State_Modified || - pathgrid.mState==CSMWorld::RecordBase::State_ModifiedOnly) + if (pathgrid.isModified() || pathgrid.mState == CSMWorld::RecordBase::State_Deleted) { CSMWorld::Pathgrid record = pathgrid.get(); @@ -385,15 +366,10 @@ void CSMDoc::WritePathgridCollectionStage::perform (int stage, Messages& message else record.mCell = record.mId; - mState.getWriter().startRecord (record.sRecordId); - - record.save (mState.getWriter()); - - mState.getWriter().endRecord (record.sRecordId); - } - else if (pathgrid.mState==CSMWorld::RecordBase::State_Deleted) - { - /// \todo write record with delete flag + record.mIsDeleted = (pathgrid.mState == CSMWorld::RecordBase::State_Deleted); + writer.startRecord (record.sRecordId); + record.save (writer); + writer.endRecord (record.sRecordId); } } @@ -410,25 +386,18 @@ int CSMDoc::WriteLandCollectionStage::setup() void CSMDoc::WriteLandCollectionStage::perform (int stage, Messages& messages) { - const CSMWorld::Record& land = + ESM::ESMWriter& writer = mState.getWriter(); + const CSMWorld::Record& land = mDocument.getData().getLand().getRecord (stage); - if (land.mState==CSMWorld::RecordBase::State_Modified || - land.mState==CSMWorld::RecordBase::State_ModifiedOnly) + if (land.isModified() || land.mState == CSMWorld::RecordBase::State_Deleted) { CSMWorld::Land record = land.get(); - mState.getWriter().startRecord (record.mLand->sRecordId); - - record.mLand->save (mState.getWriter()); - if(record.mLand->mLandData) - record.mLand->mLandData->save (mState.getWriter()); - - mState.getWriter().endRecord (record.mLand->sRecordId); - } - else if (land.mState==CSMWorld::RecordBase::State_Deleted) - { - /// \todo write record with delete flag + record.mLand->mIsDeleted = (land.mState == CSMWorld::RecordBase::State_Deleted); + writer.startRecord (record.mLand->sRecordId); + record.mLand->save (writer); + writer.endRecord (record.mLand->sRecordId); } } @@ -445,23 +414,18 @@ int CSMDoc::WriteLandTextureCollectionStage::setup() void CSMDoc::WriteLandTextureCollectionStage::perform (int stage, Messages& messages) { - const CSMWorld::Record& landTexture = + ESM::ESMWriter& writer = mState.getWriter(); + const CSMWorld::Record& landTexture = mDocument.getData().getLandTextures().getRecord (stage); - if (landTexture.mState==CSMWorld::RecordBase::State_Modified || - landTexture.mState==CSMWorld::RecordBase::State_ModifiedOnly) + if (landTexture.isModified() || landTexture.mState == CSMWorld::RecordBase::State_Deleted) { CSMWorld::LandTexture record = landTexture.get(); + record.mIsDeleted = (landTexture.mState == CSMWorld::RecordBase::State_Deleted); - mState.getWriter().startRecord (record.sRecordId); - - record.save (mState.getWriter()); - - mState.getWriter().endRecord (record.sRecordId); - } - else if (landTexture.mState==CSMWorld::RecordBase::State_Deleted) - { - /// \todo write record with delete flag + writer.startRecord (record.sRecordId); + record.save (writer); + writer.endRecord (record.sRecordId); } } diff --git a/apps/opencs/model/doc/savingstages.hpp b/apps/opencs/model/doc/savingstages.hpp index 188f22f96..9dbb5bee3 100644 --- a/apps/opencs/model/doc/savingstages.hpp +++ b/apps/opencs/model/doc/savingstages.hpp @@ -100,26 +100,18 @@ namespace CSMDoc if (CSMWorld::getScopeFromId (mCollection.getRecord (stage).get().mId)!=mScope) return; + ESM::ESMWriter& writer = mState.getWriter(); CSMWorld::RecordBase::State state = mCollection.getRecord (stage).mState; + CollectionT::ESXRecord record = mCollection.getRecord (stage).get(); - if (state==CSMWorld::RecordBase::State_Modified || - state==CSMWorld::RecordBase::State_ModifiedOnly) + if (state == CSMWorld::RecordBase::State_Modified || + state == CSMWorld::RecordBase::State_ModifiedOnly || + state == CSMWorld::RecordBase::State_Deleted) { - // FIXME: A quick Workaround to support records which should not write - // NAME, including SKIL, MGEF and SCPT. If there are many more - // idcollection records that doesn't use NAME then a more generic - // solution may be required. - uint32_t name = mCollection.getRecord (stage).mModified.sRecordId; - mState.getWriter().startRecord (name); - - if(name != ESM::REC_SKIL && name != ESM::REC_MGEF && name != ESM::REC_SCPT) - mState.getWriter().writeHNCString ("NAME", mCollection.getId (stage)); - mCollection.getRecord (stage).mModified.save (mState.getWriter()); - mState.getWriter().endRecord (mCollection.getRecord (stage).mModified.sRecordId); - } - else if (state==CSMWorld::RecordBase::State_Deleted) - { - /// \todo write record with delete flag + CSMWorld::setRecordDeleted (record, state == CSMWorld::RecordBase::State_Deleted); + writer.startRecord (record.sRecordId); + record.save (writer); + writer.endRecord (record.sRecordId); } } diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index b0571bbed..16f5ce51f 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -43,6 +43,12 @@ namespace CSMWorld template > class Collection : public CollectionBase { + public: + + typedef ESXRecordT ESXRecord; + + private: + std::vector > mRecords; std::map mIndex; std::vector *> mColumns; diff --git a/apps/opencs/model/world/record.cpp b/apps/opencs/model/world/record.cpp index 87f5090fe..7563c4cfd 100644 --- a/apps/opencs/model/world/record.cpp +++ b/apps/opencs/model/world/record.cpp @@ -43,3 +43,27 @@ bool CSMWorld::isRecordDeleted(const ESM::Skill &skill) { return false; } + +template<> +void CSMWorld::setRecordDeleted(CSMWorld::Land &land, bool isDeleted) +{ + land.mLand->mIsDeleted = isDeleted; +} + +template<> +void CSMWorld::setRecordDeleted(ESM::GameSetting &setting, bool isDeleted) +{ + // GameSetting doesn't have a Deleted flag +} + +template<> +void CSMWorld::setRecordDeleted(ESM::MagicEffect &effect, bool isDeleted) +{ + // MagicEffect doesn't have a Deleted flag +} + +template<> +void CSMWorld::setRecordDeleted(ESM::Skill &skill, bool isDeleted) +{ + // Skill doesn't have a Deleted flag +} diff --git a/apps/opencs/model/world/record.hpp b/apps/opencs/model/world/record.hpp index c43a8b6ca..8e39cd705 100644 --- a/apps/opencs/model/world/record.hpp +++ b/apps/opencs/model/world/record.hpp @@ -177,6 +177,22 @@ namespace CSMWorld bool isRecordDeleted(const ESM::MagicEffect &effect); template<> bool isRecordDeleted(const ESM::Skill &skill); + + // ... and also a separate method for setting the deleted flag of a record + template + void setRecordDeleted(ESXRecordT &record, bool isDeleted = false) + { + record.mIsDeleted = isDeleted; + } + + template<> + void setRecordDeleted(Land &land, bool isDeleted); + template<> + void setRecordDeleted(ESM::GameSetting &setting, bool isDeleted); + template<> + void setRecordDeleted(ESM::MagicEffect &effect, bool isDeleted); + template<> + void setRecordDeleted(ESM::Skill &skill, bool isDeleted); } #endif From ede4bfcf52a77f371058e0fdce655534d6879056 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 19 Jul 2015 14:55:54 +0300 Subject: [PATCH 36/49] Rework EsmTool code. Remove explicit NAME handling --- apps/esmtool/esmtool.cpp | 93 +++++++++++++++++----------------------- apps/esmtool/record.cpp | 75 +++++++++++++++++++++++++++++++- apps/esmtool/record.hpp | 18 +++++--- 3 files changed, 124 insertions(+), 62 deletions(-) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 5b6e50b96..c2507ccdc 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -251,8 +251,7 @@ void loadCell(ESM::Cell &cell, ESM::ESMReader &esm, Arguments& info) ESM::CellRef ref; if(!quiet) std::cout << " References:\n"; - bool deleted = false; - while(cell.getNextRef(esm, ref, deleted)) + while(cell.getNextRef(esm, ref)) { if (save) { info.data.mCellRefs[&cell].push_back(ref); @@ -270,7 +269,7 @@ void loadCell(ESM::Cell &cell, ESM::ESMReader &esm, Arguments& info) std::cout << " Uses/health: '" << ref.mChargeInt << "'\n"; std::cout << " Gold value: '" << ref.mGoldValue << "'\n"; std::cout << " Blocked: '" << static_cast(ref.mReferenceBlocked) << "'" << std::endl; - std::cout << " Deleted: " << deleted << std::endl; + std::cout << " Deleted: " << ref.mIsDeleted << std::endl; if (!ref.mKey.empty()) std::cout << " Key: '" << ref.mKey << "'" << std::endl; } @@ -352,61 +351,58 @@ int load(Arguments& info) uint32_t flags; esm.getRecHeader(flags); + EsmTool::RecordBase *record = EsmTool::RecordBase::create(n); + if (record == 0) + { + if (std::find(skipped.begin(), skipped.end(), n.val) == skipped.end()) + { + std::cout << "Skipping " << n.toString() << " records." << std::endl; + skipped.push_back(n.val); + } + + esm.skipRecord(); + if (quiet) break; + std::cout << " Skipping\n"; + + continue; + } + + record->setFlags(static_cast(flags)); + record->setPrintPlain(info.plain_given); + record->load(esm); + // Is the user interested in this record type? bool interested = true; if (!info.types.empty()) { std::vector::iterator match; - match = std::find(info.types.begin(), info.types.end(), - n.toString()); + match = std::find(info.types.begin(), info.types.end(), n.toString()); if (match == info.types.end()) interested = false; } - std::string id = esm.getHNOString("NAME"); - if (id.empty()) - id = esm.getHNOString("INAM"); - - if (!info.name.empty() && !Misc::StringUtils::ciEqual(info.name, id)) + if (!info.name.empty() && !Misc::StringUtils::ciEqual(info.name, record->getId())) interested = false; if(!quiet && interested) - std::cout << "\nRecord: " << n.toString() - << " '" << id << "'\n"; - - EsmTool::RecordBase *record = EsmTool::RecordBase::create(n); - - if (record == 0) { - if (std::find(skipped.begin(), skipped.end(), n.val) == skipped.end()) - { - std::cout << "Skipping " << n.toString() << " records." << std::endl; - skipped.push_back(n.val); - } + { + std::cout << "\nRecord: " << n.toString() << " '" << record->getId() << "'\n"; + record->print(); + } - esm.skipRecord(); - if (quiet) break; - std::cout << " Skipping\n"; - } else { - if (record->getType().val == ESM::REC_GMST) { - // preset id for GameSetting record - record->cast()->get().mId = id; - } - record->setId(id); - record->setFlags((int) flags); - record->setPrintPlain(info.plain_given); - record->load(esm); - if (!quiet && interested) record->print(); - - if (record->getType().val == ESM::REC_CELL && loadCells && interested) { - loadCell(record->cast()->get(), esm, info); - } + if (record->getType().val == ESM::REC_CELL && loadCells && interested) + { + loadCell(record->cast()->get(), esm, info); + } - if (save) { - info.data.mRecords.push_back(record); - } else { - delete record; - } - ++info.data.mRecordStats[n.val]; + if (save) + { + info.data.mRecords.push_back(record); + } + else + { + delete record; } + ++info.data.mRecordStats[n.val]; } } catch(std::exception &e) { @@ -493,20 +489,11 @@ int clone(Arguments& info) for (Records::iterator it = records.begin(); it != records.end() && i > 0; ++it) { EsmTool::RecordBase *record = *it; - name.val = record->getType().val; esm.startRecord(name.toString(), record->getFlags()); - // TODO wrap this with std::set - if (ESMData::sLabeledRec.count(name.val) > 0) { - esm.writeHNCString("NAME", record->getId()); - } else { - esm.writeHNOString("NAME", record->getId()); - } - record->save(esm); - if (name.val == ESM::REC_CELL) { ESM::Cell *ptr = &record->cast()->get(); if (!info.data.mCellRefs[ptr].empty()) { diff --git a/apps/esmtool/record.cpp b/apps/esmtool/record.cpp index 2ee6c54bb..a03318262 100644 --- a/apps/esmtool/record.cpp +++ b/apps/esmtool/record.cpp @@ -405,6 +405,7 @@ void Record::print() std::cout << " Name: " << mData.mName << std::endl; std::cout << " Model: " << mData.mModel << std::endl; std::cout << " Script: " << mData.mScript << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -419,6 +420,7 @@ void Record::print() std::cout << " Value: " << mData.mData.mValue << std::endl; std::cout << " AutoCalc: " << mData.mData.mAutoCalc << std::endl; printEffectList(mData.mEffects); + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -447,6 +449,7 @@ void Record::print() if (pit->mFemale != "") std::cout << " Female Name: " << pit->mFemale << std::endl; } + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -461,6 +464,7 @@ void Record::print() std::cout << " Weight: " << mData.mData.mWeight << std::endl; std::cout << " Value: " << mData.mData.mValue << std::endl; std::cout << " Quality: " << mData.mData.mQuality << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -474,6 +478,7 @@ void Record::print() std::cout << " Part: " << meshPartLabel(mData.mData.mPart) << " (" << (int)mData.mData.mPart << ")" << std::endl; std::cout << " Vampire: " << (int)mData.mData.mVampire << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -502,6 +507,7 @@ void Record::print() { std::cout << " Text: [skipped]" << std::endl; } + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -513,6 +519,7 @@ void Record::print() std::vector::iterator pit; for (pit = mData.mPowers.mList.begin(); pit != mData.mPowers.mList.end(); ++pit) std::cout << " Power: " << *pit << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -541,6 +548,7 @@ void Record::print() std::cout << " Map Color: " << boost::format("0x%08X") % mData.mMapColor << std::endl; std::cout << " Water Level Int: " << mData.mWaterInt << std::endl; std::cout << " RefId counter: " << mData.mRefNumCounter << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } @@ -563,6 +571,7 @@ void Record::print() for (int i = 0; i != 5; i++) std::cout << " Major Skill: " << skillLabel(mData.mData.mSkills[i][1]) << " (" << mData.mData.mSkills[i][1] << ")" << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -589,6 +598,7 @@ void Record::print() if (pit->mFemale != "") std::cout << " Female Name: " << pit->mFemale << std::endl; } + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -604,6 +614,7 @@ void Record::print() for (cit = mData.mInventory.mList.begin(); cit != mData.mInventory.mList.end(); ++cit) std::cout << " Inventory: Count: " << boost::format("%4d") % cit->mCount << " Item: " << cit->mItem.toString() << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -670,6 +681,7 @@ void Record::print() std::vector::iterator pit; for (pit = mData.mAiPackage.mList.begin(); pit != mData.mAiPackage.mList.end(); ++pit) printAIPackage(*pit); + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -677,6 +689,7 @@ void Record::print() { std::cout << " Type: " << dialogTypeLabel(mData.mType) << " (" << (int)mData.mType << ")" << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; // Sadly, there are no DialInfos, because the loader dumps as it // loads, rather than loading and then dumping. :-( Anyone mind if // I change this? @@ -693,6 +706,7 @@ void Record::print() std::cout << " Script: " << mData.mScript << std::endl; std::cout << " OpenSound: " << mData.mOpenSound << std::endl; std::cout << " CloseSound: " << mData.mCloseSound << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -704,6 +718,7 @@ void Record::print() std::cout << " Charge: " << mData.mData.mCharge << std::endl; std::cout << " AutoCalc: " << mData.mData.mAutocalc << std::endl; printEffectList(mData.mEffects); + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -737,12 +752,14 @@ void Record::print() std::map::iterator rit; for (rit = mData.mReactions.begin(); rit != mData.mReactions.end(); ++rit) std::cout << " Reaction: " << rit->second << " = " << rit->first << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> void Record::print() { std::cout << " " << mData.mValue << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -809,6 +826,7 @@ void Record::print() std::cout << " Result Script: [skipped]" << std::endl; } } + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -832,6 +850,7 @@ void Record::print() std::cout << " Attribute: " << attributeLabel(mData.mData.mAttributes[i]) << " (" << mData.mData.mAttributes[i] << ")" << std::endl; } + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -854,6 +873,7 @@ void Record::print() std::cout << " Unknown2: " << mData.mLandData->mUnk2 << std::endl; } if (!wasLoaded) mData.unloadData(); + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -866,6 +886,7 @@ void Record::print() for (iit = mData.mList.begin(); iit != mData.mList.end(); ++iit) std::cout << " Creature: Level: " << iit->mLevel << " Creature: " << iit->mId << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -878,6 +899,7 @@ void Record::print() for (iit = mData.mList.begin(); iit != mData.mList.end(); ++iit) std::cout << " Inventory: Level: " << iit->mLevel << " Item: " << iit->mId << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -898,6 +920,7 @@ void Record::print() std::cout << " Duration: " << mData.mData.mTime << std::endl; std::cout << " Radius: " << mData.mData.mRadius << std::endl; std::cout << " Color: " << mData.mData.mColor << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -912,6 +935,7 @@ void Record::print() std::cout << " Value: " << mData.mData.mValue << std::endl; std::cout << " Quality: " << mData.mData.mQuality << std::endl; std::cout << " Uses: " << mData.mData.mUses << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -926,6 +950,7 @@ void Record::print() std::cout << " Value: " << mData.mData.mValue << std::endl; std::cout << " Quality: " << mData.mData.mQuality << std::endl; std::cout << " Uses: " << mData.mData.mUses << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -940,6 +965,7 @@ void Record::print() std::cout << " Value: " << mData.mData.mValue << std::endl; std::cout << " Quality: " << mData.mData.mQuality << std::endl; std::cout << " Uses: " << mData.mData.mUses << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -948,6 +974,7 @@ void Record::print() std::cout << " Id: " << mData.mId << std::endl; std::cout << " Index: " << mData.mIndex << std::endl; std::cout << " Texture: " << mData.mTexture << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -998,6 +1025,7 @@ void Record::print() std::cout << " Weight: " << mData.mData.mWeight << std::endl; std::cout << " Value: " << mData.mData.mValue << std::endl; std::cout << " Is Key: " << mData.mData.mIsKey << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -1083,6 +1111,8 @@ void Record::print() std::vector::iterator pit; for (pit = mData.mAiPackage.mList.begin(); pit != mData.mAiPackage.mList.end(); ++pit) printAIPackage(*pit); + + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -1117,6 +1147,8 @@ void Record::print() std::cout << " BAD POINT IN EDGE!" << std::endl; i++; } + + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -1157,6 +1189,8 @@ void Record::print() std::vector::iterator sit; for (sit = mData.mPowers.mList.begin(); sit != mData.mPowers.mList.end(); ++sit) std::cout << " Power: " << *sit << std::endl; + + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -1216,6 +1250,8 @@ void Record::print() { std::cout << " Script: [skipped]" << std::endl; } + + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -1239,6 +1275,7 @@ void Record::print() std::cout << " Sound: " << mData.mSound << std::endl; std::cout << " Type: " << soundTypeLabel(mData.mType) << " (" << mData.mType << ")" << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -1249,6 +1286,7 @@ void Record::print() if (mData.mData.mMinRange != 0 && mData.mData.mMaxRange != 0) std::cout << " Range: " << (int)mData.mData.mMinRange << " - " << (int)mData.mData.mMaxRange << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -1260,13 +1298,15 @@ void Record::print() std::cout << " Flags: " << spellFlags(mData.mData.mFlags) << std::endl; std::cout << " Cost: " << mData.mData.mCost << std::endl; printEffectList(mData.mEffects); + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> void Record::print() { - std::cout << "Start Script: " << mData.mId << std::endl; - std::cout << "Start Data: " << mData.mData << std::endl; + std::cout << " Start Script: " << mData.mId << std::endl; + std::cout << " Start Data: " << mData.mData << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; } template<> @@ -1307,6 +1347,37 @@ void Record::print() if (mData.mData.mThrust[0] != 0 && mData.mData.mThrust[1] != 0) std::cout << " Thrust: " << (int)mData.mData.mThrust[0] << "-" << (int)mData.mData.mThrust[1] << std::endl; + std::cout << " Deleted: " << mData.mIsDeleted << std::endl; +} + +template<> +std::string Record::getId() const +{ + return mData.mName; +} + +template<> +std::string Record::getId() const +{ + return ""; // No ID for Land record +} + +template<> +std::string Record::getId() const +{ + return ""; // No ID for MagicEffect record +} + +template<> +std::string Record::getId() const +{ + return ""; // No ID for Pathgrid record +} + +template<> +std::string Record::getId() const +{ + return ""; // No ID for Skill record } } // end namespace diff --git a/apps/esmtool/record.hpp b/apps/esmtool/record.hpp index c1b90ac2b..a10fda40b 100644 --- a/apps/esmtool/record.hpp +++ b/apps/esmtool/record.hpp @@ -32,13 +32,7 @@ namespace EsmTool virtual ~RecordBase() {} - const std::string &getId() const { - return mId; - } - - void setId(const std::string &id) { - mId = id; - } + virtual std::string getId() const = 0; uint32_t getFlags() const { return mFlags; @@ -75,6 +69,10 @@ namespace EsmTool T mData; public: + std::string getId() const { + return mData.mId; + } + T &get() { return mData; } @@ -89,6 +87,12 @@ namespace EsmTool void print(); }; + + template<> std::string Record::getId() const; + template<> std::string Record::getId() const; + template<> std::string Record::getId() const; + template<> std::string Record::getId() const; + template<> std::string Record::getId() const; template<> void Record::print(); template<> void Record::print(); From 6b21da7f8e6b50de71047248c36d4ee9ec51751e Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 19 Jul 2015 16:07:56 +0300 Subject: [PATCH 37/49] Rework ESS importer code. Remove explicit NAME handling for ESM records --- apps/essimporter/converter.cpp | 6 ++---- apps/essimporter/converter.hpp | 36 +++++++++++++--------------------- apps/essimporter/importer.cpp | 2 +- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/apps/essimporter/converter.cpp b/apps/essimporter/converter.cpp index 2ef10ee34..982753134 100644 --- a/apps/essimporter/converter.cpp +++ b/apps/essimporter/converter.cpp @@ -158,8 +158,6 @@ namespace ESSImport void ConvertCell::read(ESM::ESMReader &esm) { ESM::Cell cell; - std::string id = esm.getHNString("NAME"); - cell.mName = id; cell.load(esm, false); // I wonder what 0x40 does? @@ -169,7 +167,7 @@ namespace ESSImport } // note if the player is in a nameless exterior cell, we will assign the cellId later based on player position - if (id == mContext->mPlayerCellName) + if (cell.mName == mContext->mPlayerCellName) { mContext->mPlayer.mCellId = cell.getCellId(); } @@ -277,7 +275,7 @@ namespace ESSImport if (cell.isExterior()) mExtCells[std::make_pair(cell.mData.mX, cell.mData.mY)] = newcell; else - mIntCells[id] = newcell; + mIntCells[cell.mName] = newcell; } void ConvertCell::writeCell(const Cell &cell, ESM::ESMWriter& esm) diff --git a/apps/essimporter/converter.hpp b/apps/essimporter/converter.hpp index fb8fb8c9f..3bb5d2eae 100644 --- a/apps/essimporter/converter.hpp +++ b/apps/essimporter/converter.hpp @@ -78,10 +78,9 @@ public: virtual void read(ESM::ESMReader& esm) { - std::string id = esm.getHNString("NAME"); T record; record.load(esm); - mRecords[id] = record; + mRecords[record.mId] = record; } virtual void write(ESM::ESMWriter& esm) @@ -89,7 +88,6 @@ public: for (typename std::map::const_iterator it = mRecords.begin(); it != mRecords.end(); ++it) { esm.startRecord(T::sRecordId); - esm.writeHNString("NAME", it->first); it->second.save(esm); esm.endRecord(T::sRecordId); } @@ -105,14 +103,13 @@ public: virtual void read(ESM::ESMReader &esm) { ESM::NPC npc; - std::string id = esm.getHNString("NAME"); npc.load(esm); - if (id != "player") + if (npc.mId != "player") { // Handles changes to the NPC struct, but since there is no index here // it will apply to ALL instances of the class. seems to be the reason for the // "feature" in MW where changing AI settings of one guard will change it for all guards of that refID. - mContext->mNpcs[Misc::StringUtils::lowerCase(id)] = npc; + mContext->mNpcs[Misc::StringUtils::lowerCase(npc.mId)] = npc; } else { @@ -142,9 +139,8 @@ public: { // See comment in ConvertNPC ESM::Creature creature; - std::string id = esm.getHNString("NAME"); creature.load(esm); - mContext->mCreatures[Misc::StringUtils::lowerCase(id)] = creature; + mContext->mCreatures[Misc::StringUtils::lowerCase(creature.mId)] = creature; } }; @@ -157,18 +153,17 @@ class ConvertGlobal : public DefaultConverter public: virtual void read(ESM::ESMReader &esm) { - std::string id = esm.getHNString("NAME"); ESM::Global global; global.load(esm); - if (Misc::StringUtils::ciEqual(id, "gamehour")) + if (Misc::StringUtils::ciEqual(global.mId, "gamehour")) mContext->mHour = global.mValue.getFloat(); - if (Misc::StringUtils::ciEqual(id, "day")) + if (Misc::StringUtils::ciEqual(global.mId, "day")) mContext->mDay = global.mValue.getInteger(); - if (Misc::StringUtils::ciEqual(id, "month")) + if (Misc::StringUtils::ciEqual(global.mId, "month")) mContext->mMonth = global.mValue.getInteger(); - if (Misc::StringUtils::ciEqual(id, "year")) + if (Misc::StringUtils::ciEqual(global.mId, "year")) mContext->mYear = global.mValue.getInteger(); - mRecords[id] = global; + mRecords[global.mId] = global; } }; @@ -177,14 +172,13 @@ class ConvertClass : public DefaultConverter public: virtual void read(ESM::ESMReader &esm) { - std::string id = esm.getHNString("NAME"); ESM::Class class_; class_.load(esm); - if (id == "NEWCLASSID_CHARGEN") + if (class_.mId == "NEWCLASSID_CHARGEN") mContext->mCustomPlayerClassName = class_.mName; - mRecords[id] = class_; + mRecords[class_.mId] = class_; } }; @@ -193,13 +187,12 @@ class ConvertBook : public DefaultConverter public: virtual void read(ESM::ESMReader &esm) { - std::string id = esm.getHNString("NAME"); ESM::Book book; book.load(esm); if (book.mData.mSkillID == -1) - mContext->mPlayer.mObject.mNpcStats.mUsedIds.push_back(Misc::StringUtils::lowerCase(id)); + mContext->mPlayer.mObject.mNpcStats.mUsedIds.push_back(Misc::StringUtils::lowerCase(book.mId)); - mRecords[id] = book; + mRecords[book.mId] = book; } }; @@ -371,11 +364,10 @@ class ConvertFACT : public Converter public: virtual void read(ESM::ESMReader& esm) { - std::string id = esm.getHNString("NAME"); ESM::Faction faction; faction.load(esm); + std::string id = Misc::StringUtils::toLower(faction.mId); - Misc::StringUtils::toLower(id); for (std::map::const_iterator it = faction.mReactions.begin(); it != faction.mReactions.end(); ++it) { std::string faction2 = Misc::StringUtils::lowerCase(it->first); diff --git a/apps/essimporter/importer.cpp b/apps/essimporter/importer.cpp index 624241039..4fbf06217 100644 --- a/apps/essimporter/importer.cpp +++ b/apps/essimporter/importer.cpp @@ -394,7 +394,7 @@ namespace ESSImport } writer.startRecord(ESM::REC_NPC_); - writer.writeHNString("NAME", "player"); + context.mPlayerBase.mId = "player"; context.mPlayerBase.save(writer); writer.endRecord(ESM::REC_NPC_); From f5745749a6e7875c487ac417dead00446af805c2 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 19 Jul 2015 22:50:42 +0300 Subject: [PATCH 38/49] Remove include file from loaddial.cpp --- components/esm/loaddial.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/esm/loaddial.cpp b/components/esm/loaddial.cpp index c517dc722..74a708805 100644 --- a/components/esm/loaddial.cpp +++ b/components/esm/loaddial.cpp @@ -2,8 +2,6 @@ #include -#include - #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" From 1e8182220ae7c14de13ab634c82f2b14444c0e69 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 19 Jul 2015 23:27:51 +0300 Subject: [PATCH 39/49] Fix build errors & warnings --- apps/opencs/model/doc/savingstages.hpp | 2 +- apps/opencs/model/world/idcollection.hpp | 8 ++++---- components/esm/cellref.cpp | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/opencs/model/doc/savingstages.hpp b/apps/opencs/model/doc/savingstages.hpp index 9dbb5bee3..a7d9704b0 100644 --- a/apps/opencs/model/doc/savingstages.hpp +++ b/apps/opencs/model/doc/savingstages.hpp @@ -102,7 +102,7 @@ namespace CSMDoc ESM::ESMWriter& writer = mState.getWriter(); CSMWorld::RecordBase::State state = mCollection.getRecord (stage).mState; - CollectionT::ESXRecord record = mCollection.getRecord (stage).get(); + typename CollectionT::ESXRecord record = mCollection.getRecord (stage).get(); if (state == CSMWorld::RecordBase::State_Modified || state == CSMWorld::RecordBase::State_ModifiedOnly || diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 4acfdc474..9d3ec990e 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -46,7 +46,7 @@ namespace CSMWorld loadRecord (record, reader); std::string id = IdAccessorT().getId (record); - int index = searchId (id); + int index = this->searchId (id); if (isRecordDeleted(record)) { @@ -60,13 +60,13 @@ namespace CSMWorld if (base) { - removeRows (index, 1); + this->removeRows (index, 1); return -1; } - Record baseRecord = getRecord (index); + Record baseRecord = this->getRecord (index); baseRecord.mState = RecordBase::State_Deleted; - setRecord (index, baseRecord); + this->setRecord (index, baseRecord); return index; } diff --git a/components/esm/cellref.cpp b/components/esm/cellref.cpp index c6fb899b3..bcf3de807 100644 --- a/components/esm/cellref.cpp +++ b/components/esm/cellref.cpp @@ -7,10 +7,12 @@ ESM::CellRef::CellRef() : mScale(1.0f), mFactionRank(-2), - mEnchantmentCharge(-1), - mGoldValue(1), mChargeInt(-1), + mEnchantmentCharge(-1.0f), + mGoldValue(1), + mTeleport(false), mLockLevel(0), + mReferenceBlocked(-1), mIsDeleted(false) {} From 4a16eba716d6795bb9aadc492c4417d1a05828ef Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Mon, 20 Jul 2015 17:23:14 +0300 Subject: [PATCH 40/49] Make deleted flag a parameter of load/save methods (instead of a record member) in ESM records --- components/esm/cellref.cpp | 93 +++++++++------------- components/esm/cellref.hpp | 12 ++- components/esm/debugprofile.cpp | 24 +++--- components/esm/debugprofile.hpp | 8 +- components/esm/esmreader.cpp | 1 + components/esm/filter.cpp | 21 ++--- components/esm/filter.hpp | 8 +- components/esm/loadacti.cpp | 24 +++--- components/esm/loadacti.hpp | 8 +- components/esm/loadalch.cpp | 27 +++---- components/esm/loadalch.hpp | 8 +- components/esm/loadappa.cpp | 26 +++--- components/esm/loadappa.hpp | 8 +- components/esm/loadarmo.cpp | 27 +++---- components/esm/loadarmo.hpp | 8 +- components/esm/loadbody.cpp | 27 +++---- components/esm/loadbody.hpp | 8 +- components/esm/loadbook.cpp | 26 +++--- components/esm/loadbook.hpp | 8 +- components/esm/loadbsgn.cpp | 25 +++--- components/esm/loadbsgn.hpp | 8 +- components/esm/loadcell.cpp | 136 +++++++++++++++++++------------- components/esm/loadcell.hpp | 20 ++--- components/esm/loadclas.cpp | 27 +++---- components/esm/loadclas.hpp | 8 +- components/esm/loadclot.cpp | 27 +++---- components/esm/loadclot.hpp | 8 +- components/esm/loadcont.cpp | 31 +++----- components/esm/loadcont.hpp | 8 +- components/esm/loadcrea.cpp | 31 +++----- components/esm/loadcrea.hpp | 8 +- components/esm/loaddial.cpp | 64 +++++++-------- components/esm/loaddial.hpp | 16 ++-- components/esm/loaddoor.cpp | 24 +++--- components/esm/loaddoor.hpp | 8 +- components/esm/loadench.cpp | 27 +++---- components/esm/loadench.hpp | 8 +- components/esm/loadfact.cpp | 28 +++---- components/esm/loadfact.hpp | 8 +- components/esm/loadglob.cpp | 16 ++-- components/esm/loadglob.hpp | 8 +- components/esm/loadgmst.cpp | 6 +- components/esm/loadgmst.hpp | 4 +- components/esm/loadinfo.cpp | 32 +++----- components/esm/loadinfo.hpp | 10 +-- components/esm/loadingr.cpp | 27 +++---- components/esm/loadingr.hpp | 8 +- components/esm/loadland.cpp | 109 ++++++++++++++----------- components/esm/loadland.hpp | 8 +- components/esm/loadlevlist.cpp | 41 ++++++---- components/esm/loadlevlist.hpp | 8 +- components/esm/loadligh.cpp | 26 +++--- components/esm/loadligh.hpp | 8 +- components/esm/loadlock.cpp | 26 +++--- components/esm/loadlock.hpp | 8 +- components/esm/loadltex.cpp | 24 +++--- components/esm/loadltex.hpp | 8 +- components/esm/loadmgef.cpp | 9 ++- components/esm/loadmgef.hpp | 4 +- components/esm/loadmisc.cpp | 26 +++--- components/esm/loadmisc.hpp | 8 +- components/esm/loadnpc.cpp | 31 +++----- components/esm/loadnpc.hpp | 8 +- components/esm/loadpgrd.cpp | 18 ++--- components/esm/loadpgrd.hpp | 8 +- components/esm/loadprob.cpp | 26 +++--- components/esm/loadprob.hpp | 8 +- components/esm/loadrace.cpp | 26 +++--- components/esm/loadrace.hpp | 8 +- components/esm/loadregn.cpp | 24 ++---- components/esm/loadregn.hpp | 8 +- components/esm/loadrepa.cpp | 26 +++--- components/esm/loadrepa.hpp | 8 +- components/esm/loadscpt.cpp | 26 +++--- components/esm/loadscpt.hpp | 8 +- components/esm/loadskil.cpp | 9 ++- components/esm/loadskil.hpp | 4 +- components/esm/loadsndg.cpp | 27 +++---- components/esm/loadsndg.hpp | 8 +- components/esm/loadsoun.cpp | 27 +++---- components/esm/loadsoun.hpp | 8 +- components/esm/loadspel.cpp | 28 +++---- components/esm/loadspel.hpp | 8 +- components/esm/loadsscr.cpp | 18 ++--- components/esm/loadsscr.hpp | 8 +- components/esm/loadstat.cpp | 24 +++--- components/esm/loadstat.hpp | 8 +- components/esm/loadweap.cpp | 27 +++---- components/esm/loadweap.hpp | 8 +- components/esm/objectstate.cpp | 3 +- 90 files changed, 714 insertions(+), 1050 deletions(-) diff --git a/components/esm/cellref.cpp b/components/esm/cellref.cpp index bcf3de807..9a0c8f1cc 100644 --- a/components/esm/cellref.cpp +++ b/components/esm/cellref.cpp @@ -4,18 +4,6 @@ #include "esmreader.hpp" #include "esmwriter.hpp" -ESM::CellRef::CellRef() - : mScale(1.0f), - mFactionRank(-2), - mChargeInt(-1), - mEnchantmentCharge(-1.0f), - mGoldValue(1), - mTeleport(false), - mLockLevel(0), - mReferenceBlocked(-1), - mIsDeleted(false) -{} - void ESM::RefNum::load (ESMReader& esm, bool wide) { if (wide) @@ -37,10 +25,37 @@ void ESM::RefNum::save (ESMWriter &esm, bool wide, const std::string& tag) const } -void ESM::CellRef::load (ESMReader& esm, bool wideRefNum) +void ESM::CellRef::clearData() +{ + mScale = 1; + mOwner.clear(); + mGlobalVariable.clear(); + mSoul.clear(); + mFaction.clear(); + mFactionRank = -2; + mChargeInt = -1; + mEnchantmentCharge = -1; + mGoldValue = 0; + mDestCell.clear(); + mLockLevel = 0; + mKey.clear(); + mTrap.clear(); + mReferenceBlocked = -1; + mTeleport = false; + + for (int i=0; i<3; ++i) + { + mDoorDest.pos[i] = 0; + mDoorDest.rot[i] = 0; + mPos.pos[i] = 0; + mPos.rot[i] = 0; + } +} + +void ESM::CellRef::load (ESMReader& esm, bool &isDeleted, bool wideRefNum) { loadId(esm, wideRefNum); - loadData(esm); + loadData(esm, isDeleted); } void ESM::CellRef::loadId (ESMReader& esm, bool wideRefNum) @@ -55,27 +70,19 @@ void ESM::CellRef::loadId (ESMReader& esm, bool wideRefNum) mRefNum.load (esm, wideRefNum); mRefID = esm.getHNString ("NAME"); - mIsDeleted = false; } -void ESM::CellRef::loadData(ESMReader &esm) +void ESM::CellRef::loadData(ESMReader &esm, bool &isDeleted) { - mScale = 1.0f; - mFactionRank = -2; - mChargeInt = -1; - mEnchantmentCharge = -1; - mGoldValue = 1; - mLockLevel = 0; - mReferenceBlocked = -1; - mTeleport = false; - mIsDeleted = false; + isDeleted = false; + + clearData(); bool isLoaded = false; while (!isLoaded && esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'U','N','A','M'>::value: esm.getHT(mReferenceBlocked); @@ -131,7 +138,7 @@ void ESM::CellRef::loadData(ESMReader &esm) break; case ESM::FourCC<'D','E','L','E'>::value: esm.skipHSub(); - mIsDeleted = true; + isDeleted = true; break; default: esm.cacheSubName(); @@ -141,7 +148,7 @@ void ESM::CellRef::loadData(ESMReader &esm) } } -void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory) const +void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory, bool isDeleted) const { mRefNum.save (esm, wideRefNum); @@ -192,7 +199,7 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory) cons if (!inInventory) esm.writeHNT("DATA", mPos, 24); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); } @@ -202,31 +209,7 @@ void ESM::CellRef::blank() { mRefNum.unset(); mRefID.clear(); - mScale = 1; - mOwner.clear(); - mGlobalVariable.clear(); - mSoul.clear(); - mFaction.clear(); - mFactionRank = -2; - mChargeInt = -1; - mEnchantmentCharge = -1; - mGoldValue = 0; - mDestCell.clear(); - mLockLevel = 0; - mKey.clear(); - mTrap.clear(); - mReferenceBlocked = -1; - mTeleport = false; - - for (int i=0; i<3; ++i) - { - mDoorDest.pos[i] = 0; - mDoorDest.rot[i] = 0; - mPos.pos[i] = 0; - mPos.rot[i] = 0; - } - - mIsDeleted = false; + clearData(); } bool ESM::operator== (const RefNum& left, const RefNum& right) diff --git a/components/esm/cellref.hpp b/components/esm/cellref.hpp index 553dbaae3..a9edd291e 100644 --- a/components/esm/cellref.hpp +++ b/components/esm/cellref.hpp @@ -33,6 +33,8 @@ namespace ESM class CellRef { + void clearData(); + public: // Reference number @@ -99,19 +101,15 @@ namespace ESM // Position and rotation of this object within the cell Position mPos; - bool mIsDeleted; - - CellRef(); - /// Calls loadId and loadData - void load (ESMReader& esm, bool wideRefNum = false); + void load (ESMReader& esm, bool &isDeleted, bool wideRefNum = false); void loadId (ESMReader& esm, bool wideRefNum = false); /// Implicitly called by load - void loadData (ESMReader& esm); + void loadData (ESMReader& esm, bool &isDeleted); - void save (ESMWriter &esm, bool wideRefNum = false, bool inInventory = false) const; + void save (ESMWriter &esm, bool wideRefNum = false, bool inInventory = false, bool isDeleted = false) const; void blank(); }; diff --git a/components/esm/debugprofile.cpp b/components/esm/debugprofile.cpp index d1e27debc..16fc90eec 100644 --- a/components/esm/debugprofile.cpp +++ b/components/esm/debugprofile.cpp @@ -7,27 +7,18 @@ unsigned int ESM::DebugProfile::sRecordId = REC_DBGP; -ESM::DebugProfile::DebugProfile() - : mIsDeleted(false) -{} - -void ESM::DebugProfile::load (ESMReader& esm) +void ESM::DebugProfile::load (ESMReader& esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'D','E','S','C'>::value: mDescription = esm.getHString(); break; @@ -37,6 +28,10 @@ void ESM::DebugProfile::load (ESMReader& esm) case ESM::FourCC<'F','L','A','G'>::value: esm.getHT(mFlags); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -44,11 +39,11 @@ void ESM::DebugProfile::load (ESMReader& esm) } } -void ESM::DebugProfile::save (ESMWriter& esm) const +void ESM::DebugProfile::save (ESMWriter& esm, bool isDeleted) const { esm.writeHNCString ("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -64,5 +59,4 @@ void ESM::DebugProfile::blank() mDescription.clear(); mScriptText.clear(); mFlags = 0; - mIsDeleted = false; } diff --git a/components/esm/debugprofile.hpp b/components/esm/debugprofile.hpp index 1709136f5..c056750a8 100644 --- a/components/esm/debugprofile.hpp +++ b/components/esm/debugprofile.hpp @@ -27,12 +27,8 @@ namespace ESM unsigned int mFlags; - bool mIsDeleted; - - DebugProfile(); - - void load (ESMReader& esm); - void save (ESMWriter& esm) const; + void load (ESMReader& esm, bool &isDeleted); + void save (ESMWriter& esm, bool isDeleted = false) const; /// Set record to default state (does not touch the ID). void blank(); diff --git a/components/esm/esmreader.cpp b/components/esm/esmreader.cpp index 1bf176842..6ef14a70e 100644 --- a/components/esm/esmreader.cpp +++ b/components/esm/esmreader.cpp @@ -281,6 +281,7 @@ void ESMReader::skipRecord() { skip(mCtx.leftRec); mCtx.leftRec = 0; + mCtx.subCached = false; } void ESMReader::getRecHeader(uint32_t &flags) diff --git a/components/esm/filter.cpp b/components/esm/filter.cpp index 57cb59454..b485169f2 100644 --- a/components/esm/filter.cpp +++ b/components/esm/filter.cpp @@ -7,13 +7,9 @@ unsigned int ESM::Filter::sRecordId = REC_FILT; -ESM::Filter::Filter() - : mIsDeleted(false) -{} - -void ESM::Filter::load (ESMReader& esm) +void ESM::Filter::load (ESMReader& esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; while (esm.hasMoreSubs()) { @@ -24,16 +20,16 @@ void ESM::Filter::load (ESMReader& esm) case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'F','I','L','T'>::value: mFilter = esm.getHString(); break; case ESM::FourCC<'D','E','S','C'>::value: mDescription = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -41,11 +37,11 @@ void ESM::Filter::load (ESMReader& esm) } } -void ESM::Filter::save (ESMWriter& esm) const +void ESM::Filter::save (ESMWriter& esm, bool isDeleted) const { esm.writeHNCString ("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -59,5 +55,4 @@ void ESM::Filter::blank() { mFilter.clear(); mDescription.clear(); - mIsDeleted = false; } diff --git a/components/esm/filter.hpp b/components/esm/filter.hpp index 1a8af9229..b1c511ebb 100644 --- a/components/esm/filter.hpp +++ b/components/esm/filter.hpp @@ -18,12 +18,8 @@ namespace ESM std::string mFilter; - bool mIsDeleted; - - Filter(); - - void load (ESMReader& esm); - void save (ESMWriter& esm) const; + void load (ESMReader& esm, bool &isDeleted); + void save (ESMWriter& esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadacti.cpp b/components/esm/loadacti.cpp index c32cea1a6..14db45c34 100644 --- a/components/esm/loadacti.cpp +++ b/components/esm/loadacti.cpp @@ -8,29 +8,20 @@ namespace ESM { unsigned int Activator::sRecordId = REC_ACTI; - Activator::Activator() - : mIsDeleted(false) - {} - - void Activator::load(ESMReader &esm) + void Activator::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -40,6 +31,10 @@ namespace ESM case ESM::FourCC<'S','C','R','I'>::value: mScript = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -49,11 +44,11 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); } - void Activator::save(ESMWriter &esm) const + void Activator::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -69,6 +64,5 @@ namespace ESM mName.clear(); mScript.clear(); mModel.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadacti.hpp b/components/esm/loadacti.hpp index 93de07b25..4cc72d528 100644 --- a/components/esm/loadacti.hpp +++ b/components/esm/loadacti.hpp @@ -17,12 +17,8 @@ struct Activator std::string mId, mName, mScript, mModel; - bool mIsDeleted; - - Activator(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadalch.cpp b/components/esm/loadalch.cpp index c1213583d..ceff4ba7d 100644 --- a/components/esm/loadalch.cpp +++ b/components/esm/loadalch.cpp @@ -8,31 +8,23 @@ namespace ESM { unsigned int Potion::sRecordId = REC_ALCH; - Potion::Potion() - : mIsDeleted(false) - {} - - void Potion::load(ESMReader &esm) + void Potion::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + mEffects.mList.clear(); - mIsDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -52,6 +44,10 @@ namespace ESM case ESM::FourCC<'E','N','A','M'>::value: mEffects.add(esm); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -60,14 +56,14 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing ALDT subrecord"); } - void Potion::save(ESMWriter &esm) const + void Potion::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -91,6 +87,5 @@ namespace ESM mIcon.clear(); mScript.clear(); mEffects.mList.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadalch.hpp b/components/esm/loadalch.hpp index 921585a9d..9ef390ebd 100644 --- a/components/esm/loadalch.hpp +++ b/components/esm/loadalch.hpp @@ -33,12 +33,8 @@ struct Potion std::string mId, mName, mModel, mIcon, mScript; EffectList mEffects; - bool mIsDeleted; - - Potion(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadappa.cpp b/components/esm/loadappa.cpp index edf1f473b..7a77ba421 100644 --- a/components/esm/loadappa.cpp +++ b/components/esm/loadappa.cpp @@ -8,30 +8,21 @@ namespace ESM { unsigned int Apparatus::sRecordId = REC_APPA; - Apparatus::Apparatus() - : mIsDeleted(false) - {} - - void Apparatus::load(ESMReader &esm) + void Apparatus::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -48,6 +39,10 @@ namespace ESM case ESM::FourCC<'I','T','E','X'>::value: mIcon = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -56,15 +51,15 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing AADT subrecord"); } - void Apparatus::save(ESMWriter &esm) const + void Apparatus::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -87,6 +82,5 @@ namespace ESM mIcon.clear(); mScript.clear(); mName.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadappa.hpp b/components/esm/loadappa.hpp index 2dac37995..0590d33ed 100644 --- a/components/esm/loadappa.hpp +++ b/components/esm/loadappa.hpp @@ -38,12 +38,8 @@ struct Apparatus AADTstruct mData; std::string mId, mModel, mIcon, mScript, mName; - bool mIsDeleted; - - Apparatus(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadarmo.cpp b/components/esm/loadarmo.cpp index d5b9fdd44..600c417be 100644 --- a/components/esm/loadarmo.cpp +++ b/components/esm/loadarmo.cpp @@ -38,31 +38,23 @@ namespace ESM unsigned int Armor::sRecordId = REC_ARMO; - Armor::Armor() - : mIsDeleted(false) - {} - - void Armor::load(ESMReader &esm) + void Armor::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + mParts.mParts.clear(); - mIsDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -85,6 +77,10 @@ namespace ESM case ESM::FourCC<'I','N','D','X'>::value: mParts.add(esm); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -93,15 +89,15 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing CTDT subrecord"); } - void Armor::save(ESMWriter &esm) const + void Armor::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -130,6 +126,5 @@ namespace ESM mIcon.clear(); mScript.clear(); mEnchant.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadarmo.hpp b/components/esm/loadarmo.hpp index 4ebe181a7..ef3bb734c 100644 --- a/components/esm/loadarmo.hpp +++ b/components/esm/loadarmo.hpp @@ -96,12 +96,8 @@ struct Armor std::string mId, mName, mModel, mIcon, mScript, mEnchant; - bool mIsDeleted; - - Armor(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadbody.cpp b/components/esm/loadbody.cpp index e2c6ad7b2..20d6b35cf 100644 --- a/components/esm/loadbody.cpp +++ b/components/esm/loadbody.cpp @@ -8,30 +8,21 @@ namespace ESM { unsigned int BodyPart::sRecordId = REC_BODY; - BodyPart::BodyPart() - : mIsDeleted(false) - {} - - void BodyPart::load(ESMReader &esm) + void BodyPart::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -42,6 +33,10 @@ namespace ESM esm.getHT(mData, 4); hasData = true; break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -50,15 +45,15 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing BYDT subrecord"); } - void BodyPart::save(ESMWriter &esm) const + void BodyPart::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -78,7 +73,5 @@ namespace ESM mModel.clear(); mRace.clear(); - - mIsDeleted = false; } } diff --git a/components/esm/loadbody.hpp b/components/esm/loadbody.hpp index f32d2fb58..bf320330f 100644 --- a/components/esm/loadbody.hpp +++ b/components/esm/loadbody.hpp @@ -60,12 +60,8 @@ struct BodyPart BYDTstruct mData; std::string mId, mModel, mRace; - bool mIsDeleted; - - BodyPart(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadbook.cpp b/components/esm/loadbook.cpp index 2d0d3ce75..b08b12f50 100644 --- a/components/esm/loadbook.cpp +++ b/components/esm/loadbook.cpp @@ -8,30 +8,21 @@ namespace ESM { unsigned int Book::sRecordId = REC_BOOK; - Book::Book() - : mIsDeleted(false) - {} - - void Book::load(ESMReader &esm) + void Book::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -54,6 +45,10 @@ namespace ESM case ESM::FourCC<'T','E','X','T'>::value: mText = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -62,14 +57,14 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing BKDT subrecord"); } - void Book::save(ESMWriter &esm) const + void Book::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -97,6 +92,5 @@ namespace ESM mScript.clear(); mEnchant.clear(); mText.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadbook.hpp b/components/esm/loadbook.hpp index 931f813c0..3d50356ae 100644 --- a/components/esm/loadbook.hpp +++ b/components/esm/loadbook.hpp @@ -28,12 +28,8 @@ struct Book std::string mName, mModel, mIcon, mScript, mEnchant, mText; std::string mId; - bool mIsDeleted; - - Book(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadbsgn.cpp b/components/esm/loadbsgn.cpp index 54de009aa..56dc1897c 100644 --- a/components/esm/loadbsgn.cpp +++ b/components/esm/loadbsgn.cpp @@ -8,30 +8,22 @@ namespace ESM { unsigned int BirthSign::sRecordId = REC_BSGN; - BirthSign::BirthSign() - : mIsDeleted(false) - {} - - void BirthSign::load(ESMReader &esm) + void BirthSign::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + mPowers.mList.clear(); - mIsDeleted = false; bool hasName = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); break; @@ -44,6 +36,10 @@ namespace ESM case ESM::FourCC<'N','P','C','S'>::value: mPowers.add(esm); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -54,9 +50,9 @@ namespace ESM esm.fail("Missing NAME subrecord"); } - void BirthSign::save(ESMWriter &esm) const + void BirthSign::save(ESMWriter &esm, bool isDeleted) const { - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); } @@ -75,7 +71,6 @@ namespace ESM mDescription.clear(); mTexture.clear(); mPowers.mList.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadbsgn.hpp b/components/esm/loadbsgn.hpp index 685ade82f..24d27a7f8 100644 --- a/components/esm/loadbsgn.hpp +++ b/components/esm/loadbsgn.hpp @@ -22,12 +22,8 @@ struct BirthSign // List of powers and abilities that come with this birth sign. SpellList mPowers; - bool mIsDeleted; - - BirthSign(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID/index). diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 7e02f0f85..2d8daa584 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -52,75 +52,98 @@ namespace ESM return ref.mRefNum == refNum; } - void Cell::load(ESMReader &esm, bool saveContext) + void Cell::load(ESMReader &esm, bool &isDeleted, bool saveContext) { - loadName(esm); - loadData(esm); + loadNameAndData(esm, isDeleted); loadCell(esm, saveContext); } - void Cell::loadName(ESMReader &esm) + void Cell::loadNameAndData(ESMReader &esm, bool &isDeleted) { - mName = esm.getHNString("NAME"); + isDeleted = false; - mIsDeleted = false; - if (esm.isNextSub("DELE")) + bool hasName = false; + bool hasData = false; + bool isLoaded = false; + while (!isLoaded && esm.hasMoreSubs()) { - esm.skipHSub(); - mIsDeleted = true; + esm.getSubName(); + switch (esm.retSubName().val) + { + case ESM::FourCC<'N','A','M','E'>::value: + mName = esm.getHString(); + hasName = true; + break; + case ESM::FourCC<'D','A','T','A'>::value: + esm.getHT(mData, 12); + hasData = true; + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; + default: + esm.cacheSubName(); + isLoaded = true; + break; + } } + + if (!hasName) + esm.fail("Missing NAME subrecord"); + if (!hasData) + esm.fail("Missing DATA subrecord"); } void Cell::loadCell(ESMReader &esm, bool saveContext) { + mWater = 0.0f; + mWaterInt = false; + mMapColor = 0; + mRegion.clear(); mRefNumCounter = 0; - if (mData.mFlags & Interior) + bool isLoaded = false; + while (!isLoaded && esm.hasMoreSubs()) { - // Interior cells - if (esm.isNextSub("INTV")) + esm.getSubName(); + switch (esm.retSubName().val) { - int waterl; - esm.getHT(waterl); - mWater = (float) waterl; - mWaterInt = true; + case ESM::FourCC<'I','N','T','V'>::value: + int waterl; + esm.getHT(waterl); + mWater = static_cast(waterl); + mWaterInt = true; + break; + case ESM::FourCC<'W','H','G','T'>::value: + esm.getHT(mWater); + break; + case ESM::FourCC<'A','M','B','I'>::value: + esm.getHT(mAmbi); + break; + case ESM::FourCC<'R','G','N','N'>::value: + mRegion = esm.getHString(); + break; + case ESM::FourCC<'N','A','M','5'>::value: + esm.getHT(mMapColor); + break; + case ESM::FourCC<'N','A','M','0'>::value: + esm.getHT(mRefNumCounter); + break; + default: + esm.cacheSubName(); + isLoaded = true; + break; } - else if (esm.isNextSub("WHGT")) - { - esm.getHT(mWater); - } - - // Quasi-exterior cells have a region (which determines the - // weather), pure interior cells have ambient lighting - // instead. - if (mData.mFlags & QuasiEx) - mRegion = esm.getHNOString("RGNN"); - else if (esm.isNextSub("AMBI")) - esm.getHT(mAmbi); - } - else - { - // Exterior cells - mRegion = esm.getHNOString("RGNN"); - - mMapColor = 0; - esm.getHNOT(mMapColor, "NAM5"); - } - if (esm.isNextSub("NAM0")) { - esm.getHT(mRefNumCounter); } - if (saveContext) { + if (saveContext) + { mContextList.push_back(esm.getContext()); esm.skipRecord(); } } - void Cell::loadData(ESMReader &esm) - { - esm.getHNT(mData, "DATA", 12); - } - void Cell::postLoad(ESMReader &esm) { // Save position of the cell references and move on @@ -128,11 +151,11 @@ namespace ESM esm.skipRecord(); } - void Cell::save(ESMWriter &esm) const + void Cell::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mName); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); } @@ -183,8 +206,10 @@ namespace ESM } } - bool Cell::getNextRef(ESMReader &esm, CellRef &ref, bool ignoreMoves, MovedCellRef *mref) + bool Cell::getNextRef(ESMReader &esm, CellRef &ref, bool &isDeleted, bool ignoreMoves, MovedCellRef *mref) { + isDeleted = false; + // TODO: Try and document reference numbering, I don't think this has been done anywhere else. if (!esm.hasMoreSubs()) return false; @@ -207,12 +232,15 @@ namespace ESM } } - ref.load (esm); - - // Identify references belonging to a parent file and adapt the ID accordingly. - adjustRefNum (ref.mRefNum, esm); + if (esm.peekNextSub("FRMR")) + { + ref.load (esm, isDeleted); - return true; + // Identify references belonging to a parent file and adapt the ID accordingly. + adjustRefNum (ref.mRefNum, esm); + return true; + } + return false; } bool Cell::getNextMVRF(ESMReader &esm, MovedCellRef &mref) @@ -242,8 +270,6 @@ namespace ESM mAmbi.mSunlight = 0; mAmbi.mFog = 0; mAmbi.mFogDensity = 0; - - mIsDeleted = false; } CellId Cell::getCellId() const diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index a1a758e3b..2a7a78a54 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -85,8 +85,7 @@ struct Cell mWater(0), mWaterInt(false), mMapColor(0), - mRefNumCounter(0), - mIsDeleted(false) + mRefNumCounter(0) {} // Interior cells are indexed by this (it's the 'id'), for exterior @@ -113,18 +112,15 @@ struct Cell CellRefTracker mLeasedRefs; MovedCellRefTracker mMovedRefs; - bool mIsDeleted; - void postLoad(ESMReader &esm); // This method is left in for compatibility with esmtool. Parsing moved references currently requires // passing ESMStore, bit it does not know about this parameter, so we do it this way. - void load(ESMReader &esm, bool saveContext = true); // Load everything (except references) - void loadName(ESMReader &esm); // Load NAME and checks for DELE - void loadData(ESMReader &esm); // Load DATAstruct only - void loadCell(ESMReader &esm, bool saveContext = true); // Load everything, except DATAstruct and references + void load(ESMReader &esm, bool &isDeleted, bool saveContext = true); // Load everything (except references) + void loadNameAndData(ESMReader &esm, bool &isDeleted); // Load NAME and DATAstruct + void loadCell(ESMReader &esm, bool saveContext = true); // Load everything, except NAME, DATAstruct and references - void save(ESMWriter &esm) const; + void save(ESMWriter &esm, bool isDeleted = false) const; bool isExterior() const { @@ -163,7 +159,11 @@ struct Cell reuse one memory location without blanking it between calls. */ /// \param ignoreMoves ignore MVRF record and read reference like a regular CellRef. - static bool getNextRef(ESMReader &esm, CellRef &ref, bool ignoreMoves = false, MovedCellRef *mref = 0); + static bool getNextRef(ESMReader &esm, + CellRef &ref, + bool &isDeleted, + bool ignoreMoves = false, + MovedCellRef *mref = 0); /* This fetches an MVRF record, which is used to track moved references. * Since they are comparably rare, we use a separate method for this. diff --git a/components/esm/loadclas.cpp b/components/esm/loadclas.cpp index b58c35d90..2ad14b9f2 100644 --- a/components/esm/loadclas.cpp +++ b/components/esm/loadclas.cpp @@ -22,10 +22,6 @@ namespace ESM "sSpecializationStealth" }; - Class::Class() - : mIsDeleted(false) - {} - int& Class::CLDTstruct::getSkill (int index, bool major) { if (index<0 || index>=5) @@ -42,26 +38,21 @@ namespace ESM return mSkills[index][major ? 1 : 0]; } - void Class::load(ESMReader &esm) + void Class::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); break; @@ -74,6 +65,10 @@ namespace ESM case ESM::FourCC<'D','E','S','C'>::value: mDescription = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -82,14 +77,14 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing CLDT subrecord"); } - void Class::save(ESMWriter &esm) const + void Class::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -113,7 +108,5 @@ namespace ESM for (int i=0; i<5; ++i) for (int i2=0; i2<2; ++i2) mData.mSkills[i][i2] = 0; - - mIsDeleted = false; } } diff --git a/components/esm/loadclas.hpp b/components/esm/loadclas.hpp index 399e93c24..833dd6757 100644 --- a/components/esm/loadclas.hpp +++ b/components/esm/loadclas.hpp @@ -73,12 +73,8 @@ struct Class std::string mId, mName, mDescription; CLDTstruct mData; - bool mIsDeleted; - - Class(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID/index). diff --git a/components/esm/loadclot.cpp b/components/esm/loadclot.cpp index 18f7cd44f..8a88e6d7a 100644 --- a/components/esm/loadclot.cpp +++ b/components/esm/loadclot.cpp @@ -8,31 +8,23 @@ namespace ESM { unsigned int Clothing::sRecordId = REC_CLOT; - Clothing::Clothing() - : mIsDeleted(false) - {} - - void Clothing::load(ESMReader &esm) + void Clothing::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + mParts.mParts.clear(); - mIsDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -55,6 +47,10 @@ namespace ESM case ESM::FourCC<'I','N','D','X'>::value: mParts.add(esm); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -63,15 +59,15 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing CTDT subrecord"); } - void Clothing::save(ESMWriter &esm) const + void Clothing::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -101,6 +97,5 @@ namespace ESM mIcon.clear(); mEnchant.clear(); mScript.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadclot.hpp b/components/esm/loadclot.hpp index 202c1ec45..39e5ea672 100644 --- a/components/esm/loadclot.hpp +++ b/components/esm/loadclot.hpp @@ -48,12 +48,8 @@ struct Clothing std::string mId, mName, mModel, mIcon, mEnchant, mScript; - bool mIsDeleted; - - Clothing(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadcont.cpp b/components/esm/loadcont.cpp index fadfe5f0f..372683750 100644 --- a/components/esm/loadcont.cpp +++ b/components/esm/loadcont.cpp @@ -24,16 +24,11 @@ namespace ESM unsigned int Container::sRecordId = REC_CONT; - Container::Container() - : mWeight(0), - mFlags(0x8), - mIsDeleted(false) - {} - - void Container::load(ESMReader &esm) + void Container::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + mInventory.mList.clear(); - mIsDeleted = false; bool hasName = false; bool hasWeight = false; @@ -41,17 +36,12 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -76,6 +66,10 @@ namespace ESM case ESM::FourCC<'N','P','C','O'>::value: mInventory.add(esm); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -84,17 +78,17 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasWeight && !mIsDeleted) + if (!hasWeight && !isDeleted) esm.fail("Missing CNDT subrecord"); - if (!hasFlags && !mIsDeleted) + if (!hasFlags && !isDeleted) esm.fail("Missing FLAG subrecord"); } - void Container::save(ESMWriter &esm) const + void Container::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -118,6 +112,5 @@ namespace ESM mWeight = 0; mFlags = 0x8; // set default flag value mInventory.mList.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadcont.hpp b/components/esm/loadcont.hpp index 31c7e1815..4c847f4e2 100644 --- a/components/esm/loadcont.hpp +++ b/components/esm/loadcont.hpp @@ -52,12 +52,8 @@ struct Container int mFlags; InventoryList mInventory; - bool mIsDeleted; - - Container(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index f360c8748..67c0ba31d 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -8,14 +8,10 @@ namespace ESM { unsigned int Creature::sRecordId = REC_CREA; - Creature::Creature() - : mFlags(0), - mScale(0.0f), - mIsDeleted(false) - {} - - void Creature::load(ESMReader &esm) + void Creature::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + mPersistent = (esm.getRecordFlags() & 0x0400) != 0; mAiPackage.mList.clear(); @@ -25,7 +21,6 @@ namespace ESM { mScale = 1.f; mHasAI = false; - mIsDeleted = false; bool hasName = false; bool hasNpdt = false; @@ -33,17 +28,12 @@ namespace ESM { while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -89,6 +79,10 @@ namespace ESM { case AI_CNDT: mAiPackage.add(esm); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -97,17 +91,17 @@ namespace ESM { if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasNpdt && !mIsDeleted) + if (!hasNpdt && !isDeleted) esm.fail("Missing NPDT subrecord"); - if (!hasFlags && !mIsDeleted) + if (!hasFlags && !isDeleted) esm.fail("Missing FLAG subrecord"); } - void Creature::save(ESMWriter &esm) const + void Creature::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -156,7 +150,6 @@ namespace ESM { mAiData.mServices = 0; mAiPackage.mList.clear(); mTransport.mList.clear(); - mIsDeleted = false; } const std::vector& Creature::getTransport() const diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index 22e834e45..a5147619c 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -96,14 +96,10 @@ struct Creature AIPackageList mAiPackage; Transport mTransport; - bool mIsDeleted; - - Creature(); - const std::vector& getTransport() const; - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loaddial.cpp b/components/esm/loaddial.cpp index 74a708805..30fa3cfef 100644 --- a/components/esm/loaddial.cpp +++ b/components/esm/loaddial.cpp @@ -10,29 +10,25 @@ namespace ESM { unsigned int Dialogue::sRecordId = REC_DIAL; - Dialogue::Dialogue() - : mIsDeleted(false) - {} - - void Dialogue::load(ESMReader &esm) + void Dialogue::load(ESMReader &esm, bool &isDeleted) { loadId(esm); - loadData(esm); + loadData(esm, isDeleted); } void Dialogue::loadId(ESMReader &esm) { - mIsDeleted = false; mId = esm.getHNString("NAME"); } - void Dialogue::loadData(ESMReader &esm) + void Dialogue::loadData(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'D','A','T','A'>::value: { @@ -51,7 +47,7 @@ namespace ESM case ESM::FourCC<'D','E','L','E'>::value: esm.skipHSub(); mType = Unknown; - mIsDeleted = true; + isDeleted = true; break; default: esm.fail("Unknown subrecord"); @@ -60,10 +56,10 @@ namespace ESM } } - void Dialogue::save(ESMWriter &esm) const + void Dialogue::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); } @@ -76,7 +72,6 @@ namespace ESM void Dialogue::blank() { mInfo.clear(); - mIsDeleted = false; } void Dialogue::readInfo(ESMReader &esm, bool merge) @@ -84,25 +79,27 @@ namespace ESM ESM::DialInfo info; info.loadId(esm); + bool isDeleted = false; if (!merge || mInfo.empty()) { - info.loadInfo(esm); - mLookup[info.mId] = mInfo.insert(mInfo.end(), info); + info.loadData(esm, isDeleted); + mLookup[info.mId] = std::make_pair(mInfo.insert(mInfo.end(), info), isDeleted); + return; } - ESM::Dialogue::InfoContainer::iterator it = mInfo.end(); + InfoContainer::iterator it = mInfo.end(); - std::map::iterator lookup; + LookupMap::iterator lookup; lookup = mLookup.find(info.mId); if (lookup != mLookup.end()) { - it = lookup->second; + it = lookup->second.first; // Merge with existing record. Only the subrecords that are present in // the new record will be overwritten. - it->loadInfo(esm); + it->loadData(esm, isDeleted); info = *it; // Since the record merging may have changed the next/prev linked list connection, we need to re-insert the record @@ -111,35 +108,35 @@ namespace ESM } else { - info.loadInfo(esm); + info.loadData(esm, isDeleted); } if (info.mNext.empty()) { - mLookup[info.mId] = mInfo.insert(mInfo.end(), info); + mLookup[info.mId] = std::make_pair(mInfo.insert(mInfo.end(), info), isDeleted); return; } if (info.mPrev.empty()) { - mLookup[info.mId] = mInfo.insert(mInfo.begin(), info); + mLookup[info.mId] = std::make_pair(mInfo.insert(mInfo.begin(), info), isDeleted); return; } lookup = mLookup.find(info.mPrev); if (lookup != mLookup.end()) { - it = lookup->second; + it = lookup->second.first; - mLookup[info.mId] = mInfo.insert(++it, info); + mLookup[info.mId] = std::make_pair(mInfo.insert(++it, info), isDeleted); return; } lookup = mLookup.find(info.mNext); if (lookup != mLookup.end()) { - it = lookup->second; + it = lookup->second.first; - mLookup[info.mId] = mInfo.insert(it, info); + mLookup[info.mId] = std::make_pair(mInfo.insert(it, info), isDeleted); return; } @@ -148,12 +145,15 @@ namespace ESM void Dialogue::clearDeletedInfos() { - for (InfoContainer::iterator it = mInfo.begin(); it != mInfo.end(); ) + LookupMap::const_iterator current = mLookup.begin(); + LookupMap::const_iterator end = mLookup.end(); + for (; current != end; ++current) { - if (it->mIsDeleted) - it = mInfo.erase(it); - else - ++it; + if (current->second.second) + { + mInfo.erase(current->second.first); + } } + mLookup.clear(); } } diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index 73bf16974..e517fc86f 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "loadinfo.hpp" @@ -39,27 +40,24 @@ struct Dialogue typedef std::list InfoContainer; - typedef std::map LookupMap; + // Parameters: Info ID, (Info iterator, Deleted flag) + typedef std::map > LookupMap; InfoContainer mInfo; // This is only used during the loading phase to speed up DialInfo merging. LookupMap mLookup; - bool mIsDeleted; - - Dialogue(); - - void load(ESMReader &esm); + void load(ESMReader &esm, bool &isDeleted); ///< Loads all sub-records of Dialogue record void loadId(ESMReader &esm); ///< Loads NAME sub-record of Dialogue record - void loadData(ESMReader &esm); + void loadData(ESMReader &esm, bool &isDeleted); ///< Loads all sub-records of Dialogue record, except NAME sub-record - void save(ESMWriter &esm) const; + void save(ESMWriter &esm, bool isDeleted = false) const; - /// Remove all INFOs that are deleted or marked as QS_Deleted from mInfos. + /// Remove all INFOs that are deleted void clearDeletedInfos(); /// Read the next info record diff --git a/components/esm/loaddoor.cpp b/components/esm/loaddoor.cpp index 4f58a4261..706e938e8 100644 --- a/components/esm/loaddoor.cpp +++ b/components/esm/loaddoor.cpp @@ -8,29 +8,20 @@ namespace ESM { unsigned int Door::sRecordId = REC_DOOR; - Door::Door() - : mIsDeleted(false) - {} - - void Door::load(ESMReader &esm) + void Door::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -46,6 +37,10 @@ namespace ESM case ESM::FourCC<'A','N','A','M'>::value: mCloseSound = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -56,11 +51,11 @@ namespace ESM esm.fail("Missing NAME subrecord"); } - void Door::save(ESMWriter &esm) const + void Door::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -80,6 +75,5 @@ namespace ESM mScript.clear(); mOpenSound.clear(); mCloseSound.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loaddoor.hpp b/components/esm/loaddoor.hpp index 546471ed3..3afe5d5e4 100644 --- a/components/esm/loaddoor.hpp +++ b/components/esm/loaddoor.hpp @@ -17,12 +17,8 @@ struct Door std::string mId, mName, mModel, mScript, mOpenSound, mCloseSound; - bool mIsDeleted; - - Door(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadench.cpp b/components/esm/loadench.cpp index 0e480c379..5580ef222 100644 --- a/components/esm/loadench.cpp +++ b/components/esm/loadench.cpp @@ -8,31 +8,22 @@ namespace ESM { unsigned int Enchantment::sRecordId = REC_ENCH; - Enchantment::Enchantment() - : mIsDeleted(false) - {} - - void Enchantment::load(ESMReader &esm) + void Enchantment::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; mEffects.mList.clear(); - mIsDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'E','N','D','T'>::value: esm.getHT(mData, 16); hasData = true; @@ -40,6 +31,10 @@ namespace ESM case ESM::FourCC<'E','N','A','M'>::value: mEffects.add(esm); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -48,15 +43,15 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing ENDT subrecord"); } - void Enchantment::save(ESMWriter &esm) const + void Enchantment::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -74,7 +69,5 @@ namespace ESM mData.mAutocalc = 0; mEffects.mList.clear(); - - mIsDeleted = false; } } diff --git a/components/esm/loadench.hpp b/components/esm/loadench.hpp index 6ebe8e940..7b93b519c 100644 --- a/components/esm/loadench.hpp +++ b/components/esm/loadench.hpp @@ -42,12 +42,8 @@ struct Enchantment ENDTstruct mData; EffectList mEffects; - bool mIsDeleted; - - Enchantment(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadfact.cpp b/components/esm/loadfact.cpp index 8538b0b95..f550a5538 100644 --- a/components/esm/loadfact.cpp +++ b/components/esm/loadfact.cpp @@ -10,10 +10,6 @@ namespace ESM { unsigned int Faction::sRecordId = REC_FACT; - Faction::Faction() - : mIsDeleted(false) - {} - int& Faction::FADTstruct::getSkill (int index, bool ignored) { if (index<0 || index>=7) @@ -30,9 +26,10 @@ namespace ESM return mSkills[index]; } - void Faction::load(ESMReader &esm) + void Faction::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; + mReactions.clear(); for (int i=0;i<10;++i) mRanks[i].clear(); @@ -43,17 +40,12 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); break; @@ -76,6 +68,10 @@ namespace ESM mReactions[faction] = reaction; break; } + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -84,15 +80,15 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing FADT subrecord"); } - void Faction::save(ESMWriter &esm) const + void Faction::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -136,7 +132,5 @@ namespace ESM mData.mSkills[i] = 0; mReactions.clear(); - - mIsDeleted = false; } } diff --git a/components/esm/loadfact.hpp b/components/esm/loadfact.hpp index 96c02028b..cc715d266 100644 --- a/components/esm/loadfact.hpp +++ b/components/esm/loadfact.hpp @@ -62,12 +62,8 @@ struct Faction // Name of faction ranks (may be empty for NPC factions) std::string mRanks[10]; - bool mIsDeleted; - - Faction(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID/index). diff --git a/components/esm/loadglob.cpp b/components/esm/loadglob.cpp index 5f96aff1f..72ecce503 100644 --- a/components/esm/loadglob.cpp +++ b/components/esm/loadglob.cpp @@ -8,19 +8,16 @@ namespace ESM { unsigned int Global::sRecordId = REC_GLOB; - Global::Global() - : mIsDeleted(false) - {} - - void Global::load (ESMReader &esm) + void Global::load (ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; + mId = esm.getHNString ("NAME"); if (esm.isNextSub ("DELE")) { esm.skipHSub(); - mIsDeleted = true; + isDeleted = true; } else { @@ -28,11 +25,11 @@ namespace ESM } } - void Global::save (ESMWriter &esm) const + void Global::save (ESMWriter &esm, bool isDeleted) const { esm.writeHNCString ("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString ("DELE", ""); } @@ -45,7 +42,6 @@ namespace ESM void Global::blank() { mValue.setType (ESM::VT_None); - mIsDeleted = false; } bool operator== (const Global& left, const Global& right) diff --git a/components/esm/loadglob.hpp b/components/esm/loadglob.hpp index c0219c0ba..0533cc95e 100644 --- a/components/esm/loadglob.hpp +++ b/components/esm/loadglob.hpp @@ -24,12 +24,8 @@ struct Global std::string mId; Variant mValue; - bool mIsDeleted; - - Global(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadgmst.cpp b/components/esm/loadgmst.cpp index 9e2a80270..1ebb002e6 100644 --- a/components/esm/loadgmst.cpp +++ b/components/esm/loadgmst.cpp @@ -8,13 +8,15 @@ namespace ESM { unsigned int GameSetting::sRecordId = REC_GMST; - void GameSetting::load (ESMReader &esm) + void GameSetting::load (ESMReader &esm, bool &isDeleted) { + isDeleted = false; // GameSetting record can't be deleted now (may be changed in the future) + mId = esm.getHNString("NAME"); mValue.read (esm, ESM::Variant::Format_Gmst); } - void GameSetting::save (ESMWriter &esm) const + void GameSetting::save (ESMWriter &esm, bool /*isDeleted*/) const { esm.writeHNCString("NAME", mId); mValue.write (esm, ESM::Variant::Format_Gmst); diff --git a/components/esm/loadgmst.hpp b/components/esm/loadgmst.hpp index d9d9048b6..73a723e81 100644 --- a/components/esm/loadgmst.hpp +++ b/components/esm/loadgmst.hpp @@ -26,7 +26,7 @@ struct GameSetting Variant mValue; - void load(ESMReader &esm); + void load(ESMReader &esm, bool &isDeleted); /// \todo remove the get* functions (redundant, since mValue has equivalent functions now). @@ -39,7 +39,7 @@ struct GameSetting std::string getString() const; ///< Throwns an exception if GMST is not of type string. - void save(ESMWriter &esm) const; + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index 89fd4e0cd..d1f20a3d4 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -8,29 +8,23 @@ namespace ESM { unsigned int DialInfo::sRecordId = REC_INFO; - DialInfo::DialInfo() - : mFactionLess(false), - mQuestStatus(QS_None), - mIsDeleted(false) - {} - - void DialInfo::load(ESMReader &esm) + void DialInfo::load(ESMReader &esm, bool &isDeleted) { loadId(esm); - loadInfo(esm); + loadData(esm, isDeleted); } void DialInfo::loadId(ESMReader &esm) { - mIsDeleted = false; mId = esm.getHNString("INAM"); } - void DialInfo::loadInfo(ESMReader &esm) + void DialInfo::loadData(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + mQuestStatus = QS_None; mFactionLess = false; - mIsDeleted = false; mPrev = esm.getHNString("PNAM"); mNext = esm.getHNString("NNAM"); @@ -41,13 +35,8 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'D','A','T','A'>::value: esm.getHT(mData, 12); break; @@ -104,6 +93,10 @@ namespace ESM mQuestStatus = QS_Restart; esm.skipRecord(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -111,13 +104,13 @@ namespace ESM } } - void DialInfo::save(ESMWriter &esm) const + void DialInfo::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("INAM", mId); esm.writeHNCString("PNAM", mPrev); esm.writeHNCString("NNAM", mNext); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -173,6 +166,5 @@ namespace ESM mResultScript.clear(); mFactionLess = false; mQuestStatus = QS_None; - mIsDeleted = false; } } diff --git a/components/esm/loadinfo.hpp b/components/esm/loadinfo.hpp index 65363d1be..8123a9ace 100644 --- a/components/esm/loadinfo.hpp +++ b/components/esm/loadinfo.hpp @@ -105,18 +105,14 @@ struct DialInfo REC_DELE = 0x454c4544 }; - bool mIsDeleted; - - DialInfo(); - - void load(ESMReader &esm); + void load(ESMReader &esm, bool &isDeleted); ///< Loads all sub-records of Info record void loadId(ESMReader &esm); ///< Loads only Id of Info record (INAM sub-record) - void loadInfo(ESMReader &esm); + void loadData(ESMReader &esm, bool &isDeleted); ///< Loads all sub-records of Info record, except INAM sub-record - void save(ESMWriter &esm) const; + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadingr.cpp b/components/esm/loadingr.cpp index 51a1f4805..a481d5b79 100644 --- a/components/esm/loadingr.cpp +++ b/components/esm/loadingr.cpp @@ -8,30 +8,21 @@ namespace ESM { unsigned int Ingredient::sRecordId = REC_INGR; - Ingredient::Ingredient() - : mIsDeleted(false) - {} - - void Ingredient::load(ESMReader &esm) + void Ingredient::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -48,6 +39,10 @@ namespace ESM case ESM::FourCC<'I','T','E','X'>::value: mIcon = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -56,7 +51,7 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing IRDT subrecord"); // horrible hack to fix broken data in records @@ -83,11 +78,11 @@ namespace ESM } } - void Ingredient::save(ESMWriter &esm) const + void Ingredient::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -115,7 +110,5 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); - - mIsDeleted = false; } } diff --git a/components/esm/loadingr.hpp b/components/esm/loadingr.hpp index c92f28f18..c0f445023 100644 --- a/components/esm/loadingr.hpp +++ b/components/esm/loadingr.hpp @@ -31,12 +31,8 @@ struct Ingredient IRDTstruct mData; std::string mId, mName, mModel, mIcon, mScript; - bool mIsDeleted; - - Ingredient(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 6acaa6e6a..2ffd2a21b 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -72,7 +72,6 @@ namespace ESM , mDataTypes(0) , mDataLoaded(false) , mLandData(NULL) - , mIsDeleted(false) { } @@ -81,61 +80,82 @@ namespace ESM delete mLandData; } - void Land::load(ESMReader &esm) + void Land::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + mEsm = &esm; mPlugin = mEsm->getIndex(); - mIsDeleted = false; - - // Get the grid location - esm.getSubNameIs("INTV"); - esm.getSubHeaderIs(8); - esm.getT(mX); - esm.getT(mY); - - esm.getHNT(mFlags, "DATA"); - if (esm.isNextSub("DELE")) + bool hasLocation = false; + bool isLoaded = false; + while (!isLoaded && esm.hasMoreSubs()) { - esm.skipHSub(); - mIsDeleted = true; + esm.getSubName(); + switch (esm.retSubName().val) + { + case ESM::FourCC<'I','N','T','V'>::value: + esm.getSubHeaderIs(8); + esm.getT(mX); + esm.getT(mY); + hasLocation = true; + break; + case ESM::FourCC<'D','A','T','A'>::value: + esm.getHT(mFlags); + break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; + default: + esm.cacheSubName(); + isLoaded = true; + break; + } } - // Store the file position + if (!hasLocation) + esm.fail("Missing INTV subrecord"); + mContext = esm.getContext(); - // Skip these here. Load the actual data when the cell is loaded. - if (esm.isNextSub("VNML")) - { - esm.skipHSubSize(12675); - mDataTypes |= DATA_VNML; - } - if (esm.isNextSub("VHGT")) - { - esm.skipHSubSize(4232); - mDataTypes |= DATA_VHGT; - } - if (esm.isNextSub("WNAM")) + // Skip the land data here. Load it when the cell is loaded. + while (esm.hasMoreSubs()) { - esm.skipHSubSize(81); - mDataTypes |= DATA_WNAM; - } - if (esm.isNextSub("VCLR")) - { - esm.skipHSubSize(12675); - mDataTypes |= DATA_VCLR; - } - if (esm.isNextSub("VTEX")) - { - esm.skipHSubSize(512); - mDataTypes |= DATA_VTEX; + esm.getSubName(); + switch (esm.retSubName().val) + { + case ESM::FourCC<'V','N','M','L'>::value: + esm.skipHSub(); + mDataTypes |= DATA_VNML; + break; + case ESM::FourCC<'V','H','G','T'>::value: + esm.skipHSub(); + mDataTypes |= DATA_VHGT; + break; + case ESM::FourCC<'W','N','A','M'>::value: + esm.skipHSub(); + mDataTypes |= DATA_WNAM; + break; + case ESM::FourCC<'V','C','L','R'>::value: + esm.skipHSub(); + mDataTypes |= DATA_VCLR; + break; + case ESM::FourCC<'V','T','E','X'>::value: + esm.skipHSub(); + mDataTypes |= DATA_VTEX; + break; + default: + esm.fail("Unknown subrecord"); + break; + } } mDataLoaded = 0; mLandData = NULL; } - void Land::save(ESMWriter &esm) const + void Land::save(ESMWriter &esm, bool isDeleted) const { esm.startSubRecord("INTV"); esm.writeT(mX); @@ -144,22 +164,17 @@ namespace ESM esm.writeHNT("DATA", mFlags); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); } - if (mLandData != NULL) + if (mLandData) { mLandData->save(esm); } } - void Land::blank() - { - mIsDeleted = false; - } - void Land::loadData(int flags) { // Try to load only available data diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index d9ee0015a..ddb00f394 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -97,12 +97,10 @@ struct Land LandData *mLandData; - bool mIsDeleted; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; - void load(ESMReader &esm); - void save(ESMWriter &esm) const; - - void blank(); + void blank() {} /** * Actually loads data diff --git a/components/esm/loadlevlist.cpp b/components/esm/loadlevlist.cpp index 9c34ef657..6245ec856 100644 --- a/components/esm/loadlevlist.cpp +++ b/components/esm/loadlevlist.cpp @@ -6,29 +6,21 @@ namespace ESM { - LevelledListBase::LevelledListBase() - : mIsDeleted(false) - {} - - void LevelledListBase::load(ESMReader &esm) + void LevelledListBase::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; + bool hasList = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'D','A','T','A'>::value: esm.getHT(mFlags); break; @@ -53,12 +45,28 @@ namespace ESM li.mId = esm.getHNString(mRecName); esm.getHNT(li.mLevel, "INTV"); } + + hasList = true; break; } + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: - mList.clear(); - esm.skipRecord(); + { + if (!hasList) + { + // Original engine ignores rest of the record, even if there are items following + mList.clear(); + esm.skipRecord(); + } + else + { + esm.fail("Unknown subrecord"); + } break; + } } } @@ -66,11 +74,11 @@ namespace ESM esm.fail("Missing NAME subrecord"); } - void LevelledListBase::save(ESMWriter &esm) const + void LevelledListBase::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -92,7 +100,6 @@ namespace ESM mFlags = 0; mChanceNone = 0; mList.clear(); - mIsDeleted = false; } unsigned int CreatureLevList::sRecordId = REC_LEVC; diff --git a/components/esm/loadlevlist.hpp b/components/esm/loadlevlist.hpp index 14ebc9937..ed4131c16 100644 --- a/components/esm/loadlevlist.hpp +++ b/components/esm/loadlevlist.hpp @@ -36,12 +36,8 @@ struct LevelledListBase std::vector mList; - bool mIsDeleted; - - LevelledListBase(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadligh.cpp b/components/esm/loadligh.cpp index 441e96d0a..a0fedc3ad 100644 --- a/components/esm/loadligh.cpp +++ b/components/esm/loadligh.cpp @@ -8,30 +8,21 @@ namespace ESM { unsigned int Light::sRecordId = REC_LIGH; - Light::Light() - : mIsDeleted(false) - {} - - void Light::load(ESMReader &esm) + void Light::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -51,6 +42,10 @@ namespace ESM case ESM::FourCC<'S','N','A','M'>::value: mSound = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -59,14 +54,14 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing LHDT subrecord"); } - void Light::save(ESMWriter &esm) const + void Light::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -93,6 +88,5 @@ namespace ESM mModel.clear(); mIcon.clear(); mName.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadligh.hpp b/components/esm/loadligh.hpp index d4d3418d8..8509c64b6 100644 --- a/components/esm/loadligh.hpp +++ b/components/esm/loadligh.hpp @@ -47,12 +47,8 @@ struct Light std::string mSound, mScript, mModel, mIcon, mName, mId; - bool mIsDeleted; - - Light(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadlock.cpp b/components/esm/loadlock.cpp index 2cfe43743..be93eaa0e 100644 --- a/components/esm/loadlock.cpp +++ b/components/esm/loadlock.cpp @@ -8,30 +8,21 @@ namespace ESM { unsigned int Lockpick::sRecordId = REC_LOCK; - Lockpick::Lockpick() - : mIsDeleted(false) - {} - - void Lockpick::load(ESMReader &esm) + void Lockpick::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -48,6 +39,10 @@ namespace ESM case ESM::FourCC<'I','T','E','X'>::value: mIcon = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -56,15 +51,15 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing LKDT subrecord"); } - void Lockpick::save(ESMWriter &esm) const + void Lockpick::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -88,6 +83,5 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadlock.hpp b/components/esm/loadlock.hpp index ce7de2c06..9db41af97 100644 --- a/components/esm/loadlock.hpp +++ b/components/esm/loadlock.hpp @@ -27,12 +27,8 @@ struct Lockpick Data mData; std::string mId, mName, mModel, mIcon, mScript; - bool mIsDeleted; - - Lockpick(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadltex.cpp b/components/esm/loadltex.cpp index 6bd48d801..cf026dbf1 100644 --- a/components/esm/loadltex.cpp +++ b/components/esm/loadltex.cpp @@ -8,30 +8,21 @@ namespace ESM { unsigned int LandTexture::sRecordId = REC_LTEX; - LandTexture::LandTexture() - : mIsDeleted(false) - {} - - void LandTexture::load(ESMReader &esm) + void LandTexture::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasIndex = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'I','N','T','V'>::value: esm.getHT(mIndex); hasIndex = true; @@ -39,6 +30,10 @@ namespace ESM case ESM::FourCC<'D','A','T','A'>::value: mTexture = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -50,9 +45,9 @@ namespace ESM if (!hasIndex) esm.fail("Missing INTV subrecord"); } - void LandTexture::save(ESMWriter &esm) const + void LandTexture::save(ESMWriter &esm, bool isDeleted) const { - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); } @@ -66,6 +61,5 @@ namespace ESM { mTexture.clear(); mIndex = -1; - mIsDeleted = false; } } diff --git a/components/esm/loadltex.hpp b/components/esm/loadltex.hpp index 33af77612..2cb5abf0c 100644 --- a/components/esm/loadltex.hpp +++ b/components/esm/loadltex.hpp @@ -34,12 +34,8 @@ struct LandTexture std::string mId, mTexture; int mIndex; - bool mIsDeleted; - - LandTexture(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadmgef.cpp b/components/esm/loadmgef.cpp index 6f859ab3c..eef58aa2f 100644 --- a/components/esm/loadmgef.cpp +++ b/components/esm/loadmgef.cpp @@ -189,8 +189,10 @@ namespace ESM { unsigned int MagicEffect::sRecordId = REC_MGEF; -void MagicEffect::load(ESMReader &esm) +void MagicEffect::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; // MagicEffect record can't be deleted now (may be changed in the future) + esm.getHNT(mIndex, "INDX"); mId = indexToId (mIndex); @@ -209,8 +211,7 @@ void MagicEffect::load(ESMReader &esm) while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'I','T','E','X'>::value: mIcon = esm.getHString(); @@ -250,7 +251,7 @@ void MagicEffect::load(ESMReader &esm) } } } -void MagicEffect::save(ESMWriter &esm) const +void MagicEffect::save(ESMWriter &esm, bool /*isDeleted*/) const { esm.writeHNT("INDX", mIndex); diff --git a/components/esm/loadmgef.hpp b/components/esm/loadmgef.hpp index 32b8a85a6..24d4c9e2b 100644 --- a/components/esm/loadmgef.hpp +++ b/components/esm/loadmgef.hpp @@ -96,8 +96,8 @@ struct MagicEffect // sMagicCreature04ID/05ID. int mIndex; - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; /// Set record to default state (does not touch the ID/index). void blank(); diff --git a/components/esm/loadmisc.cpp b/components/esm/loadmisc.cpp index de9ccdd6a..f03cb9a85 100644 --- a/components/esm/loadmisc.cpp +++ b/components/esm/loadmisc.cpp @@ -8,30 +8,21 @@ namespace ESM { unsigned int Miscellaneous::sRecordId = REC_MISC; - Miscellaneous::Miscellaneous() - : mIsDeleted(false) - {} - - void Miscellaneous::load(ESMReader &esm) + void Miscellaneous::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -48,6 +39,10 @@ namespace ESM case ESM::FourCC<'I','T','E','X'>::value: mIcon = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -56,15 +51,15 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing MCDT subrecord"); } - void Miscellaneous::save(ESMWriter &esm) const + void Miscellaneous::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -86,6 +81,5 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadmisc.hpp b/components/esm/loadmisc.hpp index 82018cd72..e7a323904 100644 --- a/components/esm/loadmisc.hpp +++ b/components/esm/loadmisc.hpp @@ -32,12 +32,8 @@ struct Miscellaneous std::string mId, mName, mModel, mIcon, mScript; - bool mIsDeleted; - - Miscellaneous(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index ff3213ee9..939801e74 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -8,15 +8,10 @@ namespace ESM { unsigned int NPC::sRecordId = REC_NPC_; - NPC::NPC() - : mFlags(0), - mHasAI(false), - mIsDeleted(false) - {} - - void NPC::load(ESMReader &esm) + void NPC::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; + mPersistent = (esm.getRecordFlags() & 0x0400) != 0; mSpells.mList.clear(); @@ -31,17 +26,12 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -108,6 +98,10 @@ namespace ESM case AI_CNDT: mAiPackage.add(esm); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -116,16 +110,16 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasNpdt && !mIsDeleted) + if (!hasNpdt && !isDeleted) esm.fail("Missing NPDT subrecord"); - if (!hasFlags && !mIsDeleted) + if (!hasFlags && !isDeleted) esm.fail("Missing FLAG subrecord"); } - void NPC::save(ESMWriter &esm) const + void NPC::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -206,7 +200,6 @@ namespace ESM mScript.clear(); mHair.clear(); mHead.clear(); - mIsDeleted = false; } int NPC::getFactionRank() const diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index 263752752..5b89f4055 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -130,12 +130,8 @@ struct NPC // body parts std::string mHair, mHead; - bool mIsDeleted; - - NPC(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; bool isMale() const; diff --git a/components/esm/loadpgrd.cpp b/components/esm/loadpgrd.cpp index 5e8de9d57..8027be91c 100644 --- a/components/esm/loadpgrd.cpp +++ b/components/esm/loadpgrd.cpp @@ -32,12 +32,10 @@ namespace ESM { } - Pathgrid::Pathgrid() - : mIsDeleted(false) - {} - - void Pathgrid::load(ESMReader &esm) + void Pathgrid::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + mPoints.clear(); mEdges.clear(); @@ -49,8 +47,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'D','A','T','A'>::value: esm.getHT(mData, 12); @@ -118,7 +115,7 @@ namespace ESM } case ESM::FourCC<'D','E','L','E'>::value: esm.skipHSub(); - mIsDeleted = true; + isDeleted = true; break; default: esm.fail("Unknown subrecord"); @@ -132,12 +129,12 @@ namespace ESM esm.fail("Missing NAME subrecord"); } - void Pathgrid::save(ESMWriter &esm) const + void Pathgrid::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNT("DATA", mData, 12); esm.writeHNCString("NAME", mCell); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -173,6 +170,5 @@ namespace ESM mData.mS2 = 0; mPoints.clear(); mEdges.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadpgrd.hpp b/components/esm/loadpgrd.hpp index 4b82d9571..d1003eb86 100644 --- a/components/esm/loadpgrd.hpp +++ b/components/esm/loadpgrd.hpp @@ -53,12 +53,8 @@ struct Pathgrid typedef std::vector EdgeList; EdgeList mEdges; - bool mIsDeleted; - - Pathgrid(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); }; diff --git a/components/esm/loadprob.cpp b/components/esm/loadprob.cpp index 4ce9b9d9c..31caeff41 100644 --- a/components/esm/loadprob.cpp +++ b/components/esm/loadprob.cpp @@ -8,30 +8,21 @@ namespace ESM { unsigned int Probe::sRecordId = REC_PROB; - Probe::Probe() - : mIsDeleted(false) - {} - - void Probe::load(ESMReader &esm) + void Probe::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -48,6 +39,10 @@ namespace ESM case ESM::FourCC<'I','T','E','X'>::value: mIcon = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -56,15 +51,15 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing PBDT subrecord"); } - void Probe::save(ESMWriter &esm) const + void Probe::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -88,6 +83,5 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadprob.hpp b/components/esm/loadprob.hpp index 748d498fc..da203b456 100644 --- a/components/esm/loadprob.hpp +++ b/components/esm/loadprob.hpp @@ -27,12 +27,8 @@ struct Probe Data mData; std::string mId, mName, mModel, mIcon, mScript; - bool mIsDeleted; - - Probe(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadrace.cpp b/components/esm/loadrace.cpp index 12762bda3..d5172a133 100644 --- a/components/esm/loadrace.cpp +++ b/components/esm/loadrace.cpp @@ -8,10 +8,6 @@ namespace ESM { unsigned int Race::sRecordId = REC_RACE; - Race::Race() - : mIsDeleted(false) - {} - int Race::MaleFemale::getValue (bool male) const { return male ? mMale : mFemale; @@ -22,27 +18,23 @@ namespace ESM return static_cast(male ? mMale : mFemale); } - void Race::load(ESMReader &esm) + void Race::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + mPowers.mList.clear(); - mIsDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); break; @@ -56,6 +48,10 @@ namespace ESM case ESM::FourCC<'N','P','C','S'>::value: mPowers.add(esm); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); } @@ -63,14 +59,14 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing RADT subrecord"); } - void Race::save(ESMWriter &esm) const + void Race::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; diff --git a/components/esm/loadrace.hpp b/components/esm/loadrace.hpp index e8e9a442b..bf0573075 100644 --- a/components/esm/loadrace.hpp +++ b/components/esm/loadrace.hpp @@ -68,12 +68,8 @@ struct Race std::string mId, mName, mDescription; SpellList mPowers; - bool mIsDeleted; - - Race(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID/index). diff --git a/components/esm/loadregn.cpp b/components/esm/loadregn.cpp index b48ffa4b7..b04e6ee3b 100644 --- a/components/esm/loadregn.cpp +++ b/components/esm/loadregn.cpp @@ -8,29 +8,20 @@ namespace ESM { unsigned int Region::sRecordId = REC_REGN; - Region::Region() - : mMapColor(0), - mIsDeleted(false) - {} - - void Region::load(ESMReader &esm) + void Region::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); @@ -75,6 +66,9 @@ namespace ESM esm.getHT(sr, 33); mSoundList.push_back(sr); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; default: esm.fail("Unknown subrecord"); break; @@ -85,9 +79,9 @@ namespace ESM esm.fail("Missing NAME subrecord"); } - void Region::save(ESMWriter &esm) const + void Region::save(ESMWriter &esm, bool isDeleted) const { - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); } @@ -121,7 +115,5 @@ namespace ESM mName.clear(); mSleepList.clear(); mSoundList.clear(); - - mIsDeleted = false; } } diff --git a/components/esm/loadregn.hpp b/components/esm/loadregn.hpp index 9082437fe..3d914bd17 100644 --- a/components/esm/loadregn.hpp +++ b/components/esm/loadregn.hpp @@ -51,12 +51,8 @@ struct Region std::vector mSoundList; - bool mIsDeleted; - - Region(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID/index). diff --git a/components/esm/loadrepa.cpp b/components/esm/loadrepa.cpp index 74e682d63..00d2ebf08 100644 --- a/components/esm/loadrepa.cpp +++ b/components/esm/loadrepa.cpp @@ -8,30 +8,21 @@ namespace ESM { unsigned int Repair::sRecordId = REC_REPA; - Repair::Repair() - : mIsDeleted(false) - {} - - void Repair::load(ESMReader &esm) + void Repair::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -48,6 +39,10 @@ namespace ESM case ESM::FourCC<'I','T','E','X'>::value: mIcon = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -56,15 +51,15 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing RIDT subrecord"); } - void Repair::save(ESMWriter &esm) const + void Repair::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -88,6 +83,5 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadrepa.hpp b/components/esm/loadrepa.hpp index 1448f9c77..2537c53cb 100644 --- a/components/esm/loadrepa.hpp +++ b/components/esm/loadrepa.hpp @@ -27,12 +27,8 @@ struct Repair Data mData; std::string mId, mName, mModel, mIcon, mScript; - bool mIsDeleted; - - Repair(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index 333389ba4..e433ddede 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -10,10 +10,6 @@ namespace ESM { unsigned int Script::sRecordId = REC_SCPT; - Script::Script() - : mIsDeleted(false) - {} - void Script::loadSCVR(ESMReader &esm) { int s = mData.mStringTableSize; @@ -61,17 +57,17 @@ namespace ESM } } - void Script::load(ESMReader &esm) + void Script::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + mVarNames.clear(); - mIsDeleted = false; bool hasHeader = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'S','C','H','D'>::value: SCHD data; @@ -80,10 +76,6 @@ namespace ESM mId = data.mName.toString(); hasHeader = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'S','C','V','R'>::value: // list of local variables loadSCVR(esm); @@ -96,6 +88,10 @@ namespace ESM case ESM::FourCC<'S','C','T','X'>::value: mScriptText = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -106,7 +102,7 @@ namespace ESM esm.fail("Missing SCHD subrecord"); } - void Script::save(ESMWriter &esm) const + void Script::save(ESMWriter &esm, bool isDeleted) const { std::string varNameString; if (!mVarNames.empty()) @@ -121,7 +117,7 @@ namespace ESM esm.writeHNT("SCHD", data, 52); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); } @@ -156,8 +152,6 @@ namespace ESM mScriptText = "Begin \"" + mId + "\"\n\nEnd " + mId + "\n"; else mScriptText = "Begin " + mId + "\n\nEnd " + mId + "\n"; - - mIsDeleted = false; } } diff --git a/components/esm/loadscpt.hpp b/components/esm/loadscpt.hpp index 58b5842e8..b8a06406d 100644 --- a/components/esm/loadscpt.hpp +++ b/components/esm/loadscpt.hpp @@ -50,12 +50,8 @@ public: /// Script source code std::string mScriptText; - bool mIsDeleted; - - Script(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID/index). diff --git a/components/esm/loadskil.cpp b/components/esm/loadskil.cpp index 7883b8a1a..c52089791 100644 --- a/components/esm/loadskil.cpp +++ b/components/esm/loadskil.cpp @@ -129,15 +129,16 @@ namespace ESM unsigned int Skill::sRecordId = REC_SKIL; - void Skill::load(ESMReader &esm) + void Skill::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; // Skill record can't be deleted now (may be changed in the future) + bool hasIndex = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'I','N','D','X'>::value: esm.getHT(mIndex); @@ -164,7 +165,7 @@ namespace ESM mId = indexToId (mIndex); } - void Skill::save(ESMWriter &esm) const + void Skill::save(ESMWriter &esm, bool /*isDeleted*/) const { esm.writeHNT("INDX", mIndex); esm.writeHNT("SKDT", mData, 24); diff --git a/components/esm/loadskil.hpp b/components/esm/loadskil.hpp index e00184297..5430b422d 100644 --- a/components/esm/loadskil.hpp +++ b/components/esm/loadskil.hpp @@ -78,8 +78,8 @@ struct Skill static const std::string sIconNames[Length]; static const boost::array sSkillIds; - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID/index). diff --git a/components/esm/loadsndg.cpp b/components/esm/loadsndg.cpp index a20e6ee51..400b1072b 100644 --- a/components/esm/loadsndg.cpp +++ b/components/esm/loadsndg.cpp @@ -8,31 +8,21 @@ namespace ESM { unsigned int SoundGenerator::sRecordId = REC_SNDG; - SoundGenerator::SoundGenerator() - : mType(LeftFoot), - mIsDeleted(false) - {} - - void SoundGenerator::load(ESMReader &esm) + void SoundGenerator::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'D','A','T','A'>::value: esm.getHT(mType, 4); hasData = true; @@ -43,6 +33,10 @@ namespace ESM case ESM::FourCC<'S','N','A','M'>::value: mSound = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -51,17 +45,17 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing DATA subrecord"); } - void SoundGenerator::save(ESMWriter &esm) const + void SoundGenerator::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); esm.writeHNT("DATA", mType, 4); esm.writeHNOCString("CNAM", mCreature); esm.writeHNOCString("SNAM", mSound); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); } @@ -72,6 +66,5 @@ namespace ESM mType = LeftFoot; mCreature.clear(); mSound.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadsndg.hpp b/components/esm/loadsndg.hpp index 13eb18072..70b221e98 100644 --- a/components/esm/loadsndg.hpp +++ b/components/esm/loadsndg.hpp @@ -36,12 +36,8 @@ struct SoundGenerator std::string mId, mCreature, mSound; - bool mIsDeleted; - - SoundGenerator(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); }; diff --git a/components/esm/loadsoun.cpp b/components/esm/loadsoun.cpp index 55fe69292..d3a82e198 100644 --- a/components/esm/loadsoun.cpp +++ b/components/esm/loadsoun.cpp @@ -8,30 +8,21 @@ namespace ESM { unsigned int Sound::sRecordId = REC_SOUN; - Sound::Sound() - : mIsDeleted(false) - {} - - void Sound::load(ESMReader &esm) + void Sound::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'F','N','A','M'>::value: mSound = esm.getHString(); break; @@ -39,6 +30,10 @@ namespace ESM esm.getHT(mData, 3); hasData = true; break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -47,15 +42,15 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing DATA subrecord"); } - void Sound::save(ESMWriter &esm) const + void Sound::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -72,7 +67,5 @@ namespace ESM mData.mVolume = 128; mData.mMinRange = 0; mData.mMaxRange = 255; - - mIsDeleted = false; } } diff --git a/components/esm/loadsoun.hpp b/components/esm/loadsoun.hpp index 0b40ae751..937e22be8 100644 --- a/components/esm/loadsoun.hpp +++ b/components/esm/loadsoun.hpp @@ -23,12 +23,8 @@ struct Sound SOUNstruct mData; std::string mId, mSound; - bool mIsDeleted; - - Sound(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID/index). diff --git a/components/esm/loadspel.cpp b/components/esm/loadspel.cpp index 28feffd20..16ffb63ff 100644 --- a/components/esm/loadspel.cpp +++ b/components/esm/loadspel.cpp @@ -8,32 +8,23 @@ namespace ESM { unsigned int Spell::sRecordId = REC_SPEL; - Spell::Spell() - : mIsDeleted(false) - {} - - void Spell::load(ESMReader &esm) + void Spell::load(ESMReader &esm, bool &isDeleted) { + isDeleted = false; + mEffects.mList.clear(); - mIsDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t val = esm.retSubName().val; - - switch (val) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); break; @@ -46,6 +37,10 @@ namespace ESM esm.getHT(s, 24); mEffects.mList.push_back(s); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -54,15 +49,15 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing SPDT subrecord"); } - void Spell::save(ESMWriter &esm) const + void Spell::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -81,6 +76,5 @@ namespace ESM mName.clear(); mEffects.mList.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadspel.hpp b/components/esm/loadspel.hpp index 327e94d8f..1763d0991 100644 --- a/components/esm/loadspel.hpp +++ b/components/esm/loadspel.hpp @@ -45,12 +45,8 @@ struct Spell std::string mId, mName; EffectList mEffects; - bool mIsDeleted; - - Spell(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID/index). diff --git a/components/esm/loadsscr.cpp b/components/esm/loadsscr.cpp index 076f73742..6af6c96dc 100644 --- a/components/esm/loadsscr.cpp +++ b/components/esm/loadsscr.cpp @@ -8,21 +8,16 @@ namespace ESM { unsigned int StartScript::sRecordId = REC_SSCR; - StartScript::StartScript() - : mIsDeleted(false) - {} - - void StartScript::load(ESMReader &esm) + void StartScript::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasData = false; bool hasName = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'D','A','T','A'>::value: mData = esm.getHString(); @@ -34,7 +29,7 @@ namespace ESM break; case ESM::FourCC<'D','E','L','E'>::value: esm.skipHSub(); - mIsDeleted = true; + isDeleted = true; break; default: esm.fail("Unknown subrecord"); @@ -47,12 +42,12 @@ namespace ESM if (!hasName) esm.fail("Missing NAME"); } - void StartScript::save(ESMWriter &esm) const + void StartScript::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNString("DATA", mData); esm.writeHNString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); } @@ -61,6 +56,5 @@ namespace ESM void StartScript::blank() { mData.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadsscr.hpp b/components/esm/loadsscr.hpp index e475abd86..ce2ff49e7 100644 --- a/components/esm/loadsscr.hpp +++ b/components/esm/loadsscr.hpp @@ -26,13 +26,9 @@ struct StartScript std::string mData; std::string mId; - bool mIsDeleted; - - StartScript(); - // Load a record and add it to the list - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); }; diff --git a/components/esm/loadstat.cpp b/components/esm/loadstat.cpp index 9a146a370..eee7a50f5 100644 --- a/components/esm/loadstat.cpp +++ b/components/esm/loadstat.cpp @@ -8,32 +8,27 @@ namespace ESM { unsigned int Static::sRecordId = REC_STAT; - Static::Static() - : mIsDeleted(false) - {} - - void Static::load(ESMReader &esm) + void Static::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; @@ -43,10 +38,10 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); } - void Static::save(ESMWriter &esm) const + void Static::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); } @@ -59,6 +54,5 @@ namespace ESM void Static::blank() { mModel.clear(); - mIsDeleted = false; } } diff --git a/components/esm/loadstat.hpp b/components/esm/loadstat.hpp index f88ad671b..930cdb849 100644 --- a/components/esm/loadstat.hpp +++ b/components/esm/loadstat.hpp @@ -28,12 +28,8 @@ struct Static std::string mId, mModel; - bool mIsDeleted; - - Static(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/loadweap.cpp b/components/esm/loadweap.cpp index 98302c13d..b0bc1dad6 100644 --- a/components/esm/loadweap.cpp +++ b/components/esm/loadweap.cpp @@ -8,30 +8,21 @@ namespace ESM { unsigned int Weapon::sRecordId = REC_WEAP; - Weapon::Weapon() - : mIsDeleted(false) - {} - - void Weapon::load(ESMReader &esm) + void Weapon::load(ESMReader &esm, bool &isDeleted) { - mIsDeleted = false; + isDeleted = false; bool hasName = false; bool hasData = false; while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; - switch (name) + switch (esm.retSubName().val) { case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; - case ESM::FourCC<'D','E','L','E'>::value: - esm.skipHSub(); - mIsDeleted = true; - break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; @@ -51,6 +42,10 @@ namespace ESM case ESM::FourCC<'E','N','A','M'>::value: mEnchant = esm.getHString(); break; + case ESM::FourCC<'D','E','L','E'>::value: + esm.skipHSub(); + isDeleted = true; + break; default: esm.fail("Unknown subrecord"); } @@ -58,14 +53,14 @@ namespace ESM if (!hasName) esm.fail("Missing NAME subrecord"); - if (!hasData && !mIsDeleted) + if (!hasData && !isDeleted) esm.fail("Missing WPDT subrecord"); } - void Weapon::save(ESMWriter &esm) const + void Weapon::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - if (mIsDeleted) + if (isDeleted) { esm.writeHNCString("DELE", ""); return; @@ -98,7 +93,5 @@ namespace ESM mIcon.clear(); mEnchant.clear(); mScript.clear(); - - mIsDeleted = false; } } diff --git a/components/esm/loadweap.hpp b/components/esm/loadweap.hpp index ce61eeb72..eddcaee4f 100644 --- a/components/esm/loadweap.hpp +++ b/components/esm/loadweap.hpp @@ -69,12 +69,8 @@ struct Weapon std::string mId, mName, mModel, mIcon, mEnchant, mScript; - bool mIsDeleted; - - Weapon(); - - void load(ESMReader &esm); - void save(ESMWriter &esm) const; + void load(ESMReader &esm, bool &isDeleted); + void save(ESMWriter &esm, bool isDeleted = false) const; void blank(); ///< Set record to default state (does not touch the ID). diff --git a/components/esm/objectstate.cpp b/components/esm/objectstate.cpp index 0ae690ee8..575826ef3 100644 --- a/components/esm/objectstate.cpp +++ b/components/esm/objectstate.cpp @@ -8,7 +8,8 @@ void ESM::ObjectState::load (ESMReader &esm) { mVersion = esm.getFormat(); - mRef.loadData(esm); + bool isDeleted; + mRef.loadData(esm, isDeleted); mHasLocals = 0; esm.getHNOT (mHasLocals, "HLOC"); From 67c8f95c4e85466a7c802f4cced117ade2378184 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 21 Jul 2015 13:17:03 +0300 Subject: [PATCH 41/49] Load/read methods (for ESM records) accept a deleted flag in OpenMW --- apps/openmw/mwworld/cellreflist.hpp | 2 +- apps/openmw/mwworld/cellstore.cpp | 58 +++++++++--------- apps/openmw/mwworld/cellstore.hpp | 2 +- apps/openmw/mwworld/globals.cpp | 6 +- apps/openmw/mwworld/store.cpp | 94 +++++++++++++---------------- 5 files changed, 79 insertions(+), 83 deletions(-) diff --git a/apps/openmw/mwworld/cellreflist.hpp b/apps/openmw/mwworld/cellreflist.hpp index 0ce603224..49197d167 100644 --- a/apps/openmw/mwworld/cellreflist.hpp +++ b/apps/openmw/mwworld/cellreflist.hpp @@ -22,7 +22,7 @@ namespace MWWorld /// and the build will fail with an ugly three-way cyclic header dependence /// so we need to pass the instantiation of the method to the linker, when /// all methods are known. - void load (ESM::CellRef &ref, const MWWorld::ESMStore &esmStore); + void load (ESM::CellRef &ref, bool deleted, const MWWorld::ESMStore &esmStore); LiveRef *find (const std::string& name) { diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index a51672581..e9f9c5cd1 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -147,7 +147,7 @@ namespace MWWorld { template - void CellRefList::load(ESM::CellRef &ref, const MWWorld::ESMStore &esmStore) + void CellRefList::load(ESM::CellRef &ref, bool deleted, const MWWorld::ESMStore &esmStore) { const MWWorld::Store &store = esmStore.get(); @@ -158,7 +158,7 @@ namespace MWWorld LiveRef liveCellRef (ref, ptr); - if (ref.mIsDeleted) + if (deleted) liveCellRef.mData.setDeleted(true); if (iter != mList.end()) @@ -374,9 +374,10 @@ namespace MWWorld ESM::CellRef ref; // Get each reference in turn - while (mCell->getNextRef (esm[index], ref)) + bool deleted = false; + while (mCell->getNextRef (esm[index], ref, deleted)) { - if (ref.mIsDeleted) + if (deleted) continue; // Don't list reference if it was moved to a different cell. @@ -419,7 +420,8 @@ namespace MWWorld ref.mRefNum.mContentFile = ESM::RefNum::RefNum_NoContentFile; // Get each reference in turn - while(mCell->getNextRef(esm[index], ref)) + bool deleted = false; + while(mCell->getNextRef(esm[index], ref, deleted)) { // Don't load reference if it was moved to a different cell. ESM::MovedCellRefTracker::const_iterator iter = @@ -428,7 +430,7 @@ namespace MWWorld continue; } - loadRef (ref, store); + loadRef (ref, deleted, store); } } @@ -437,7 +439,7 @@ namespace MWWorld { ESM::CellRef &ref = const_cast(*it); - loadRef (ref, store); + loadRef (ref, false, store); } } @@ -466,32 +468,32 @@ namespace MWWorld return Ptr(); } - void CellStore::loadRef (ESM::CellRef& ref, const ESMStore& store) + void CellStore::loadRef (ESM::CellRef& ref, bool deleted, const ESMStore& store) { Misc::StringUtils::toLower (ref.mRefID); switch (store.find (ref.mRefID)) { - case ESM::REC_ACTI: mActivators.load(ref, store); break; - case ESM::REC_ALCH: mPotions.load(ref,store); break; - case ESM::REC_APPA: mAppas.load(ref, store); break; - case ESM::REC_ARMO: mArmors.load(ref, store); break; - case ESM::REC_BOOK: mBooks.load(ref, store); break; - case ESM::REC_CLOT: mClothes.load(ref, store); break; - case ESM::REC_CONT: mContainers.load(ref, store); break; - case ESM::REC_CREA: mCreatures.load(ref, store); break; - case ESM::REC_DOOR: mDoors.load(ref, store); break; - case ESM::REC_INGR: mIngreds.load(ref, store); break; - case ESM::REC_LEVC: mCreatureLists.load(ref, store); break; - case ESM::REC_LEVI: mItemLists.load(ref, store); break; - case ESM::REC_LIGH: mLights.load(ref, store); break; - case ESM::REC_LOCK: mLockpicks.load(ref, store); break; - case ESM::REC_MISC: mMiscItems.load(ref, store); break; - case ESM::REC_NPC_: mNpcs.load(ref, store); break; - case ESM::REC_PROB: mProbes.load(ref, store); break; - case ESM::REC_REPA: mRepairs.load(ref, store); break; - case ESM::REC_STAT: mStatics.load(ref, store); break; - case ESM::REC_WEAP: mWeapons.load(ref, store); break; + case ESM::REC_ACTI: mActivators.load(ref, deleted, store); break; + case ESM::REC_ALCH: mPotions.load(ref, deleted,store); break; + case ESM::REC_APPA: mAppas.load(ref, deleted, store); break; + case ESM::REC_ARMO: mArmors.load(ref, deleted, store); break; + case ESM::REC_BOOK: mBooks.load(ref, deleted, store); break; + case ESM::REC_CLOT: mClothes.load(ref, deleted, store); break; + case ESM::REC_CONT: mContainers.load(ref, deleted, store); break; + case ESM::REC_CREA: mCreatures.load(ref, deleted, store); break; + case ESM::REC_DOOR: mDoors.load(ref, deleted, store); break; + case ESM::REC_INGR: mIngreds.load(ref, deleted, store); break; + case ESM::REC_LEVC: mCreatureLists.load(ref, deleted, store); break; + case ESM::REC_LEVI: mItemLists.load(ref, deleted, store); break; + case ESM::REC_LIGH: mLights.load(ref, deleted, store); break; + case ESM::REC_LOCK: mLockpicks.load(ref, deleted, store); break; + case ESM::REC_MISC: mMiscItems.load(ref, deleted, store); break; + case ESM::REC_NPC_: mNpcs.load(ref, deleted, store); break; + case ESM::REC_PROB: mProbes.load(ref, deleted, store); break; + case ESM::REC_REPA: mRepairs.load(ref, deleted, store); break; + case ESM::REC_STAT: mStatics.load(ref, deleted, store); break; + case ESM::REC_WEAP: mWeapons.load(ref, deleted, store); break; case 0: std::cerr << "Cell reference " + ref.mRefID + " not found!\n"; break; diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 5caa4eeea..f879343d9 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -214,7 +214,7 @@ namespace MWWorld void loadRefs(const MWWorld::ESMStore &store, std::vector &esm); - void loadRef (ESM::CellRef& ref, const ESMStore& store); + void loadRef (ESM::CellRef& ref, bool deleted, const ESMStore& store); ///< Make case-adjustments to \a ref and insert it into the respective container. /// /// Invalid \a ref objects are silently dropped. diff --git a/apps/openmw/mwworld/globals.cpp b/apps/openmw/mwworld/globals.cpp index 668a33f09..87070a712 100644 --- a/apps/openmw/mwworld/globals.cpp +++ b/apps/openmw/mwworld/globals.cpp @@ -92,7 +92,11 @@ namespace MWWorld if (type==ESM::REC_GLOB) { ESM::Global global; - global.load(reader); + bool isDeleted = false; + + // This readRecord() method is used when reading a saved game. + // Deleted globals can't appear there, so isDeleted will be ignored here. + global.load(reader, isDeleted); Misc::StringUtils::toLower(global.mId); Collection::iterator iter = mVariables.find (global.mId); diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 55fb43e00..cd9290bfc 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -66,7 +66,9 @@ namespace MWWorld void IndexedStore::load(ESM::ESMReader &esm) { T record; - record.load(esm); + bool isDeleted = false; + + record.load(esm, isDeleted); // Try to overwrite existing record std::pair ret = mStatic.insert(std::make_pair(record.mIndex, record)); @@ -187,14 +189,16 @@ namespace MWWorld RecordId Store::load(ESM::ESMReader &esm) { T record; - record.load(esm); + bool isDeleted = false; + + record.load(esm, isDeleted); Misc::StringUtils::toLower(record.mId); std::pair inserted = mStatic.insert(std::make_pair(record.mId, record)); if (inserted.second) mShared.push_back(&inserted.first->second); - return RecordId(record.mId, record.mIsDeleted); + return RecordId(record.mId, isDeleted); } template void Store::setUp() @@ -324,10 +328,12 @@ namespace MWWorld RecordId Store::read(ESM::ESMReader& reader) { T record; - record.load (reader); + bool isDeleted = false; + + record.load (reader, isDeleted); insert (record); - return RecordId(record.mId, record.mIsDeleted); + return RecordId(record.mId, isDeleted); } // LandTexture @@ -370,7 +376,9 @@ namespace MWWorld RecordId Store::load(ESM::ESMReader &esm, size_t plugin) { ESM::LandTexture lt; - lt.load(esm); + bool isDeleted = false; + + lt.load(esm, isDeleted); // Make sure we have room for the structure if (plugin >= mStatic.size()) { @@ -383,7 +391,7 @@ namespace MWWorld // Store it ltexl[lt.mIndex] = lt; - return RecordId(lt.mId, lt.mIsDeleted); + return RecordId(lt.mId, isDeleted); } RecordId Store::load(ESM::ESMReader &esm) { @@ -449,7 +457,9 @@ namespace MWWorld RecordId Store::load(ESM::ESMReader &esm) { ESM::Land *ptr = new ESM::Land(); - ptr->load(esm); + bool isDeleted = false; + + ptr->load(esm, isDeleted); // Same area defined in multiple plugins? -> last plugin wins // Can't use search() because we aren't sorted yet - is there any other way to speed this up? @@ -465,7 +475,7 @@ namespace MWWorld mStatic.push_back(ptr); - return RecordId(); // No ID and can't be deleted (for now) + return RecordId("", isDeleted); } void Store::setUp() { @@ -617,12 +627,12 @@ namespace MWWorld // All cells have a name record, even nameless exterior cells. ESM::Cell cell; - cell.loadName(esm); - std::string idLower = Misc::StringUtils::lowerCase(cell.mName); + bool isDeleted = false; - // Load the (x,y) coordinates of the cell, if it is an exterior cell, + // Load the (x,y) coordinates of the cell, if it is an exterior cell, // so we can find the cell we need to merge with - cell.loadData(esm); + cell.loadNameAndData(esm, isDeleted); + std::string idLower = Misc::StringUtils::lowerCase(cell.mName); if(cell.mData.mFlags & ESM::Cell::Interior) { @@ -690,7 +700,8 @@ namespace MWWorld mExt[std::make_pair(cell.mData.mX, cell.mData.mY)] = cell; } } - return RecordId("", cell.mIsDeleted); + + return RecordId(cell.mName, isDeleted); } Store::iterator Store::intBegin() const { @@ -849,7 +860,9 @@ namespace MWWorld RecordId Store::load(ESM::ESMReader &esm) { ESM::Pathgrid pathgrid; - pathgrid.load(esm); + bool isDeleted = false; + + pathgrid.load(esm, isDeleted); // Unfortunately the Pathgrid record model does not specify whether the pathgrid belongs to an interior or exterior cell. // For interior cells, mCell is the cell name, but for exterior cells it is either the cell name or if that doesn't exist, the cell's region name. @@ -872,7 +885,7 @@ namespace MWWorld ret.first->second = pathgrid; } - return RecordId(); // No ID and can't be deleted (for now) + return RecordId("", isDeleted); } size_t Store::getSize() const { @@ -1027,22 +1040,24 @@ namespace MWWorld inline RecordId Store::load(ESM::ESMReader &esm) { // The original letter case of a dialogue ID is saved, because it's printed ESM::Dialogue dialogue; + bool isDeleted = false; + dialogue.loadId(esm); std::string idLower = Misc::StringUtils::lowerCase(dialogue.mId); std::map::iterator found = mStatic.find(idLower); if (found == mStatic.end()) { - dialogue.loadData(esm); + dialogue.loadData(esm, isDeleted); mStatic.insert(std::make_pair(idLower, dialogue)); } else { - found->second.loadData(esm); + found->second.loadData(esm, isDeleted); dialogue = found->second; } - return RecordId(dialogue.mId, dialogue.mIsDeleted); + return RecordId(dialogue.mId, isDeleted); } @@ -1052,7 +1067,9 @@ namespace MWWorld template <> inline RecordId Store::load(ESM::ESMReader &esm) { ESM::Script script; - script.load(esm); + bool isDeleted = false; + + script.load(esm, isDeleted); Misc::StringUtils::toLower(script.mId); std::pair inserted = mStatic.insert(std::make_pair(script.mId, script)); @@ -1061,7 +1078,7 @@ namespace MWWorld else inserted.first->second = script; - return RecordId(script.mId, script.mIsDeleted); + return RecordId(script.mId, isDeleted); } @@ -1072,7 +1089,9 @@ namespace MWWorld inline RecordId Store::load(ESM::ESMReader &esm) { ESM::StartScript script; - script.load(esm); + bool isDeleted = false; + + script.load(esm, isDeleted); Misc::StringUtils::toLower(script.mId); std::pair inserted = mStatic.insert(std::make_pair(script.mId, script)); @@ -1081,36 +1100,7 @@ namespace MWWorld else inserted.first->second = script; - return RecordId(script.mId); - } - - // GameSetting - // Need to specialize load() and read() methods, because GameSetting can't - // be deleted (has no mIsDeleted flag) - //========================================================================= - - template <> - inline RecordId Store::load(ESM::ESMReader &reader) - { - ESM::GameSetting setting; - setting.load(reader); - Misc::StringUtils::toLower(setting.mId); - - std::pair inserted = mStatic.insert(std::make_pair(setting.mId, setting)); - if (inserted.second) - mShared.push_back(&inserted.first->second); - - return RecordId(setting.mId); - } - - template <> - inline RecordId Store::read(ESM::ESMReader &reader) - { - ESM::GameSetting setting; - setting.load(reader); - insert(setting); - - return RecordId(setting.mId); + return RecordId(script.mId, isDeleted); } } From 13bb6be2383c808084eabed0cb1bfb3b9749e55a Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 21 Jul 2015 20:25:43 +0300 Subject: [PATCH 42/49] Load methods (for ESM records) accept a deleted flag in OpenCS --- apps/opencs/model/doc/savingstages.cpp | 31 ++++-------- apps/opencs/model/doc/savingstages.hpp | 3 +- apps/opencs/model/world/cell.cpp | 6 +-- apps/opencs/model/world/cell.hpp | 2 +- apps/opencs/model/world/data.cpp | 6 ++- apps/opencs/model/world/idcollection.cpp | 3 -- apps/opencs/model/world/idcollection.hpp | 13 +++-- apps/opencs/model/world/infocollection.cpp | 6 ++- apps/opencs/model/world/land.cpp | 5 +- apps/opencs/model/world/land.hpp | 2 +- apps/opencs/model/world/landtexture.cpp | 8 +--- apps/opencs/model/world/landtexture.hpp | 2 +- apps/opencs/model/world/pathgrid.cpp | 15 ++---- apps/opencs/model/world/pathgrid.hpp | 5 +- apps/opencs/model/world/record.cpp | 48 ------------------- apps/opencs/model/world/record.hpp | 39 --------------- apps/opencs/model/world/refcollection.cpp | 5 +- apps/opencs/model/world/refiddata.hpp | 11 +++-- apps/opencs/model/world/subcellcollection.hpp | 7 +-- 19 files changed, 56 insertions(+), 161 deletions(-) delete mode 100644 apps/opencs/model/world/idcollection.cpp diff --git a/apps/opencs/model/doc/savingstages.cpp b/apps/opencs/model/doc/savingstages.cpp index dbfa4651b..87f7ea16a 100644 --- a/apps/opencs/model/doc/savingstages.cpp +++ b/apps/opencs/model/doc/savingstages.cpp @@ -107,10 +107,8 @@ void CSMDoc::WriteDialogueCollectionStage::perform (int stage, Messages& message { // if the topic is deleted, we do not need to bother with INFO records. ESM::Dialogue dialogue = topic.get(); - dialogue.mIsDeleted = true; - writer.startRecord(dialogue.sRecordId); - dialogue.save(writer); + dialogue.save(writer, true); writer.endRecord(dialogue.sRecordId); return; } @@ -121,7 +119,7 @@ void CSMDoc::WriteDialogueCollectionStage::perform (int stage, Messages& message for (CSMWorld::InfoCollection::RecordConstIterator iter (range.first); iter!=range.second; ++iter) { - if (topic.isModified() || iter->mState == CSMWorld::RecordBase::State_Deleted) + if (iter->isModified() || iter->mState == CSMWorld::RecordBase::State_Deleted) { infoModified = true; break; @@ -131,7 +129,6 @@ void CSMDoc::WriteDialogueCollectionStage::perform (int stage, Messages& message if (topic.isModified() || infoModified) { ESM::Dialogue dialogue = topic.get(); - writer.startRecord (dialogue.sRecordId); dialogue.save (writer); writer.endRecord (dialogue.sRecordId); @@ -143,7 +140,6 @@ void CSMDoc::WriteDialogueCollectionStage::perform (int stage, Messages& message { ESM::DialInfo info = iter->get(); info.mId = info.mId.substr (info.mId.find_last_of ('#')+1); - info.mIsDeleted = (iter->mState == CSMWorld::RecordBase::State_Deleted); info.mPrev = ""; if (iter!=range.first) @@ -164,7 +160,7 @@ void CSMDoc::WriteDialogueCollectionStage::perform (int stage, Messages& message } writer.startRecord (info.sRecordId); - info.save (writer); + info.save (writer, iter->mState == CSMWorld::RecordBase::State_Deleted); writer.endRecord (info.sRecordId); } } @@ -213,9 +209,7 @@ void CSMDoc::CollectionReferencesStage::perform (int stage, Messages& messages) const CSMWorld::Record& record = mDocument.getData().getReferences().getRecord (i); - if (record.mState==CSMWorld::RecordBase::State_Deleted || - record.mState==CSMWorld::RecordBase::State_Modified || - record.mState==CSMWorld::RecordBase::State_ModifiedOnly) + if (record.isModified() || record.mState == CSMWorld::RecordBase::State_Deleted) { std::string cellId = record.get().mOriginalCell.empty() ? record.get().mCell : record.get().mOriginalCell; @@ -284,8 +278,7 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages) stream >> ignore >> cellRecord.mData.mX >> cellRecord.mData.mY; } - cellRecord.mIsDeleted = (cell.mState == CSMWorld::RecordBase::State_Deleted); - cellRecord.save (writer); + cellRecord.save (writer, cell.mState == CSMWorld::RecordBase::State_Deleted); // write references if (references!=mState.getSubRecords().end()) @@ -326,8 +319,7 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages) writer.writeHNT ("CNDT", moved.mTarget, 8); } - refRecord.mIsDeleted = (ref.mState == CSMWorld::RecordBase::State_Deleted); - refRecord.save (writer); + refRecord.save (writer, false, false, ref.mState == CSMWorld::RecordBase::State_Deleted); } } } @@ -366,9 +358,8 @@ void CSMDoc::WritePathgridCollectionStage::perform (int stage, Messages& message else record.mCell = record.mId; - record.mIsDeleted = (pathgrid.mState == CSMWorld::RecordBase::State_Deleted); writer.startRecord (record.sRecordId); - record.save (writer); + record.save (writer, pathgrid.mState == CSMWorld::RecordBase::State_Deleted); writer.endRecord (record.sRecordId); } } @@ -393,10 +384,8 @@ void CSMDoc::WriteLandCollectionStage::perform (int stage, Messages& messages) if (land.isModified() || land.mState == CSMWorld::RecordBase::State_Deleted) { CSMWorld::Land record = land.get(); - - record.mLand->mIsDeleted = (land.mState == CSMWorld::RecordBase::State_Deleted); writer.startRecord (record.mLand->sRecordId); - record.mLand->save (writer); + record.mLand->save (writer, land.mState == CSMWorld::RecordBase::State_Deleted); writer.endRecord (record.mLand->sRecordId); } } @@ -421,10 +410,8 @@ void CSMDoc::WriteLandTextureCollectionStage::perform (int stage, Messages& mess if (landTexture.isModified() || landTexture.mState == CSMWorld::RecordBase::State_Deleted) { CSMWorld::LandTexture record = landTexture.get(); - record.mIsDeleted = (landTexture.mState == CSMWorld::RecordBase::State_Deleted); - writer.startRecord (record.sRecordId); - record.save (writer); + record.save (writer, landTexture.mState == CSMWorld::RecordBase::State_Deleted); writer.endRecord (record.sRecordId); } } diff --git a/apps/opencs/model/doc/savingstages.hpp b/apps/opencs/model/doc/savingstages.hpp index a7d9704b0..64afd0dd8 100644 --- a/apps/opencs/model/doc/savingstages.hpp +++ b/apps/opencs/model/doc/savingstages.hpp @@ -108,9 +108,8 @@ namespace CSMDoc state == CSMWorld::RecordBase::State_ModifiedOnly || state == CSMWorld::RecordBase::State_Deleted) { - CSMWorld::setRecordDeleted (record, state == CSMWorld::RecordBase::State_Deleted); writer.startRecord (record.sRecordId); - record.save (writer); + record.save (writer, state == CSMWorld::RecordBase::State_Deleted); writer.endRecord (record.sRecordId); } } diff --git a/apps/opencs/model/world/cell.cpp b/apps/opencs/model/world/cell.cpp index 8816cd35e..be64061be 100644 --- a/apps/opencs/model/world/cell.cpp +++ b/apps/opencs/model/world/cell.cpp @@ -3,12 +3,12 @@ #include -void CSMWorld::Cell::load (ESM::ESMReader &esm) +void CSMWorld::Cell::load (ESM::ESMReader &esm, bool &isDeleted) { - ESM::Cell::load (esm, false); + ESM::Cell::load (esm, isDeleted, false); mId = mName; - if (!(mData.mFlags & Interior)) + if (isExterior()) { std::ostringstream stream; stream << "#" << mData.mX << " " << mData.mY; diff --git a/apps/opencs/model/world/cell.hpp b/apps/opencs/model/world/cell.hpp index f393e2cf9..160610874 100644 --- a/apps/opencs/model/world/cell.hpp +++ b/apps/opencs/model/world/cell.hpp @@ -16,7 +16,7 @@ namespace CSMWorld { std::string mId; - void load (ESM::ESMReader &esm); + void load (ESM::ESMReader &esm, bool &isDeleted); }; } diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 91ccda73c..32255cb1a 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -989,9 +989,11 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Messages& messages) case ESM::REC_DIAL: { ESM::Dialogue record; - record.load (*mReader); + bool isDeleted = false; - if (record.mIsDeleted) + record.load (*mReader, isDeleted); + + if (isDeleted) { // record vector can be shuffled around which would make pointer to record invalid mDialogue = 0; diff --git a/apps/opencs/model/world/idcollection.cpp b/apps/opencs/model/world/idcollection.cpp deleted file mode 100644 index 9571ed773..000000000 --- a/apps/opencs/model/world/idcollection.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "idcollection.hpp" - - diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 9d3ec990e..c79b4e020 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -12,7 +12,7 @@ namespace CSMWorld template > class IdCollection : public Collection { - virtual void loadRecord (ESXRecordT& record, ESM::ESMReader& reader); + virtual void loadRecord (ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted); public: @@ -34,21 +34,24 @@ namespace CSMWorld template void IdCollection::loadRecord (ESXRecordT& record, - ESM::ESMReader& reader) + ESM::ESMReader& reader, + bool& isDeleted) { - record.load (reader); + record.load (reader, isDeleted); } template int IdCollection::load (ESM::ESMReader& reader, bool base) { ESXRecordT record; - loadRecord (record, reader); + bool isDeleted = false; + + loadRecord (record, reader, isDeleted); std::string id = IdAccessorT().getId (record); int index = this->searchId (id); - if (isRecordDeleted(record)) + if (isDeleted) { if (index==-1) { diff --git a/apps/opencs/model/world/infocollection.cpp b/apps/opencs/model/world/infocollection.cpp index 665b497d0..81f3ac143 100644 --- a/apps/opencs/model/world/infocollection.cpp +++ b/apps/opencs/model/world/infocollection.cpp @@ -108,10 +108,12 @@ bool CSMWorld::InfoCollection::reorderRows (int baseIndex, const std::vectorload(esm); + mLand->load(esm, isDeleted); std::ostringstream stream; stream << "#" << mLand->mX << " " << mLand->mY; - mId = stream.str(); } diff --git a/apps/opencs/model/world/land.hpp b/apps/opencs/model/world/land.hpp index e97a2d7dd..c006f2a4d 100644 --- a/apps/opencs/model/world/land.hpp +++ b/apps/opencs/model/world/land.hpp @@ -20,7 +20,7 @@ namespace CSMWorld std::string mId; /// Loads the metadata and ID - void load (ESM::ESMReader &esm); + void load (ESM::ESMReader &esm, bool &isDeleted); void blank(); }; diff --git a/apps/opencs/model/world/landtexture.cpp b/apps/opencs/model/world/landtexture.cpp index 4725866a5..9e8dcff9f 100644 --- a/apps/opencs/model/world/landtexture.cpp +++ b/apps/opencs/model/world/landtexture.cpp @@ -4,17 +4,13 @@ namespace CSMWorld { - - void LandTexture::load(ESM::ESMReader &esm) + void LandTexture::load(ESM::ESMReader &esm, bool &isDeleted) { - ESM::LandTexture::load(esm); - + ESM::LandTexture::load(esm, isDeleted); int plugin = esm.getIndex(); std::ostringstream stream; - stream << mIndex << "_" << plugin; - mId = stream.str(); } diff --git a/apps/opencs/model/world/landtexture.hpp b/apps/opencs/model/world/landtexture.hpp index b13903186..e18f0277c 100644 --- a/apps/opencs/model/world/landtexture.hpp +++ b/apps/opencs/model/world/landtexture.hpp @@ -15,7 +15,7 @@ namespace CSMWorld { std::string mId; - void load (ESM::ESMReader &esm); + void load (ESM::ESMReader &esm, bool &isDeleted); }; } diff --git a/apps/opencs/model/world/pathgrid.cpp b/apps/opencs/model/world/pathgrid.cpp index 5c66e7d8e..c995bd8f0 100644 --- a/apps/opencs/model/world/pathgrid.cpp +++ b/apps/opencs/model/world/pathgrid.cpp @@ -4,33 +4,28 @@ #include -void CSMWorld::Pathgrid::load (ESM::ESMReader &esm, const IdCollection& cells) +void CSMWorld::Pathgrid::load (ESM::ESMReader &esm, bool &isDeleted, const IdCollection& cells) { - load (esm); + load (esm, isDeleted); // correct ID if (!mId.empty() && mId[0]!='#' && cells.searchId (mId)==-1) { std::ostringstream stream; - stream << "#" << mData.mX << " " << mData.mY; - mId = stream.str(); } } -void CSMWorld::Pathgrid::load (ESM::ESMReader &esm) +void CSMWorld::Pathgrid::load (ESM::ESMReader &esm, bool &isDeleted) { - ESM::Pathgrid::load (esm); + ESM::Pathgrid::load (esm, isDeleted); + mId = mCell; if (mCell.empty()) { std::ostringstream stream; - stream << "#" << mData.mX << " " << mData.mY; - mId = stream.str(); } - else - mId = mCell; } diff --git a/apps/opencs/model/world/pathgrid.hpp b/apps/opencs/model/world/pathgrid.hpp index 7e7b7c3bb..22d01b071 100644 --- a/apps/opencs/model/world/pathgrid.hpp +++ b/apps/opencs/model/world/pathgrid.hpp @@ -20,9 +20,8 @@ namespace CSMWorld { std::string mId; - void load (ESM::ESMReader &esm, const IdCollection& cells); - - void load (ESM::ESMReader &esm); + void load (ESM::ESMReader &esm, bool &isDeleted, const IdCollection& cells); + void load (ESM::ESMReader &esm, bool &isDeleted); }; } diff --git a/apps/opencs/model/world/record.cpp b/apps/opencs/model/world/record.cpp index 7563c4cfd..ef2f4d320 100644 --- a/apps/opencs/model/world/record.cpp +++ b/apps/opencs/model/world/record.cpp @@ -19,51 +19,3 @@ bool CSMWorld::RecordBase::isModified() const { return mState==State_Modified || mState==State_ModifiedOnly; } - -template<> -bool CSMWorld::isRecordDeleted(const CSMWorld::Land &land) -{ - return land.mLand->mIsDeleted; -} - -template<> -bool CSMWorld::isRecordDeleted(const ESM::GameSetting &setting) -{ - return false; -} - -template<> -bool CSMWorld::isRecordDeleted(const ESM::MagicEffect &effect) -{ - return false; -} - -template<> -bool CSMWorld::isRecordDeleted(const ESM::Skill &skill) -{ - return false; -} - -template<> -void CSMWorld::setRecordDeleted(CSMWorld::Land &land, bool isDeleted) -{ - land.mLand->mIsDeleted = isDeleted; -} - -template<> -void CSMWorld::setRecordDeleted(ESM::GameSetting &setting, bool isDeleted) -{ - // GameSetting doesn't have a Deleted flag -} - -template<> -void CSMWorld::setRecordDeleted(ESM::MagicEffect &effect, bool isDeleted) -{ - // MagicEffect doesn't have a Deleted flag -} - -template<> -void CSMWorld::setRecordDeleted(ESM::Skill &skill, bool isDeleted) -{ - // Skill doesn't have a Deleted flag -} diff --git a/apps/opencs/model/world/record.hpp b/apps/opencs/model/world/record.hpp index 8e39cd705..3362f9f96 100644 --- a/apps/opencs/model/world/record.hpp +++ b/apps/opencs/model/world/record.hpp @@ -3,12 +3,6 @@ #include -#include -#include -#include - -#include "land.hpp" - namespace CSMWorld { struct RecordBase @@ -160,39 +154,6 @@ namespace CSMWorld mState = State_Erased; } } - - // Not all records can be deleted (may be changed in the future), - // so we need to use a separate method to check whether a record is deleted or not. - template - bool isRecordDeleted(const ESXRecordT &record) - { - return record.mIsDeleted; - } - - template<> - bool isRecordDeleted(const Land &land); - template<> - bool isRecordDeleted(const ESM::GameSetting &setting); - template<> - bool isRecordDeleted(const ESM::MagicEffect &effect); - template<> - bool isRecordDeleted(const ESM::Skill &skill); - - // ... and also a separate method for setting the deleted flag of a record - template - void setRecordDeleted(ESXRecordT &record, bool isDeleted = false) - { - record.mIsDeleted = isDeleted; - } - - template<> - void setRecordDeleted(Land &land, bool isDeleted); - template<> - void setRecordDeleted(ESM::GameSetting &setting, bool isDeleted); - template<> - void setRecordDeleted(ESM::MagicEffect &effect, bool isDeleted); - template<> - void setRecordDeleted(ESM::Skill &skill, bool isDeleted); } #endif diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp index d32f21d0a..39af9b408 100644 --- a/apps/opencs/model/world/refcollection.cpp +++ b/apps/opencs/model/world/refcollection.cpp @@ -21,9 +21,10 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool CellRef ref; ESM::MovedCellRef mref; + bool isDeleted = false; // hack to initialise mindex - while (!(mref.mRefNum.mIndex = 0) && ESM::Cell::getNextRef(reader, ref, true, &mref)) + while (!(mref.mRefNum.mIndex = 0) && ESM::Cell::getNextRef(reader, ref, isDeleted, true, &mref)) { // Keep mOriginalCell empty when in modified (as an indicator that the // original cell will always be equal the current cell). @@ -79,7 +80,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool break; } - if (ref.mIsDeleted) + if (isDeleted) { if (iter==cache.end()) { diff --git a/apps/opencs/model/world/refiddata.hpp b/apps/opencs/model/world/refiddata.hpp index 195244ba8..0c9239d59 100644 --- a/apps/opencs/model/world/refiddata.hpp +++ b/apps/opencs/model/world/refiddata.hpp @@ -129,7 +129,9 @@ namespace CSMWorld int RefIdDataContainer::load (ESM::ESMReader& reader, bool base) { RecordT record; - record.load(reader); + bool isDeleted = false; + + record.load(reader, isDeleted); int index = 0; int numRecords = static_cast(mContainer.size()); @@ -141,7 +143,7 @@ namespace CSMWorld } } - if (record.mIsDeleted) + if (isDeleted) { if (index == numRecords) { @@ -197,13 +199,12 @@ namespace CSMWorld void RefIdDataContainer::save (int index, ESM::ESMWriter& writer) const { Record record = mContainer.at(index); - RecordT esmRecord = record.get(); if (record.isModified() || record.mState == RecordBase::State_Deleted) { - esmRecord.mIsDeleted = (record.mState == RecordBase::State_Deleted); + RecordT esmRecord = record.get(); writer.startRecord(esmRecord.sRecordId); - esmRecord.save(writer); + esmRecord.save(writer, record.mState == RecordBase::State_Deleted); writer.endRecord(esmRecord.sRecordId); } } diff --git a/apps/opencs/model/world/subcellcollection.hpp b/apps/opencs/model/world/subcellcollection.hpp index df1f8a12e..496cb0643 100644 --- a/apps/opencs/model/world/subcellcollection.hpp +++ b/apps/opencs/model/world/subcellcollection.hpp @@ -20,7 +20,7 @@ namespace CSMWorld { const IdCollection& mCells; - virtual void loadRecord (ESXRecordT& record, ESM::ESMReader& reader); + virtual void loadRecord (ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted); public: @@ -29,9 +29,10 @@ namespace CSMWorld template void SubCellCollection::loadRecord (ESXRecordT& record, - ESM::ESMReader& reader) + ESM::ESMReader& reader, + bool& isDeleted) { - record.load (reader, mCells); + record.load (reader, isDeleted, mCells); } template From 8243fb2479a18cd47e03e9ffcff87020a9c1446f Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 21 Jul 2015 20:47:02 +0300 Subject: [PATCH 43/49] Load methods (for ESM records) accept a deleted flag in ESMTool --- apps/esmtool/esmtool.cpp | 14 ++++---- apps/esmtool/record.cpp | 74 ++++++++++++++++++++-------------------- apps/esmtool/record.hpp | 9 +++-- 3 files changed, 52 insertions(+), 45 deletions(-) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index c2507ccdc..be90afec3 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -27,7 +27,8 @@ struct ESMData std::vector masters; std::deque mRecords; - std::map > mCellRefs; + // Value: (Reference, Deleted flag) + std::map > > mCellRefs; std::map mRecordStats; static const std::set sLabeledRec; @@ -251,10 +252,11 @@ void loadCell(ESM::Cell &cell, ESM::ESMReader &esm, Arguments& info) ESM::CellRef ref; if(!quiet) std::cout << " References:\n"; - while(cell.getNextRef(esm, ref)) + bool deleted = false; + while(cell.getNextRef(esm, ref, deleted)) { if (save) { - info.data.mCellRefs[&cell].push_back(ref); + info.data.mCellRefs[&cell].push_back(std::make_pair(ref, deleted)); } if(quiet) continue; @@ -269,7 +271,7 @@ void loadCell(ESM::Cell &cell, ESM::ESMReader &esm, Arguments& info) std::cout << " Uses/health: '" << ref.mChargeInt << "'\n"; std::cout << " Gold value: '" << ref.mGoldValue << "'\n"; std::cout << " Blocked: '" << static_cast(ref.mReferenceBlocked) << "'" << std::endl; - std::cout << " Deleted: " << ref.mIsDeleted << std::endl; + std::cout << " Deleted: " << deleted << std::endl; if (!ref.mKey.empty()) std::cout << " Key: '" << ref.mKey << "'" << std::endl; } @@ -497,11 +499,11 @@ int clone(Arguments& info) if (name.val == ESM::REC_CELL) { ESM::Cell *ptr = &record->cast()->get(); if (!info.data.mCellRefs[ptr].empty()) { - typedef std::deque RefList; + typedef std::deque > RefList; RefList &refs = info.data.mCellRefs[ptr]; for (RefList::iterator refIt = refs.begin(); refIt != refs.end(); ++refIt) { - refIt->save(esm); + refIt->first.save(esm, refIt->second); } } } diff --git a/apps/esmtool/record.cpp b/apps/esmtool/record.cpp index a03318262..728c5dc91 100644 --- a/apps/esmtool/record.cpp +++ b/apps/esmtool/record.cpp @@ -405,7 +405,7 @@ void Record::print() std::cout << " Name: " << mData.mName << std::endl; std::cout << " Model: " << mData.mModel << std::endl; std::cout << " Script: " << mData.mScript << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -420,7 +420,7 @@ void Record::print() std::cout << " Value: " << mData.mData.mValue << std::endl; std::cout << " AutoCalc: " << mData.mData.mAutoCalc << std::endl; printEffectList(mData.mEffects); - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -449,7 +449,7 @@ void Record::print() if (pit->mFemale != "") std::cout << " Female Name: " << pit->mFemale << std::endl; } - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -464,7 +464,7 @@ void Record::print() std::cout << " Weight: " << mData.mData.mWeight << std::endl; std::cout << " Value: " << mData.mData.mValue << std::endl; std::cout << " Quality: " << mData.mData.mQuality << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -478,7 +478,7 @@ void Record::print() std::cout << " Part: " << meshPartLabel(mData.mData.mPart) << " (" << (int)mData.mData.mPart << ")" << std::endl; std::cout << " Vampire: " << (int)mData.mData.mVampire << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -507,7 +507,7 @@ void Record::print() { std::cout << " Text: [skipped]" << std::endl; } - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -519,7 +519,7 @@ void Record::print() std::vector::iterator pit; for (pit = mData.mPowers.mList.begin(); pit != mData.mPowers.mList.end(); ++pit) std::cout << " Power: " << *pit << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -548,7 +548,7 @@ void Record::print() std::cout << " Map Color: " << boost::format("0x%08X") % mData.mMapColor << std::endl; std::cout << " Water Level Int: " << mData.mWaterInt << std::endl; std::cout << " RefId counter: " << mData.mRefNumCounter << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } @@ -571,7 +571,7 @@ void Record::print() for (int i = 0; i != 5; i++) std::cout << " Major Skill: " << skillLabel(mData.mData.mSkills[i][1]) << " (" << mData.mData.mSkills[i][1] << ")" << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -598,7 +598,7 @@ void Record::print() if (pit->mFemale != "") std::cout << " Female Name: " << pit->mFemale << std::endl; } - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -614,7 +614,7 @@ void Record::print() for (cit = mData.mInventory.mList.begin(); cit != mData.mInventory.mList.end(); ++cit) std::cout << " Inventory: Count: " << boost::format("%4d") % cit->mCount << " Item: " << cit->mItem.toString() << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -681,7 +681,7 @@ void Record::print() std::vector::iterator pit; for (pit = mData.mAiPackage.mList.begin(); pit != mData.mAiPackage.mList.end(); ++pit) printAIPackage(*pit); - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -689,7 +689,7 @@ void Record::print() { std::cout << " Type: " << dialogTypeLabel(mData.mType) << " (" << (int)mData.mType << ")" << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; // Sadly, there are no DialInfos, because the loader dumps as it // loads, rather than loading and then dumping. :-( Anyone mind if // I change this? @@ -706,7 +706,7 @@ void Record::print() std::cout << " Script: " << mData.mScript << std::endl; std::cout << " OpenSound: " << mData.mOpenSound << std::endl; std::cout << " CloseSound: " << mData.mCloseSound << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -718,7 +718,7 @@ void Record::print() std::cout << " Charge: " << mData.mData.mCharge << std::endl; std::cout << " AutoCalc: " << mData.mData.mAutocalc << std::endl; printEffectList(mData.mEffects); - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -752,14 +752,14 @@ void Record::print() std::map::iterator rit; for (rit = mData.mReactions.begin(); rit != mData.mReactions.end(); ++rit) std::cout << " Reaction: " << rit->second << " = " << rit->first << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> void Record::print() { std::cout << " " << mData.mValue << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -826,7 +826,7 @@ void Record::print() std::cout << " Result Script: [skipped]" << std::endl; } } - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -850,7 +850,7 @@ void Record::print() std::cout << " Attribute: " << attributeLabel(mData.mData.mAttributes[i]) << " (" << mData.mData.mAttributes[i] << ")" << std::endl; } - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -873,7 +873,7 @@ void Record::print() std::cout << " Unknown2: " << mData.mLandData->mUnk2 << std::endl; } if (!wasLoaded) mData.unloadData(); - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -886,7 +886,7 @@ void Record::print() for (iit = mData.mList.begin(); iit != mData.mList.end(); ++iit) std::cout << " Creature: Level: " << iit->mLevel << " Creature: " << iit->mId << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -899,7 +899,7 @@ void Record::print() for (iit = mData.mList.begin(); iit != mData.mList.end(); ++iit) std::cout << " Inventory: Level: " << iit->mLevel << " Item: " << iit->mId << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -920,7 +920,7 @@ void Record::print() std::cout << " Duration: " << mData.mData.mTime << std::endl; std::cout << " Radius: " << mData.mData.mRadius << std::endl; std::cout << " Color: " << mData.mData.mColor << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -935,7 +935,7 @@ void Record::print() std::cout << " Value: " << mData.mData.mValue << std::endl; std::cout << " Quality: " << mData.mData.mQuality << std::endl; std::cout << " Uses: " << mData.mData.mUses << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -950,7 +950,7 @@ void Record::print() std::cout << " Value: " << mData.mData.mValue << std::endl; std::cout << " Quality: " << mData.mData.mQuality << std::endl; std::cout << " Uses: " << mData.mData.mUses << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -965,7 +965,7 @@ void Record::print() std::cout << " Value: " << mData.mData.mValue << std::endl; std::cout << " Quality: " << mData.mData.mQuality << std::endl; std::cout << " Uses: " << mData.mData.mUses << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -974,7 +974,7 @@ void Record::print() std::cout << " Id: " << mData.mId << std::endl; std::cout << " Index: " << mData.mIndex << std::endl; std::cout << " Texture: " << mData.mTexture << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -1025,7 +1025,7 @@ void Record::print() std::cout << " Weight: " << mData.mData.mWeight << std::endl; std::cout << " Value: " << mData.mData.mValue << std::endl; std::cout << " Is Key: " << mData.mData.mIsKey << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -1112,7 +1112,7 @@ void Record::print() for (pit = mData.mAiPackage.mList.begin(); pit != mData.mAiPackage.mList.end(); ++pit) printAIPackage(*pit); - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -1148,7 +1148,7 @@ void Record::print() i++; } - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -1190,7 +1190,7 @@ void Record::print() for (sit = mData.mPowers.mList.begin(); sit != mData.mPowers.mList.end(); ++sit) std::cout << " Power: " << *sit << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -1251,7 +1251,7 @@ void Record::print() std::cout << " Script: [skipped]" << std::endl; } - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -1275,7 +1275,7 @@ void Record::print() std::cout << " Sound: " << mData.mSound << std::endl; std::cout << " Type: " << soundTypeLabel(mData.mType) << " (" << mData.mType << ")" << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -1286,7 +1286,7 @@ void Record::print() if (mData.mData.mMinRange != 0 && mData.mData.mMaxRange != 0) std::cout << " Range: " << (int)mData.mData.mMinRange << " - " << (int)mData.mData.mMaxRange << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -1298,7 +1298,7 @@ void Record::print() std::cout << " Flags: " << spellFlags(mData.mData.mFlags) << std::endl; std::cout << " Cost: " << mData.mData.mCost << std::endl; printEffectList(mData.mEffects); - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -1306,7 +1306,7 @@ void Record::print() { std::cout << " Start Script: " << mData.mId << std::endl; std::cout << " Start Data: " << mData.mData << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> @@ -1347,7 +1347,7 @@ void Record::print() if (mData.mData.mThrust[0] != 0 && mData.mData.mThrust[1] != 0) std::cout << " Thrust: " << (int)mData.mData.mThrust[0] << "-" << (int)mData.mData.mThrust[1] << std::endl; - std::cout << " Deleted: " << mData.mIsDeleted << std::endl; + std::cout << " Deleted: " << mIsDeleted << std::endl; } template<> diff --git a/apps/esmtool/record.hpp b/apps/esmtool/record.hpp index a10fda40b..d0c113279 100644 --- a/apps/esmtool/record.hpp +++ b/apps/esmtool/record.hpp @@ -67,8 +67,13 @@ namespace EsmTool class Record : public RecordBase { T mData; + bool mIsDeleted; public: + Record() + : mIsDeleted(false) + {} + std::string getId() const { return mData.mId; } @@ -78,11 +83,11 @@ namespace EsmTool } void save(ESM::ESMWriter &esm) { - mData.save(esm); + mData.save(esm, mIsDeleted); } void load(ESM::ESMReader &esm) { - mData.load(esm); + mData.load(esm, mIsDeleted); } void print(); From 0c6ab6cc9449e14fe30d1f9baa3424b92eee9ba8 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 21 Jul 2015 21:49:36 +0300 Subject: [PATCH 44/49] Load methods (for ESM records) accept a deleted flag in ESSImporter --- apps/essimporter/converter.cpp | 4 +++- apps/essimporter/converter.hpp | 29 +++++++++++++++++++++------- apps/essimporter/importacdt.cpp | 3 ++- apps/essimporter/importinventory.cpp | 3 ++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/apps/essimporter/converter.cpp b/apps/essimporter/converter.cpp index 982753134..1d1942a3e 100644 --- a/apps/essimporter/converter.cpp +++ b/apps/essimporter/converter.cpp @@ -158,7 +158,9 @@ namespace ESSImport void ConvertCell::read(ESM::ESMReader &esm) { ESM::Cell cell; - cell.load(esm, false); + bool isDeleted = false; + + cell.load(esm, isDeleted, false); // I wonder what 0x40 does? if (cell.isExterior() && cell.mData.mFlags & 0x20) diff --git a/apps/essimporter/converter.hpp b/apps/essimporter/converter.hpp index 3bb5d2eae..1c6783539 100644 --- a/apps/essimporter/converter.hpp +++ b/apps/essimporter/converter.hpp @@ -54,6 +54,8 @@ public: void setContext(Context& context) { mContext = &context; } + /// @note The load method of ESM records accept the deleted flag as a parameter. + /// I don't know can the DELE sub-record appear in saved games, so the deleted flag will be ignored. virtual void read(ESM::ESMReader& esm) { } @@ -79,7 +81,9 @@ public: virtual void read(ESM::ESMReader& esm) { T record; - record.load(esm); + bool isDeleted = false; + + record.load(esm, isDeleted); mRecords[record.mId] = record; } @@ -103,7 +107,9 @@ public: virtual void read(ESM::ESMReader &esm) { ESM::NPC npc; - npc.load(esm); + bool isDeleted = false; + + npc.load(esm, isDeleted); if (npc.mId != "player") { // Handles changes to the NPC struct, but since there is no index here @@ -139,7 +145,9 @@ public: { // See comment in ConvertNPC ESM::Creature creature; - creature.load(esm); + bool isDeleted = false; + + creature.load(esm, isDeleted); mContext->mCreatures[Misc::StringUtils::lowerCase(creature.mId)] = creature; } }; @@ -154,7 +162,9 @@ public: virtual void read(ESM::ESMReader &esm) { ESM::Global global; - global.load(esm); + bool isDeleted = false; + + global.load(esm, isDeleted); if (Misc::StringUtils::ciEqual(global.mId, "gamehour")) mContext->mHour = global.mValue.getFloat(); if (Misc::StringUtils::ciEqual(global.mId, "day")) @@ -173,8 +183,9 @@ public: virtual void read(ESM::ESMReader &esm) { ESM::Class class_; - class_.load(esm); + bool isDeleted = false; + class_.load(esm, isDeleted); if (class_.mId == "NEWCLASSID_CHARGEN") mContext->mCustomPlayerClassName = class_.mName; @@ -188,7 +199,9 @@ public: virtual void read(ESM::ESMReader &esm) { ESM::Book book; - book.load(esm); + bool isDeleted = false; + + book.load(esm, isDeleted); if (book.mData.mSkillID == -1) mContext->mPlayer.mObject.mNpcStats.mUsedIds.push_back(Misc::StringUtils::lowerCase(book.mId)); @@ -365,7 +378,9 @@ public: virtual void read(ESM::ESMReader& esm) { ESM::Faction faction; - faction.load(esm); + bool isDeleted = false; + + faction.load(esm, isDeleted); std::string id = Misc::StringUtils::toLower(faction.mId); for (std::map::const_iterator it = faction.mReactions.begin(); it != faction.mReactions.end(); ++it) diff --git a/apps/essimporter/importacdt.cpp b/apps/essimporter/importacdt.cpp index 9d881515d..1602aa784 100644 --- a/apps/essimporter/importacdt.cpp +++ b/apps/essimporter/importacdt.cpp @@ -18,7 +18,8 @@ namespace ESSImport if (esm.isNextSub("MNAM")) esm.skipHSub(); - ESM::CellRef::loadData(esm); + bool isDeleted = false; + ESM::CellRef::loadData(esm, isDeleted); mHasACDT = false; if (esm.isNextSub("ACDT")) diff --git a/apps/essimporter/importinventory.cpp b/apps/essimporter/importinventory.cpp index d27cd5c8c..3ec640d3d 100644 --- a/apps/essimporter/importinventory.cpp +++ b/apps/essimporter/importinventory.cpp @@ -32,7 +32,8 @@ namespace ESSImport item.mSCRI.load(esm); // for XSOL and XCHG seen so far, but probably others too - item.ESM::CellRef::loadData(esm); + bool isDeleted = false; + item.ESM::CellRef::loadData(esm, isDeleted); int charge=-1; esm.getHNOT(charge, "XHLT"); From daaff1284e26d13358b130d7b44721ced210066d Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Wed, 22 Jul 2015 22:02:01 +0300 Subject: [PATCH 45/49] Remove unused includes --- apps/opencs/model/world/idcollection.hpp | 1 - apps/openmw/mwworld/store.cpp | 1 - components/esm/loaddial.hpp | 1 - components/esm/util.hpp | 5 ----- 4 files changed, 8 deletions(-) diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index c79b4e020..ea6eefb88 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -4,7 +4,6 @@ #include #include "collection.hpp" -#include "record.hpp" namespace CSMWorld { diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index cd9290bfc..a8b0af88a 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index e517fc86f..b80cbd74c 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include "loadinfo.hpp" diff --git a/components/esm/util.hpp b/components/esm/util.hpp index e16603b84..a80df2456 100644 --- a/components/esm/util.hpp +++ b/components/esm/util.hpp @@ -1,14 +1,9 @@ #ifndef OPENMW_ESM_UTIL_H #define OPENMW_ESM_UTIL_H -#include - #include #include -#include "esmreader.hpp" -#include "esmwriter.hpp" - namespace ESM { From 9a8ca819073e54406daafd04319299429c089c4e Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 26 Jul 2015 13:54:36 +0300 Subject: [PATCH 46/49] Fix missing break in switch statement --- components/esm/loadregn.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esm/loadregn.cpp b/components/esm/loadregn.cpp index b04e6ee3b..add821c3e 100644 --- a/components/esm/loadregn.cpp +++ b/components/esm/loadregn.cpp @@ -22,7 +22,6 @@ namespace ESM mId = esm.getHString(); hasName = true; break; - break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); break; @@ -69,6 +68,7 @@ namespace ESM case ESM::FourCC<'D','E','L','E'>::value: esm.skipHSub(); isDeleted = true; + break; default: esm.fail("Unknown subrecord"); break; From f9b0b7ede5eb2bc8ef62fce47c495247b04ebd78 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 28 Jul 2015 15:04:22 +0300 Subject: [PATCH 47/49] Make saving of deleted ESM records more consistent --- components/esm/cellref.cpp | 67 +++++++++++++++++-------------------- components/esm/cellref.hpp | 3 -- components/esm/loadbsgn.cpp | 5 +-- components/esm/loadcell.cpp | 18 ++++------ components/esm/loadland.cpp | 1 + components/esm/loadltex.cpp | 8 ++--- components/esm/loadpgrd.cpp | 12 +++---- components/esm/loadregn.cpp | 4 ++- components/esm/loadscpt.cpp | 1 + components/esm/loadsndg.cpp | 11 +++--- components/esm/loadsscr.cpp | 20 ++++++----- 11 files changed, 71 insertions(+), 79 deletions(-) diff --git a/components/esm/cellref.cpp b/components/esm/cellref.cpp index 9a0c8f1cc..7cd8186bd 100644 --- a/components/esm/cellref.cpp +++ b/components/esm/cellref.cpp @@ -25,33 +25,6 @@ void ESM::RefNum::save (ESMWriter &esm, bool wide, const std::string& tag) const } -void ESM::CellRef::clearData() -{ - mScale = 1; - mOwner.clear(); - mGlobalVariable.clear(); - mSoul.clear(); - mFaction.clear(); - mFactionRank = -2; - mChargeInt = -1; - mEnchantmentCharge = -1; - mGoldValue = 0; - mDestCell.clear(); - mLockLevel = 0; - mKey.clear(); - mTrap.clear(); - mReferenceBlocked = -1; - mTeleport = false; - - for (int i=0; i<3; ++i) - { - mDoorDest.pos[i] = 0; - mDoorDest.rot[i] = 0; - mPos.pos[i] = 0; - mPos.rot[i] = 0; - } -} - void ESM::CellRef::load (ESMReader& esm, bool &isDeleted, bool wideRefNum) { loadId(esm, wideRefNum); @@ -67,6 +40,8 @@ void ESM::CellRef::loadId (ESMReader& esm, bool wideRefNum) if (esm.isNextSub ("NAM0")) esm.skipHSub(); + blank(); + mRefNum.load (esm, wideRefNum); mRefID = esm.getHNString ("NAME"); @@ -76,8 +51,6 @@ void ESM::CellRef::loadData(ESMReader &esm, bool &isDeleted) { isDeleted = false; - clearData(); - bool isLoaded = false; while (!isLoaded && esm.hasMoreSubs()) { @@ -154,6 +127,11 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory, bool esm.writeHNCString("NAME", mRefID); + if (isDeleted) { + esm.writeHNCString("DELE", ""); + return; + } + if (mScale != 1.0) { esm.writeHNT("XSCL", mScale); } @@ -198,18 +176,35 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory, bool if (!inInventory) esm.writeHNT("DATA", mPos, 24); - - if (isDeleted) - { - esm.writeHNCString("DELE", ""); - } } void ESM::CellRef::blank() { mRefNum.unset(); - mRefID.clear(); - clearData(); + mRefID.clear(); + mScale = 1; + mOwner.clear(); + mGlobalVariable.clear(); + mSoul.clear(); + mFaction.clear(); + mFactionRank = -2; + mChargeInt = -1; + mEnchantmentCharge = -1; + mGoldValue = 0; + mDestCell.clear(); + mLockLevel = 0; + mKey.clear(); + mTrap.clear(); + mReferenceBlocked = -1; + mTeleport = false; + + for (int i=0; i<3; ++i) + { + mDoorDest.pos[i] = 0; + mDoorDest.rot[i] = 0; + mPos.pos[i] = 0; + mPos.rot[i] = 0; + } } bool ESM::operator== (const RefNum& left, const RefNum& right) diff --git a/components/esm/cellref.hpp b/components/esm/cellref.hpp index a9edd291e..c371a4f01 100644 --- a/components/esm/cellref.hpp +++ b/components/esm/cellref.hpp @@ -33,10 +33,7 @@ namespace ESM class CellRef { - void clearData(); - public: - // Reference number // Note: Currently unused for items in containers RefNum mRefNum; diff --git a/components/esm/loadbsgn.cpp b/components/esm/loadbsgn.cpp index 56dc1897c..0413a8610 100644 --- a/components/esm/loadbsgn.cpp +++ b/components/esm/loadbsgn.cpp @@ -52,12 +52,13 @@ namespace ESM void BirthSign::save(ESMWriter &esm, bool isDeleted) const { + esm.writeHNCString("NAME", mId); + if (isDeleted) { esm.writeHNCString("DELE", ""); + return; } - - esm.writeHNCString("NAME", mId); esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("TNAM", mTexture); esm.writeHNOCString("DESC", mDescription); diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 2d8daa584..703a4f4cb 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -62,7 +62,8 @@ namespace ESM { isDeleted = false; - bool hasName = false; + blank(); + bool hasData = false; bool isLoaded = false; while (!isLoaded && esm.hasMoreSubs()) @@ -72,7 +73,6 @@ namespace ESM { case ESM::FourCC<'N','A','M','E'>::value: mName = esm.getHString(); - hasName = true; break; case ESM::FourCC<'D','A','T','A'>::value: esm.getHT(mData, 12); @@ -89,20 +89,12 @@ namespace ESM } } - if (!hasName) - esm.fail("Missing NAME subrecord"); if (!hasData) esm.fail("Missing DATA subrecord"); } void Cell::loadCell(ESMReader &esm, bool saveContext) { - mWater = 0.0f; - mWaterInt = false; - mMapColor = 0; - mRegion.clear(); - mRefNumCounter = 0; - bool isLoaded = false; while (!isLoaded && esm.hasMoreSubs()) { @@ -117,6 +109,7 @@ namespace ESM break; case ESM::FourCC<'W','H','G','T'>::value: esm.getHT(mWater); + mWaterInt = false; break; case ESM::FourCC<'A','M','B','I'>::value: esm.getHT(mAmbi); @@ -153,14 +146,15 @@ namespace ESM void Cell::save(ESMWriter &esm, bool isDeleted) const { - esm.writeHNCString("NAME", mName); + esm.writeHNOCString("NAME", mName); + esm.writeHNT("DATA", mData, 12); if (isDeleted) { esm.writeHNCString("DELE", ""); + return; } - esm.writeHNT("DATA", mData, 12); if (mData.mFlags & Interior) { if (mWaterInt) { diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 2ffd2a21b..1317fc71c 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -167,6 +167,7 @@ namespace ESM if (isDeleted) { esm.writeHNCString("DELE", ""); + return; } if (mLandData) diff --git a/components/esm/loadltex.cpp b/components/esm/loadltex.cpp index cf026dbf1..e9cd4578d 100644 --- a/components/esm/loadltex.cpp +++ b/components/esm/loadltex.cpp @@ -47,14 +47,14 @@ namespace ESM } void LandTexture::save(ESMWriter &esm, bool isDeleted) const { + esm.writeHNCString("NAME", mId); + esm.writeHNT("INTV", mIndex); + esm.writeHNCString("DATA", mTexture); + if (isDeleted) { esm.writeHNCString("DELE", ""); } - - esm.writeHNCString("NAME", mId); - esm.writeHNT("INTV", mIndex); - esm.writeHNCString("DATA", mTexture); } void LandTexture::blank() diff --git a/components/esm/loadpgrd.cpp b/components/esm/loadpgrd.cpp index 8027be91c..95e6a906f 100644 --- a/components/esm/loadpgrd.cpp +++ b/components/esm/loadpgrd.cpp @@ -43,20 +43,18 @@ namespace ESM int edgeCount = 0; bool hasData = false; - bool hasName = false; while (esm.hasMoreSubs()) { esm.getSubName(); switch (esm.retSubName().val) { + case ESM::FourCC<'N','A','M','E'>::value: + mCell = esm.getHString(); + break; case ESM::FourCC<'D','A','T','A'>::value: esm.getHT(mData, 12); hasData = true; break; - case ESM::FourCC<'N','A','M','E'>::value: - mCell = esm.getHString(); - hasName = true; - break; case ESM::FourCC<'P','G','R','P'>::value: { esm.getSubHeader(); @@ -125,14 +123,12 @@ namespace ESM if (!hasData) esm.fail("Missing DATA subrecord"); - if (!hasName) - esm.fail("Missing NAME subrecord"); } void Pathgrid::save(ESMWriter &esm, bool isDeleted) const { - esm.writeHNT("DATA", mData, 12); esm.writeHNCString("NAME", mCell); + esm.writeHNT("DATA", mData, 12); if (isDeleted) { diff --git a/components/esm/loadregn.cpp b/components/esm/loadregn.cpp index add821c3e..9f3089763 100644 --- a/components/esm/loadregn.cpp +++ b/components/esm/loadregn.cpp @@ -81,12 +81,14 @@ namespace ESM void Region::save(ESMWriter &esm, bool isDeleted) const { + esm.writeHNCString("NAME", mId); + if (isDeleted) { esm.writeHNCString("DELE", ""); + return; } - esm.writeHNString("NAME", mId); esm.writeHNOCString("FNAM", mName); if (esm.getVersion() == VER_12) diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index e433ddede..2a0542138 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -120,6 +120,7 @@ namespace ESM if (isDeleted) { esm.writeHNCString("DELE", ""); + return; } if (!mVarNames.empty()) diff --git a/components/esm/loadsndg.cpp b/components/esm/loadsndg.cpp index 400b1072b..189cc97df 100644 --- a/components/esm/loadsndg.cpp +++ b/components/esm/loadsndg.cpp @@ -51,14 +51,17 @@ namespace ESM void SoundGenerator::save(ESMWriter &esm, bool isDeleted) const { esm.writeHNCString("NAME", mId); - esm.writeHNT("DATA", mType, 4); - esm.writeHNOCString("CNAM", mCreature); - esm.writeHNOCString("SNAM", mSound); - + if (isDeleted) { esm.writeHNCString("DELE", ""); + return; } + + esm.writeHNT("DATA", mType, 4); + esm.writeHNOCString("CNAM", mCreature); + esm.writeHNOCString("SNAM", mSound); + } void SoundGenerator::blank() diff --git a/components/esm/loadsscr.cpp b/components/esm/loadsscr.cpp index 6af6c96dc..a211a99bf 100644 --- a/components/esm/loadsscr.cpp +++ b/components/esm/loadsscr.cpp @@ -19,14 +19,14 @@ namespace ESM esm.getSubName(); switch (esm.retSubName().val) { - case ESM::FourCC<'D','A','T','A'>::value: - mData = esm.getHString(); - hasData = true; - break; case ESM::FourCC<'N','A','M','E'>::value: mId = esm.getHString(); hasName = true; break; + case ESM::FourCC<'D','A','T','A'>::value: + mData = esm.getHString(); + hasData = true; + break; case ESM::FourCC<'D','E','L','E'>::value: esm.skipHSub(); isDeleted = true; @@ -37,20 +37,22 @@ namespace ESM } } - if (!hasData) - esm.fail("Missing DATA"); if (!hasName) esm.fail("Missing NAME"); + if (!hasData && !isDeleted) + esm.fail("Missing DATA"); } void StartScript::save(ESMWriter &esm, bool isDeleted) const { - esm.writeHNString("DATA", mData); - esm.writeHNString("NAME", mId); - + esm.writeHNCString("NAME", mId); if (isDeleted) { esm.writeHNCString("DELE", ""); } + else + { + esm.writeHNString("DATA", mData); + } } void StartScript::blank() From f15adb4e4f18e9f5509c95a065001f85a4e0dd82 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Thu, 30 Jul 2015 14:43:36 +0300 Subject: [PATCH 48/49] Store::load() overwrites loaded records with the same IDs --- apps/openmw/mwworld/store.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index a8b0af88a..5c1b2c6e3 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -196,6 +196,8 @@ namespace MWWorld std::pair inserted = mStatic.insert(std::make_pair(record.mId, record)); if (inserted.second) mShared.push_back(&inserted.first->second); + else + inserted.first->second = record; return RecordId(record.mId, isDeleted); } From d13766cb3c185ecce9b95518d1367b2cf2d2812d Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Thu, 30 Jul 2015 15:36:17 +0300 Subject: [PATCH 49/49] Remove redundant template specializations --- apps/openmw/mwworld/store.cpp | 43 ----------------------------------- 1 file changed, 43 deletions(-) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 5c1b2c6e3..98138147d 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -1060,49 +1060,6 @@ namespace MWWorld return RecordId(dialogue.mId, isDeleted); } - - - // Script - //========================================================================= - - template <> - inline RecordId Store::load(ESM::ESMReader &esm) { - ESM::Script script; - bool isDeleted = false; - - script.load(esm, isDeleted); - Misc::StringUtils::toLower(script.mId); - - std::pair inserted = mStatic.insert(std::make_pair(script.mId, script)); - if (inserted.second) - mShared.push_back(&inserted.first->second); - else - inserted.first->second = script; - - return RecordId(script.mId, isDeleted); - } - - - // StartScript - //========================================================================= - - template <> - inline RecordId Store::load(ESM::ESMReader &esm) - { - ESM::StartScript script; - bool isDeleted = false; - - script.load(esm, isDeleted); - Misc::StringUtils::toLower(script.mId); - - std::pair inserted = mStatic.insert(std::make_pair(script.mId, script)); - if (inserted.second) - mShared.push_back(&inserted.first->second); - else - inserted.first->second = script; - - return RecordId(script.mId, isDeleted); - } } template class MWWorld::Store;