forked from mirror/openmw-tes3mp
added reference collection stage to saving operation (preparation for cell saving)
This commit is contained in:
parent
f4334da42e
commit
e0ba9a4bf2
7 changed files with 78 additions and 0 deletions
|
@ -65,7 +65,10 @@ CSMDoc::Saving::Saving (Document& document, const boost::filesystem::path& proje
|
|||
|
||||
appendStage (new WriteRefIdCollectionStage (mDocument, mState));
|
||||
|
||||
appendStage (new CollectionReferencesStage (mDocument, mState));
|
||||
|
||||
|
||||
// close file and clean up
|
||||
appendStage (new CloseSaveStage (mState));
|
||||
|
||||
appendStage (new FinalSavingStage (mDocument, mState));
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
#include <components/esm/loaddial.hpp>
|
||||
|
||||
#include <components/misc/stringops.hpp>
|
||||
|
||||
#include "../world/infocollection.hpp"
|
||||
|
||||
#include "document.hpp"
|
||||
|
@ -214,6 +216,42 @@ void CSMDoc::WriteFilterStage::perform (int stage, Messages& messages)
|
|||
}
|
||||
|
||||
|
||||
CSMDoc::CollectionReferencesStage::CollectionReferencesStage (Document& document,
|
||||
SavingState& state)
|
||||
: mDocument (document), mState (state)
|
||||
{}
|
||||
|
||||
int CSMDoc::CollectionReferencesStage::setup()
|
||||
{
|
||||
mState.getSubRecords().clear();
|
||||
|
||||
int size = mDocument.getData().getReferences().getSize();
|
||||
|
||||
int steps = size/100;
|
||||
if (size%100) ++steps;
|
||||
|
||||
return steps;
|
||||
}
|
||||
|
||||
void CSMDoc::CollectionReferencesStage::perform (int stage, Messages& messages)
|
||||
{
|
||||
int size = mDocument.getData().getReferences().getSize();
|
||||
|
||||
for (int i=stage*100; i<stage*100+100 && i<size; ++i)
|
||||
{
|
||||
const CSMWorld::Record<CSMWorld::CellRef>& 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)
|
||||
{
|
||||
mState.getSubRecords()[Misc::StringUtils::lowerCase (record.get().mId)].push_back (i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CSMDoc::CloseSaveStage::CloseSaveStage (SavingState& state)
|
||||
: mState (state)
|
||||
{}
|
||||
|
|
|
@ -163,8 +163,24 @@ namespace CSMDoc
|
|||
|
||||
virtual void perform (int stage, Messages& messages);
|
||||
///< Messages resulting from this stage will be appended to \a messages.
|
||||
|
||||
};
|
||||
|
||||
class CollectionReferencesStage : public Stage
|
||||
{
|
||||
Document& mDocument;
|
||||
SavingState& mState;
|
||||
|
||||
public:
|
||||
|
||||
CollectionReferencesStage (Document& document, SavingState& state);
|
||||
|
||||
virtual int setup();
|
||||
///< \return number of steps
|
||||
|
||||
virtual void perform (int stage, Messages& messages);
|
||||
///< Messages resulting from this stage will be appended to \a messages.
|
||||
};
|
||||
|
||||
class CloseSaveStage : public Stage
|
||||
{
|
||||
|
|
|
@ -25,6 +25,8 @@ void CSMDoc::SavingState::start (Document& document, bool project)
|
|||
|
||||
mStream.clear();
|
||||
|
||||
mSubRecords.clear();
|
||||
|
||||
if (project)
|
||||
mPath = mProjectPath;
|
||||
else
|
||||
|
@ -60,4 +62,9 @@ ESM::ESMWriter& CSMDoc::SavingState::getWriter()
|
|||
bool CSMDoc::SavingState::isProjectFile() const
|
||||
{
|
||||
return mProjectFile;
|
||||
}
|
||||
|
||||
std::map<std::string, std::vector<int> > CSMDoc::SavingState::getSubRecords()
|
||||
{
|
||||
return mSubRecords;
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
#define CSM_DOC_SAVINGSTATE_H
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
|
@ -24,6 +25,7 @@ namespace CSMDoc
|
|||
ESM::ESMWriter mWriter;
|
||||
boost::filesystem::path mProjectPath;
|
||||
bool mProjectFile;
|
||||
std::map<std::string, std::vector<int> > mSubRecords; // record ID, list of subrecords
|
||||
|
||||
public:
|
||||
|
||||
|
@ -45,6 +47,8 @@ namespace CSMDoc
|
|||
|
||||
bool isProjectFile() const;
|
||||
///< Currently saving project file? (instead of content file)
|
||||
|
||||
std::map<std::string, std::vector<int> > getSubRecords();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,2 +1,10 @@
|
|||
|
||||
#include "ref.hpp"
|
||||
|
||||
CSMWorld::CellRef::CellRef()
|
||||
{
|
||||
mRefNum.mIndex = 0;
|
||||
|
||||
// special marker: This reference does not have a RefNum assign to it yet.
|
||||
mRefNum.mContentFile = -2;
|
||||
}
|
|
@ -12,6 +12,8 @@ namespace CSMWorld
|
|||
{
|
||||
std::string mId;
|
||||
std::string mCell;
|
||||
|
||||
CellRef();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue