|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
#include "magiceffects.hpp"
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
|
|
|
|
|
@ -42,7 +43,10 @@
|
|
|
|
|
#include <components/esm4/loadligh.hpp>
|
|
|
|
|
#include <components/esm4/loadrefr.hpp>
|
|
|
|
|
#include <components/esm4/loadstat.hpp>
|
|
|
|
|
#include <components/esm4/readerutils.hpp>
|
|
|
|
|
#include <components/files/openfile.hpp>
|
|
|
|
|
#include <components/misc/tuplehelpers.hpp>
|
|
|
|
|
#include <components/resource/resourcesystem.hpp>
|
|
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
|
#include "../mwbase/luamanager.hpp"
|
|
|
|
@ -756,19 +760,47 @@ namespace MWWorld
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CellStore::listRefs(const ESM4::Cell& cell)
|
|
|
|
|
template <typename ReferenceInvocable>
|
|
|
|
|
static void visitCell4References(const ESM4::Cell& cell, ESM::ReadersCache& readers, ReferenceInvocable&& invocable)
|
|
|
|
|
{
|
|
|
|
|
auto& refs = MWBase::Environment::get().getWorld()->getStore().get<ESM4::Reference>();
|
|
|
|
|
auto stream = Files::openBinaryInputFileStream(cell.mReaderContext.filename);
|
|
|
|
|
ESM4::Reader readerESM4(
|
|
|
|
|
std::move(stream), cell.mReaderContext.filename, MWBase::Environment::get().getResourceSystem()->getVFS());
|
|
|
|
|
|
|
|
|
|
for (const auto& ref : refs)
|
|
|
|
|
readerESM4.setEncoder(readers.getStatelessEncoder());
|
|
|
|
|
readerESM4.restoreContext(cell.mReaderContext);
|
|
|
|
|
bool continueRead = true;
|
|
|
|
|
while (ESM::RefId::formIdRefId(readerESM4.getContext().currCell) == cell.mId && readerESM4.hasMoreRecs()
|
|
|
|
|
&& continueRead)
|
|
|
|
|
{
|
|
|
|
|
if (ref.mParent == cell.mId)
|
|
|
|
|
{
|
|
|
|
|
mIds.push_back(ref.mBaseObj);
|
|
|
|
|
}
|
|
|
|
|
continueRead = ESM4::ReaderUtils::readItem(
|
|
|
|
|
readerESM4,
|
|
|
|
|
[&](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)
|
|
|
|
|
{
|
|
|
|
|
ESM4::Reference ref;
|
|
|
|
|
ref.load(reader);
|
|
|
|
|
invocable(ref);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (esm4RecName == ESM::RecNameInts::REC_CELL4)
|
|
|
|
|
{
|
|
|
|
|
ESM4::Cell cellToLoad;
|
|
|
|
|
cellToLoad.load(reader); // This is necessary to exit
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
[&](ESM4::Reader& reader) {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CellStore::listRefs(const ESM4::Cell& cell)
|
|
|
|
|
{
|
|
|
|
|
visitCell4References(cell, mReaders, [&](ESM4::Reference& ref) { mIds.push_back(ref.mBaseObj); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CellStore::listRefs()
|
|
|
|
|
{
|
|
|
|
|
ESM::visit([&](auto&& cell) { listRefs(cell); }, mCellVariant);
|
|
|
|
@ -830,15 +862,7 @@ namespace MWWorld
|
|
|
|
|
|
|
|
|
|
void CellStore::loadRefs(const ESM4::Cell& cell, std::map<ESM::RefNum, ESM::RefId>& refNumToID)
|
|
|
|
|
{
|
|
|
|
|
auto& refs = MWBase::Environment::get().getWorld()->getStore().get<ESM4::Reference>();
|
|
|
|
|
|
|
|
|
|
for (const auto& ref : refs)
|
|
|
|
|
{
|
|
|
|
|
if (ref.mParent == cell.mId)
|
|
|
|
|
{
|
|
|
|
|
loadRef(ref, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
visitCell4References(cell, mReaders, [&](ESM4::Reference& ref) { loadRef(ref, false); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CellStore::loadRefs()
|
|
|
|
|