1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-28 16:39:43 +00:00

Add ReadersCache::clear

This commit is contained in:
Evil Eye 2024-05-19 20:39:23 +02:00
parent 5f0fe8097c
commit 77d554594f
4 changed files with 16 additions and 8 deletions

View file

@ -1065,11 +1065,9 @@ int CSMWorld::Data::startLoading(const std::filesystem::path& path, bool base, b
{
Log(Debug::Info) << "Loading content file " << path;
if (!mReaders)
mReaders.emplace();
mDialogue = nullptr;
auto reader = mReaders->get(mReaderIndex++);
ESM::ReadersCache::BusyItem reader = mReaders.get(mReaderIndex++);
reader->setEncoder(&mEncoder);
reader->open(path);
@ -1133,14 +1131,14 @@ void CSMWorld::Data::loadFallbackEntries()
bool CSMWorld::Data::continueLoading(CSMDoc::Messages& messages)
{
if (mReaderIndex == 0 || !mReaders)
if (mReaderIndex == 0)
throw std::logic_error("can't continue loading, because no load has been started");
ESM::ReadersCache::BusyItem reader = mReaders->get(mReaderIndex - 1);
ESM::ReadersCache::BusyItem reader = mReaders.get(mReaderIndex - 1);
if (!reader->isOpen())
throw std::logic_error("can't continue loading, because no load has been started");
reader->setEncoder(&mEncoder);
reader->setIndex(static_cast<int>(mReaderIndex - 1));
reader->resolveParentFileIndices(*mReaders);
reader->resolveParentFileIndices(mReaders);
if (!reader->hasMoreRecs())
{
@ -1411,7 +1409,7 @@ void CSMWorld::Data::finishLoading()
mTopicInfos.sort(mTopicInfoOrder);
mJournalInfos.sort(mJournalInfoOrder);
// Release file locks so we can actually write to the file we're editing
mReaders.reset();
mReaders.clear();
}
bool CSMWorld::Data::hasId(const std::string& id) const

View file

@ -123,7 +123,7 @@ namespace CSMWorld
std::unique_ptr<ActorAdapter> mActorAdapter;
std::vector<QAbstractItemModel*> mModels;
std::map<UniversalId::Type, QAbstractItemModel*> mModelIndex;
std::optional<ESM::ReadersCache> mReaders;
ESM::ReadersCache mReaders;
const ESM::Dialogue* mDialogue; // last loaded dialogue
bool mBase;
bool mProject;

View file

@ -86,4 +86,12 @@ namespace ESM
it->mState = State::Closed;
}
}
void ReadersCache::clear()
{
mIndex.clear();
mBusyItems.clear();
mFreeItems.clear();
mClosedItems.clear();
}
}

View file

@ -55,6 +55,8 @@ namespace ESM
BusyItem get(std::size_t index);
void clear();
private:
const std::size_t mCapacity;
std::map<std::size_t, std::list<Item>::iterator> mIndex;