1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-04-10 15:45:37 +00:00

Disable lazy loading

This commit is contained in:
Petr Mikheev 2023-04-08 15:51:47 +02:00
parent edfc6b78c8
commit 2365ba2ce0
2 changed files with 9 additions and 45 deletions

View File

@ -762,55 +762,18 @@ namespace MWWorld
template <typename ReferenceInvocable> template <typename ReferenceInvocable>
static void visitCell4References(const ESM4::Cell& cell, ESM::ReadersCache& readers, ReferenceInvocable&& invocable) static void visitCell4References(const ESM4::Cell& cell, ESM::ReadersCache& readers, ReferenceInvocable&& invocable)
{ {
auto stream = Files::openBinaryInputFileStream(cell.mReaderContext.filename); for (const ESM4::Reference& ref : MWBase::Environment::get().getWorld()->getStore().get<ESM4::Reference>())
stream->seekg(0);
ESM4::Reader readerESM4(
std::move(stream), cell.mReaderContext.filename, MWBase::Environment::get().getResourceSystem()->getVFS());
readerESM4.setEncoder(readers.getStatelessEncoder());
bool contextValid = cell.mReaderContext.filePos != std::streampos(-1);
if (contextValid)
readerESM4.restoreContext(cell.mReaderContext);
while (
(ESM::RefId::formIdRefId(readerESM4.currCell()) == cell.mId || !contextValid) && readerESM4.hasMoreRecs())
{ {
if (!contextValid) if (ref.mParent == cell.mId)
readerESM4.exitGroupCheck(); {
invocable(ref);
auto onRecord = [&](ESM4::Reader& reader) { }
auto recordType = static_cast<ESM4::RecordTypes>(reader.hdr().record.typeId);
ESM::RecNameInts esm4RecName = static_cast<ESM::RecNameInts>(ESM::esm4Recname(recordType));
if (esm4RecName == ESM::RecNameInts::REC_REFR4 && contextValid)
{
reader.getRecordData();
ESM4::Reference ref;
ref.load(reader);
invocable(ref);
return true;
}
else if (esm4RecName == ESM::RecNameInts::REC_CELL4)
{
reader.getRecordData();
ESM4::Cell cellToLoad;
cellToLoad.load(reader); // This is necessary to exit or to find the correct cell
if (cellToLoad.mId == cell.mId)
contextValid = true;
return true;
}
return false;
};
if (!ESM4::ReaderUtils::readItem(readerESM4, onRecord, [&](ESM4::Reader& reader) {}))
break;
} }
} }
void CellStore::listRefs(const ESM4::Cell& cell) void CellStore::listRefs(const ESM4::Cell& cell)
{ {
visitCell4References(cell, mReaders, [&](ESM4::Reference& ref) { mIds.push_back(ref.mBaseObj); }); visitCell4References(cell, mReaders, [&](const ESM4::Reference& ref) { mIds.push_back(ref.mBaseObj); });
} }
void CellStore::listRefs() void CellStore::listRefs()
@ -874,7 +837,7 @@ namespace MWWorld
void CellStore::loadRefs(const ESM4::Cell& cell, std::map<ESM::RefNum, ESM::RefId>& refNumToID) void CellStore::loadRefs(const ESM4::Cell& cell, std::map<ESM::RefNum, ESM::RefId>& refNumToID)
{ {
visitCell4References(cell, mReaders, [&](ESM4::Reference& ref) { loadRef(ref, false); }); visitCell4References(cell, mReaders, [&](const ESM4::Reference& ref) { loadRef(ref, false); });
} }
void CellStore::loadRefs() void CellStore::loadRefs()

View File

@ -30,6 +30,7 @@ namespace ESM4
struct Static; struct Static;
struct Cell; struct Cell;
struct Light; struct Light;
struct Reference;
} }
namespace ESM namespace ESM
@ -105,7 +106,7 @@ namespace MWWorld
// Special entry which is hardcoded and not loaded from an ESM // Special entry which is hardcoded and not loaded from an ESM
Store<ESM::Attribute>, Store<ESM::Attribute>,
Store<ESM4::Static>, Store<ESM4::Cell>, Store<ESM4::Light>>; Store<ESM4::Static>, Store<ESM4::Cell>, Store<ESM4::Light>, Store<ESM4::Reference>>;
private: private:
template <typename T> template <typename T>