Optimize saving in editor

pull/3229/head
elsid 2 years ago
parent 8383fa3547
commit b2299ef914
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -125,6 +125,7 @@ CSMDoc::WriteDialogueCollectionStage::WriteDialogueCollectionStage(Document& doc
int CSMDoc::WriteDialogueCollectionStage::setup()
{
mInfosByTopic = mInfos.getInfosByTopic();
return mTopics.getSize();
}
@ -145,14 +146,17 @@ void CSMDoc::WriteDialogueCollectionStage::perform(int stage, Messages& messages
// Test, if we need to save anything associated info records.
bool infoModified = false;
const auto infos = mInfos.getTopicInfos(topic.get().mId);
const auto topicInfos = mInfosByTopic.find(topic.get().mId);
for (const auto& record : infos)
if (topicInfos != mInfosByTopic.end())
{
if (record->isModified() || record->mState == CSMWorld::RecordBase::State_Deleted)
for (const auto& record : topicInfos->second)
{
infoModified = true;
break;
if (record->isModified() || record->mState == CSMWorld::RecordBase::State_Deleted)
{
infoModified = true;
break;
}
}
}
@ -173,31 +177,36 @@ void CSMDoc::WriteDialogueCollectionStage::perform(int stage, Messages& messages
}
// write modified selected info records
for (auto iter = infos.begin(); iter != infos.end(); ++iter)
if (topicInfos != mInfosByTopic.end())
{
const CSMWorld::Record<CSMWorld::Info>& record = **iter;
const std::vector<const CSMWorld::Record<CSMWorld::Info>*>& infos = topicInfos->second;
if (record.isModified() || record.mState == CSMWorld::RecordBase::State_Deleted)
for (auto iter = infos.begin(); iter != infos.end(); ++iter)
{
ESM::DialInfo info = record.get();
info.mId = record.get().mOriginalId;
const CSMWorld::Record<CSMWorld::Info>& record = **iter;
info.mPrev = ESM::RefId::sEmpty;
if (iter != infos.begin())
if (record.isModified() || record.mState == CSMWorld::RecordBase::State_Deleted)
{
const auto prev = std::prev(iter);
info.mPrev = (*prev)->get().mOriginalId;
}
ESM::DialInfo info = record.get();
info.mId = record.get().mOriginalId;
const auto next = std::next(iter);
info.mPrev = ESM::RefId::sEmpty;
if (iter != infos.begin())
{
const auto prev = std::prev(iter);
info.mPrev = (*prev)->get().mOriginalId;
}
info.mNext = ESM::RefId::sEmpty;
if (next != infos.end())
info.mNext = (*next)->get().mOriginalId;
const auto next = std::next(iter);
writer.startRecord(info.sRecordId);
info.save(writer, record.mState == CSMWorld::RecordBase::State_Deleted);
writer.endRecord(info.sRecordId);
info.mNext = ESM::RefId::sEmpty;
if (next != infos.end())
info.mNext = (*next)->get().mOriginalId;
writer.startRecord(info.sRecordId);
info.save(writer, record.mState == CSMWorld::RecordBase::State_Deleted);
writer.endRecord(info.sRecordId);
}
}
}
}

@ -4,8 +4,10 @@
#include "stage.hpp"
#include <deque>
#include <unordered_map>
#include "../world/idcollection.hpp"
#include "../world/infocollection.hpp"
#include "../world/record.hpp"
#include "../world/scope.hpp"
@ -118,6 +120,7 @@ namespace CSMDoc
SavingState& mState;
const CSMWorld::IdCollection<ESM::Dialogue>& mTopics;
CSMWorld::InfoCollection& mInfos;
CSMWorld::InfosRecordPtrByTopic mInfosByTopic;
public:
WriteDialogueCollectionStage(Document& document, SavingState& state, bool journal);

@ -32,7 +32,7 @@ CSMTools::JournalCheckStage::JournalCheckStage(
int CSMTools::JournalCheckStage::setup()
{
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
mInfosByTopic = mJournalInfos.getInfosByTopic();
return mJournals.getSize();
}
@ -50,38 +50,39 @@ void CSMTools::JournalCheckStage::perform(int stage, CSMDoc::Messages& messages)
int totalInfoCount = 0;
std::set<int> questIndices;
for (const CSMWorld::Record<CSMWorld::Info>* record : mJournalInfos.getTopicInfos(journal.mId))
if (const auto infos = mInfosByTopic.find(journal.mId); infos != mInfosByTopic.end())
{
if (record->isDeleted())
continue;
const CSMWorld::Info& journalInfo = record->get();
totalInfoCount += 1;
if (journalInfo.mQuestStatus == ESM::DialInfo::QS_Name)
{
statusNamedCount += 1;
}
// Skip "Base" records (setting!)
if (mIgnoreBaseRecords && record->mState == CSMWorld::RecordBase::State_BaseOnly)
continue;
if (journalInfo.mResponse.empty())
{
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_JournalInfo, journalInfo.mId);
messages.add(id, "Missing journal entry text", "", CSMDoc::Message::Severity_Warning);
}
std::pair<std::set<int>::iterator, bool> result = questIndices.insert(journalInfo.mData.mJournalIndex);
// Duplicate index
if (!result.second)
for (const CSMWorld::Record<CSMWorld::Info>* record : infos->second)
{
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_JournalInfo, journalInfo.mId);
messages.add(id, "Duplicated quest index " + std::to_string(journalInfo.mData.mJournalIndex), "",
CSMDoc::Message::Severity_Error);
if (record->isDeleted())
continue;
const CSMWorld::Info& journalInfo = record->get();
totalInfoCount += 1;
if (journalInfo.mQuestStatus == ESM::DialInfo::QS_Name)
{
statusNamedCount += 1;
}
// Skip "Base" records (setting!)
if (mIgnoreBaseRecords && record->mState == CSMWorld::RecordBase::State_BaseOnly)
continue;
if (journalInfo.mResponse.empty())
{
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_JournalInfo, journalInfo.mId);
messages.add(id, "Missing journal entry text", "", CSMDoc::Message::Severity_Warning);
}
// Duplicate index
if (!questIndices.insert(journalInfo.mData.mJournalIndex).second)
{
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_JournalInfo, journalInfo.mId);
messages.add(id, "Duplicated quest index " + std::to_string(journalInfo.mData.mJournalIndex), "",
CSMDoc::Message::Severity_Error);
}
}
}

@ -2,6 +2,7 @@
#define CSM_TOOLS_JOURNALCHECK_H
#include "../world/idcollection.hpp"
#include "../world/infocollection.hpp"
#include "../doc/stage.hpp"
@ -39,6 +40,7 @@ namespace CSMTools
const CSMWorld::IdCollection<ESM::Dialogue>& mJournals;
const CSMWorld::InfoCollection& mJournalInfos;
bool mIgnoreBaseRecords;
CSMWorld::InfosRecordPtrByTopic mInfosByTopic;
};
}

@ -82,11 +82,10 @@ void CSMWorld::InfoCollection::load(
}
}
std::vector<CSMWorld::Record<CSMWorld::Info>*> CSMWorld::InfoCollection::getTopicInfos(const ESM::RefId& topic) const
CSMWorld::InfosRecordPtrByTopic CSMWorld::InfoCollection::getInfosByTopic() const
{
std::vector<CSMWorld::Record<CSMWorld::Info>*> result;
InfosRecordPtrByTopic result;
for (const std::unique_ptr<Record<Info>>& record : getRecords())
if (record->mBase.mTopicId == topic)
result.push_back(record.get());
result[record->mBase.mTopicId].push_back(record.get());
return result;
}

@ -7,7 +7,6 @@
#include "collection.hpp"
#include "info.hpp"
#include "record.hpp"
namespace ESM
{
@ -18,6 +17,7 @@ namespace ESM
namespace CSMWorld
{
using InfosByTopic = std::unordered_map<ESM::RefId, std::vector<ESM::RefId>>;
using InfosRecordPtrByTopic = std::unordered_map<ESM::RefId, std::vector<const Record<Info>*>>;
class InfoCollection : public Collection<Info, IdAccessor<Info>>
{
@ -27,7 +27,7 @@ namespace CSMWorld
public:
void load(ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue, InfosByTopic& infosByTopic);
std::vector<Record<Info>*> getTopicInfos(const ESM::RefId& topic) const;
InfosRecordPtrByTopic getInfosByTopic() const;
};
}

Loading…
Cancel
Save