Skip to content

Commit

Permalink
Merge branch 'loadingesm4' into 'master'
Browse files Browse the repository at this point in the history
Track ESM4 file loading progress

See merge request OpenMW/openmw!4516
  • Loading branch information
psi29a committed Jan 17, 2025
2 parents fe047d9 + 9fc62be commit e515e99
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/openmw/mwworld/esmloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
11 changes: 9 additions & 2 deletions apps/openmw/mwworld/esmstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&) {});
}

Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwworld/esmstore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T>
const Store<T>& get() const
Expand Down
2 changes: 1 addition & 1 deletion components/esm4/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e515e99

Please sign in to comment.