1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-29 08:15:35 +00:00

Show groundcover loading progress

This commit is contained in:
elsid 2022-06-03 18:59:08 +02:00
parent c7449dc272
commit 9c93de65be
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
7 changed files with 44 additions and 15 deletions

View file

@ -10,6 +10,7 @@
#include <components/lua/configuration.hpp> #include <components/lua/configuration.hpp>
#include <components/misc/algorithm.hpp> #include <components/misc/algorithm.hpp>
#include <components/esm3/readerscache.hpp> #include <components/esm3/readerscache.hpp>
#include <components/esmloader/load.hpp>
#include "../mwmechanics/spelllist.hpp" #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) 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. // 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 // 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; dialogue = nullptr;
} }
} }
listener->setProgress(static_cast<size_t>(esm.getFileOffset() / (float)esm.getFileSize() * 1000)); if (listener != nullptr)
listener->setProgress(::EsmLoader::fileProgress * esm.getFileOffset() / esm.getFileSize());
} }
} }

View file

@ -6,14 +6,16 @@
namespace MWWorld namespace MWWorld
{ {
void GroundcoverStore::init(const Store<ESM::Static>& statics, const Files::Collections& fileCollections, const std::vector<std::string>& groundcoverFiles, ToUTF8::Utf8Encoder* encoder) void GroundcoverStore::init(const Store<ESM::Static>& statics, const Files::Collections& fileCollections,
const std::vector<std::string>& groundcoverFiles, ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener)
{ {
::EsmLoader::Query query; ::EsmLoader::Query query;
query.mLoadStatics = true; query.mLoadStatics = true;
query.mLoadCells = true; query.mLoadCells = true;
ESM::ReadersCache readers; 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) for (const ESM::Static& stat : statics)
{ {

View file

@ -20,7 +20,10 @@ namespace MWWorld
std::map<std::pair<int, int>, std::vector<ESM::ESM_Context>> mCellContexts; std::map<std::pair<int, int>, std::vector<ESM::ESM_Context>> mCellContexts;
public: public:
void init(const Store<ESM::Static>& statics, const Files::Collections& fileCollections, const std::vector<std::string>& groundcoverFiles, ToUTF8::Utf8Encoder* encoder); void init(const Store<ESM::Static>& statics, const Files::Collections& fileCollections,
const std::vector<std::string>& groundcoverFiles, ToUTF8::Utf8Encoder* encoder,
Loading::Listener* listener);
std::string getGroundcoverModel(const std::string& id) const; std::string getGroundcoverModel(const std::string& id) const;
void initCell(ESM::Cell& cell, int cellX, int cellY) const; void initCell(ESM::Cell& cell, int cellX, int cellY) const;
}; };

View file

@ -157,7 +157,7 @@ namespace MWWorld
listener->loadingOn(); listener->loadingOn();
loadContentFiles(fileCollections, contentFiles, encoder, listener); loadContentFiles(fileCollections, contentFiles, encoder, listener);
loadGroundcoverFiles(fileCollections, groundcoverFiles, encoder); loadGroundcoverFiles(fileCollections, groundcoverFiles, encoder, listener);
listener->loadingOff(); listener->loadingOff();
@ -2940,13 +2940,14 @@ namespace MWWorld
ensureNeededRecords(); // Insert records that may not be present in all versions of master files. ensureNeededRecords(); // Insert records that may not be present in all versions of master files.
} }
void World::loadGroundcoverFiles(const Files::Collections& fileCollections, const std::vector<std::string>& groundcoverFiles, ToUTF8::Utf8Encoder* encoder) void World::loadGroundcoverFiles(const Files::Collections& fileCollections,
const std::vector<std::string>& groundcoverFiles, ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener)
{ {
if (!Settings::Manager::getBool("enabled", "Groundcover")) return; if (!Settings::Manager::getBool("enabled", "Groundcover")) return;
Log(Debug::Info) << "Loading groundcover:"; Log(Debug::Info) << "Loading groundcover:";
mGroundcoverStore.init(mStore.get<ESM::Static>(), fileCollections, groundcoverFiles, encoder); mGroundcoverStore.init(mStore.get<ESM::Static>(), fileCollections, groundcoverFiles, encoder, listener);
} }
bool World::startSpellCast(const Ptr &actor) bool World::startSpellCast(const Ptr &actor)

View file

@ -171,7 +171,9 @@ namespace MWWorld
void loadContentFiles(const Files::Collections& fileCollections, const std::vector<std::string>& content, void loadContentFiles(const Files::Collections& fileCollections, const std::vector<std::string>& content,
ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener); ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener);
void loadGroundcoverFiles(const Files::Collections& fileCollections, const std::vector<std::string>& groundcoverFiles, ToUTF8::Utf8Encoder* encoder); void loadGroundcoverFiles(const Files::Collections& fileCollections,
const std::vector<std::string>& groundcoverFiles, ToUTF8::Utf8Encoder* encoder,
Loading::Listener* listener);
float feetToGameUnits(float feet); float feetToGameUnits(float feet);
float getActivationDistancePlusTelekinesis(); float getActivationDistancePlusTelekinesis();

View file

@ -19,6 +19,7 @@
#include <components/misc/resourcehelpers.hpp> #include <components/misc/resourcehelpers.hpp>
#include <components/misc/stringops.hpp> #include <components/misc/stringops.hpp>
#include <components/esm3/readerscache.hpp> #include <components/esm3/readerscache.hpp>
#include <components/loadinglistener/loadinglistener.hpp>
#include <algorithm> #include <algorithm>
#include <filesystem> #include <filesystem>
@ -190,7 +191,7 @@ namespace EsmLoader
reader.skipRecord(); 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(); Log(Debug::Info) << "Loading ESM file " << reader.getName();
@ -204,12 +205,15 @@ namespace EsmLoader
continue; continue;
} }
loadRecord(query, recName, reader, content); loadRecord(query, recName, reader, content);
if (listener != nullptr)
listener->setProgress(fileProgress * reader.getFileOffset() / reader.getFileSize());
} }
} }
ShallowContent shallowLoad(const Query& query, const std::vector<std::string>& contentFiles, ShallowContent shallowLoad(const Query& query, const std::vector<std::string>& contentFiles,
const Files::Collections& fileCollections, ESM::ReadersCache& readers, const Files::Collections& fileCollections, ESM::ReadersCache& readers,
ToUTF8::Utf8Encoder* encoder) ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener)
{ {
ShallowContent result; ShallowContent result;
@ -232,6 +236,12 @@ namespace EsmLoader
continue; continue;
} }
if (listener != nullptr)
{
listener->setLabel(file);
listener->setProgressRange(fileProgress);
}
const Files::MultiDirCollection& collection = fileCollections.getCollection(extension); const Files::MultiDirCollection& collection = fileCollections.getCollection(extension);
const ESM::ReadersCache::BusyItem reader = readers.get(i); const ESM::ReadersCache::BusyItem reader = readers.get(i);
@ -241,7 +251,7 @@ namespace EsmLoader
if (query.mLoadCells) if (query.mLoadCells)
reader->resolveParentFileIndices(readers); reader->resolveParentFileIndices(readers);
loadEsm(query, *reader, result); loadEsm(query, *reader, result, listener);
} }
return result; return result;
@ -290,11 +300,12 @@ namespace EsmLoader
} }
EsmData loadEsmData(const Query& query, const std::vector<std::string>& contentFiles, EsmData loadEsmData(const Query& query, const std::vector<std::string>& 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..."; 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; std::ostringstream loaded;

View file

@ -16,10 +16,17 @@ namespace Files
class Collections; class Collections;
} }
namespace Loading
{
class Listener;
}
namespace EsmLoader namespace EsmLoader
{ {
struct EsmData; struct EsmData;
inline constexpr std::size_t fileProgress = 1000;
struct Query struct Query
{ {
bool mLoadActivators = false; bool mLoadActivators = false;
@ -33,7 +40,7 @@ namespace EsmLoader
EsmData loadEsmData(const Query& query, const std::vector<std::string>& contentFiles, EsmData loadEsmData(const Query& query, const std::vector<std::string>& contentFiles,
const Files::Collections& fileCollections, ESM::ReadersCache& readers, const Files::Collections& fileCollections, ESM::ReadersCache& readers,
ToUTF8::Utf8Encoder* encoder); ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener = nullptr);
} }
#endif #endif