From 9fc62be2c69c7e7d50843b806c27d9dff5317dcb Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Tue, 14 Jan 2025 19:39:24 +0300 Subject: [PATCH] Track ESM4 file loading progress --- apps/openmw/mwworld/esmloader.cpp | 2 +- apps/openmw/mwworld/esmstore.cpp | 11 +++++++++-- apps/openmw/mwworld/esmstore.hpp | 2 +- components/esm4/reader.hpp | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwworld/esmloader.cpp b/apps/openmw/mwworld/esmloader.cpp index ebdd40303aa..833f152e134 100644 --- a/apps/openmw/mwworld/esmloader.cpp +++ b/apps/openmw/mwworld/esmloader.cpp @@ -70,7 +70,7 @@ namespace MWWorld mEncoder != nullptr ? &mEncoder->getStatelessEncoder() : nullptr); reader.setModIndex(index); reader.updateModIndices(mNameToIndex); - mStore.loadESM4(reader); + mStore.loadESM4(reader, listener); break; } } diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 15a687f4d79..ea183b6b532 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -468,9 +468,16 @@ namespace MWWorld } } - void ESMStore::loadESM4(ESM4::Reader& reader) + void ESMStore::loadESM4(ESM4::Reader& reader, Loading::Listener* listener) { - auto visitorRec = [this](ESM4::Reader& reader) { return ESMStoreImp::readRecord(reader, *this); }; + if (listener != nullptr) + listener->setProgressRange(::EsmLoader::fileProgress); + auto visitorRec = [this, listener](ESM4::Reader& reader) { + bool result = ESMStoreImp::readRecord(reader, *this); + if (listener != nullptr) + listener->setProgress(::EsmLoader::fileProgress * reader.getFileOffset() / reader.getFileSize()); + return result; + }; ESM4::ReaderUtils::readAll(reader, visitorRec, [](ESM4::Reader&) {}); } diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index d8cfd1dcdf7..6c71ae00527 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -219,7 +219,7 @@ namespace MWWorld void validateDynamic(); void load(ESM::ESMReader& esm, Loading::Listener* listener, ESM::Dialogue*& dialogue); - void loadESM4(ESM4::Reader& esm); + void loadESM4(ESM4::Reader& esm, Loading::Listener* listener); template const Store& get() const diff --git a/components/esm4/reader.hpp b/components/esm4/reader.hpp index 914fa4a647f..e8be4843556 100644 --- a/components/esm4/reader.hpp +++ b/components/esm4/reader.hpp @@ -217,7 +217,7 @@ namespace ESM4 // Methods added for updating loading progress bars inline std::size_t getFileSize() const { return mFileSize; } - inline std::size_t getFileOffset() const { return mStream->tellg(); } + inline std::size_t getFileOffset() const { return mSavedStream ? mSavedStream->tellg() : mStream->tellg(); } // Methods added for saving/restoring context ReaderContext getContext(); // WARN: must be called immediately after reading the record header