mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-20 22:11:33 +00:00
Use ESM::RefId as key for SavingState::mSubRecords
This commit is contained in:
parent
0d25656d81
commit
3c9dbb11cc
3 changed files with 30 additions and 16 deletions
|
@ -236,7 +236,7 @@ CSMDoc::CollectionReferencesStage::CollectionReferencesStage(Document& document,
|
||||||
|
|
||||||
int CSMDoc::CollectionReferencesStage::setup()
|
int CSMDoc::CollectionReferencesStage::setup()
|
||||||
{
|
{
|
||||||
mState.getSubRecords().clear();
|
mState.clearSubRecords();
|
||||||
|
|
||||||
int size = mDocument.getData().getReferences().getSize();
|
int size = mDocument.getData().getReferences().getSize();
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ void CSMDoc::CollectionReferencesStage::perform(int stage, Messages& messages)
|
||||||
const ESM::RefId& cellId
|
const ESM::RefId& cellId
|
||||||
= record.get().mOriginalCell.empty() ? record.get().mCell : record.get().mOriginalCell;
|
= record.get().mOriginalCell.empty() ? record.get().mCell : record.get().mOriginalCell;
|
||||||
|
|
||||||
std::deque<int>& indices = mState.getSubRecords()[cellId.getRefIdString()];
|
std::deque<int>& indices = mState.getOrInsertSubRecord(cellId);
|
||||||
|
|
||||||
// collect moved references at the end of the container
|
// collect moved references at the end of the container
|
||||||
const bool interior = !cellId.startsWith("#");
|
const bool interior = !cellId.startsWith("#");
|
||||||
|
@ -360,11 +360,9 @@ void CSMDoc::WriteCellCollectionStage::perform(int stage, Messages& messages)
|
||||||
std::deque<int> tempRefs;
|
std::deque<int> tempRefs;
|
||||||
std::deque<int> persistentRefs;
|
std::deque<int> persistentRefs;
|
||||||
|
|
||||||
std::map<std::string, std::deque<int>>::const_iterator references
|
const std::deque<int>* references = mState.findSubRecord(cell.get().mId);
|
||||||
= mState.getSubRecords().find(cell.get().mId.getRefIdString());
|
|
||||||
|
|
||||||
if (cell.isModified() || cell.mState == CSMWorld::RecordBase::State_Deleted
|
if (cell.isModified() || cell.mState == CSMWorld::RecordBase::State_Deleted || references != nullptr)
|
||||||
|| references != mState.getSubRecords().end())
|
|
||||||
{
|
{
|
||||||
CSMWorld::Cell cellRecord = cell.get();
|
CSMWorld::Cell cellRecord = cell.get();
|
||||||
const bool interior = !cellRecord.mId.startsWith("#");
|
const bool interior = !cellRecord.mId.startsWith("#");
|
||||||
|
@ -372,10 +370,9 @@ void CSMDoc::WriteCellCollectionStage::perform(int stage, Messages& messages)
|
||||||
// count new references and adjust RefNumCount accordingsly
|
// count new references and adjust RefNumCount accordingsly
|
||||||
unsigned int newRefNum = cellRecord.mRefNumCounter;
|
unsigned int newRefNum = cellRecord.mRefNumCounter;
|
||||||
|
|
||||||
if (references != mState.getSubRecords().end())
|
if (references != nullptr)
|
||||||
{
|
{
|
||||||
for (std::deque<int>::const_iterator iter(references->second.begin()); iter != references->second.end();
|
for (std::deque<int>::const_iterator iter(references->begin()); iter != references->end(); ++iter)
|
||||||
++iter)
|
|
||||||
{
|
{
|
||||||
const CSMWorld::Record<CSMWorld::CellRef>& ref = mDocument.getData().getReferences().getRecord(*iter);
|
const CSMWorld::Record<CSMWorld::CellRef>& ref = mDocument.getData().getReferences().getRecord(*iter);
|
||||||
|
|
||||||
|
@ -421,10 +418,10 @@ void CSMDoc::WriteCellCollectionStage::perform(int stage, Messages& messages)
|
||||||
cellRecord.save(writer, cell.mState == CSMWorld::RecordBase::State_Deleted);
|
cellRecord.save(writer, cell.mState == CSMWorld::RecordBase::State_Deleted);
|
||||||
|
|
||||||
// write references
|
// write references
|
||||||
if (references != mState.getSubRecords().end())
|
if (references != nullptr)
|
||||||
{
|
{
|
||||||
writeReferences(persistentRefs, interior, newRefNum);
|
writeReferences(persistentRefs, interior, newRefNum);
|
||||||
cellRecord.saveTempMarker(writer, int(references->second.size()) - persistentRefs.size());
|
cellRecord.saveTempMarker(writer, static_cast<int>(references->size()) - persistentRefs.size());
|
||||||
writeReferences(tempRefs, interior, newRefNum);
|
writeReferences(tempRefs, interior, newRefNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,20 @@ bool CSMDoc::SavingState::isProjectFile() const
|
||||||
return mProjectFile;
|
return mProjectFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, std::deque<int>, Misc::StringUtils::CiComp>& CSMDoc::SavingState::getSubRecords()
|
const std::deque<int>* CSMDoc::SavingState::findSubRecord(const ESM::RefId& refId) const
|
||||||
{
|
{
|
||||||
return mSubRecords;
|
const auto it = mSubRecords.find(refId);
|
||||||
|
if (it == mSubRecords.end())
|
||||||
|
return nullptr;
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::deque<int>& CSMDoc::SavingState::getOrInsertSubRecord(const ESM::RefId& refId)
|
||||||
|
{
|
||||||
|
return mSubRecords[refId];
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMDoc::SavingState::clearSubRecords()
|
||||||
|
{
|
||||||
|
mSubRecords.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <components/esm3/esmwriter.hpp>
|
#include <components/esm3/esmwriter.hpp>
|
||||||
|
|
||||||
#include <components/misc/algorithm.hpp>
|
#include <components/misc/algorithm.hpp>
|
||||||
#include <components/to_utf8/to_utf8.hpp>
|
#include <components/to_utf8/to_utf8.hpp>
|
||||||
|
|
||||||
namespace CSMDoc
|
namespace CSMDoc
|
||||||
{
|
{
|
||||||
class Operation;
|
class Operation;
|
||||||
|
@ -26,7 +26,7 @@ namespace CSMDoc
|
||||||
ESM::ESMWriter mWriter;
|
ESM::ESMWriter mWriter;
|
||||||
std::filesystem::path mProjectPath;
|
std::filesystem::path mProjectPath;
|
||||||
bool mProjectFile;
|
bool mProjectFile;
|
||||||
std::map<std::string, std::deque<int>, Misc::StringUtils::CiComp> mSubRecords; // record ID, list of subrecords
|
std::map<ESM::RefId, std::deque<int>> mSubRecords; // record ID, list of subrecords
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SavingState(Operation& operation, std::filesystem::path projectPath, ToUTF8::FromType encoding);
|
SavingState(Operation& operation, std::filesystem::path projectPath, ToUTF8::FromType encoding);
|
||||||
|
@ -47,7 +47,11 @@ namespace CSMDoc
|
||||||
bool isProjectFile() const;
|
bool isProjectFile() const;
|
||||||
///< Currently saving project file? (instead of content file)
|
///< Currently saving project file? (instead of content file)
|
||||||
|
|
||||||
std::map<std::string, std::deque<int>, Misc::StringUtils::CiComp>& getSubRecords();
|
const std::deque<int>* findSubRecord(const ESM::RefId& refId) const;
|
||||||
|
|
||||||
|
std::deque<int>& getOrInsertSubRecord(const ESM::RefId& refId);
|
||||||
|
|
||||||
|
void clearSubRecords();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue