diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index bd93cc7c4e..30bf044ae4 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "../mwmechanics/spelllist.hpp" @@ -145,7 +146,8 @@ static bool isCacheableRecord(int id) void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener, ESM::Dialogue*& dialogue) { - listener->setProgressRange(1000); + if (listener != nullptr) + listener->setProgressRange(::EsmLoader::fileProgress); // Land texture loading needs to use a separate internal store for each plugin. // We set the number of plugins here so we can properly verify if valid plugin @@ -211,7 +213,8 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener, ESM::Dialo dialogue = nullptr; } } - listener->setProgress(static_cast(esm.getFileOffset() / (float)esm.getFileSize() * 1000)); + if (listener != nullptr) + listener->setProgress(::EsmLoader::fileProgress * esm.getFileOffset() / esm.getFileSize()); } } diff --git a/apps/openmw/mwworld/groundcoverstore.cpp b/apps/openmw/mwworld/groundcoverstore.cpp index 1b27f8eed3..52e9b07a4d 100644 --- a/apps/openmw/mwworld/groundcoverstore.cpp +++ b/apps/openmw/mwworld/groundcoverstore.cpp @@ -6,14 +6,16 @@ namespace MWWorld { - void GroundcoverStore::init(const Store& statics, const Files::Collections& fileCollections, const std::vector& groundcoverFiles, ToUTF8::Utf8Encoder* encoder) + void GroundcoverStore::init(const Store& statics, const Files::Collections& fileCollections, + const std::vector& groundcoverFiles, ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener) { ::EsmLoader::Query query; query.mLoadStatics = true; query.mLoadCells = true; ESM::ReadersCache readers; - const ::EsmLoader::EsmData content = ::EsmLoader::loadEsmData(query, groundcoverFiles, fileCollections, readers, encoder); + const ::EsmLoader::EsmData content = ::EsmLoader::loadEsmData(query, groundcoverFiles, fileCollections, + readers, encoder, listener); for (const ESM::Static& stat : statics) { diff --git a/apps/openmw/mwworld/groundcoverstore.hpp b/apps/openmw/mwworld/groundcoverstore.hpp index 6c48a63c58..ffeb111134 100644 --- a/apps/openmw/mwworld/groundcoverstore.hpp +++ b/apps/openmw/mwworld/groundcoverstore.hpp @@ -20,7 +20,10 @@ namespace MWWorld std::map, std::vector> mCellContexts; public: - void init(const Store& statics, const Files::Collections& fileCollections, const std::vector& groundcoverFiles, ToUTF8::Utf8Encoder* encoder); + void init(const Store& statics, const Files::Collections& fileCollections, + const std::vector& groundcoverFiles, ToUTF8::Utf8Encoder* encoder, + Loading::Listener* listener); + std::string getGroundcoverModel(const std::string& id) const; void initCell(ESM::Cell& cell, int cellX, int cellY) const; }; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 3c0d796e9b..2387002ec4 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -157,7 +157,7 @@ namespace MWWorld listener->loadingOn(); loadContentFiles(fileCollections, contentFiles, encoder, listener); - loadGroundcoverFiles(fileCollections, groundcoverFiles, encoder); + loadGroundcoverFiles(fileCollections, groundcoverFiles, encoder, listener); listener->loadingOff(); @@ -2940,13 +2940,14 @@ namespace MWWorld ensureNeededRecords(); // Insert records that may not be present in all versions of master files. } - void World::loadGroundcoverFiles(const Files::Collections& fileCollections, const std::vector& groundcoverFiles, ToUTF8::Utf8Encoder* encoder) + void World::loadGroundcoverFiles(const Files::Collections& fileCollections, + const std::vector& groundcoverFiles, ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener) { if (!Settings::Manager::getBool("enabled", "Groundcover")) return; Log(Debug::Info) << "Loading groundcover:"; - mGroundcoverStore.init(mStore.get(), fileCollections, groundcoverFiles, encoder); + mGroundcoverStore.init(mStore.get(), fileCollections, groundcoverFiles, encoder, listener); } bool World::startSpellCast(const Ptr &actor) diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 50aff408d5..17f66cbd4e 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -171,7 +171,9 @@ namespace MWWorld void loadContentFiles(const Files::Collections& fileCollections, const std::vector& content, ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener); - void loadGroundcoverFiles(const Files::Collections& fileCollections, const std::vector& groundcoverFiles, ToUTF8::Utf8Encoder* encoder); + void loadGroundcoverFiles(const Files::Collections& fileCollections, + const std::vector& groundcoverFiles, ToUTF8::Utf8Encoder* encoder, + Loading::Listener* listener); float feetToGameUnits(float feet); float getActivationDistancePlusTelekinesis(); diff --git a/components/esmloader/load.cpp b/components/esmloader/load.cpp index 0db1d726a7..d3c170bc4c 100644 --- a/components/esmloader/load.cpp +++ b/components/esmloader/load.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -190,7 +191,7 @@ namespace EsmLoader reader.skipRecord(); } - void loadEsm(const Query& query, ESM::ESMReader& reader, ShallowContent& content) + void loadEsm(const Query& query, ESM::ESMReader& reader, ShallowContent& content, Loading::Listener* listener) { Log(Debug::Info) << "Loading ESM file " << reader.getName(); @@ -204,12 +205,15 @@ namespace EsmLoader continue; } loadRecord(query, recName, reader, content); + + if (listener != nullptr) + listener->setProgress(fileProgress * reader.getFileOffset() / reader.getFileSize()); } } ShallowContent shallowLoad(const Query& query, const std::vector& contentFiles, const Files::Collections& fileCollections, ESM::ReadersCache& readers, - ToUTF8::Utf8Encoder* encoder) + ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener) { ShallowContent result; @@ -232,6 +236,12 @@ namespace EsmLoader continue; } + if (listener != nullptr) + { + listener->setLabel(file); + listener->setProgressRange(fileProgress); + } + const Files::MultiDirCollection& collection = fileCollections.getCollection(extension); const ESM::ReadersCache::BusyItem reader = readers.get(i); @@ -241,7 +251,7 @@ namespace EsmLoader if (query.mLoadCells) reader->resolveParentFileIndices(readers); - loadEsm(query, *reader, result); + loadEsm(query, *reader, result, listener); } return result; @@ -290,11 +300,12 @@ namespace EsmLoader } EsmData loadEsmData(const Query& query, const std::vector& contentFiles, - const Files::Collections& fileCollections, ESM::ReadersCache& readers, ToUTF8::Utf8Encoder* encoder) + const Files::Collections& fileCollections, ESM::ReadersCache& readers, ToUTF8::Utf8Encoder* encoder, + Loading::Listener* listener) { Log(Debug::Info) << "Loading ESM data..."; - ShallowContent content = shallowLoad(query, contentFiles, fileCollections, readers, encoder); + ShallowContent content = shallowLoad(query, contentFiles, fileCollections, readers, encoder, listener); std::ostringstream loaded; diff --git a/components/esmloader/load.hpp b/components/esmloader/load.hpp index 8bb8df35fe..d7a64a1c85 100644 --- a/components/esmloader/load.hpp +++ b/components/esmloader/load.hpp @@ -16,10 +16,17 @@ namespace Files class Collections; } +namespace Loading +{ + class Listener; +} + namespace EsmLoader { struct EsmData; + inline constexpr std::size_t fileProgress = 1000; + struct Query { bool mLoadActivators = false; @@ -33,7 +40,7 @@ namespace EsmLoader EsmData loadEsmData(const Query& query, const std::vector& contentFiles, const Files::Collections& fileCollections, ESM::ReadersCache& readers, - ToUTF8::Utf8Encoder* encoder); + ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener = nullptr); } #endif