mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-13 00:13:17 +00:00
applies review changes
filepos changed to an actual file pos moved lambda declaration out of function call
This commit is contained in:
parent
464092e323
commit
a3a7767093
3 changed files with 30 additions and 34 deletions
|
|
@ -765,52 +765,48 @@ namespace MWWorld
|
||||||
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);
|
auto stream = Files::openBinaryInputFileStream(cell.mReaderContext.filename);
|
||||||
const ESM::Format format = ESM::readFormat(*stream);
|
|
||||||
assert(format == ESM::Format::Tes4);
|
|
||||||
stream->seekg(0);
|
stream->seekg(0);
|
||||||
|
|
||||||
ESM4::Reader readerESM4(
|
ESM4::Reader readerESM4(
|
||||||
std::move(stream), cell.mReaderContext.filename, MWBase::Environment::get().getResourceSystem()->getVFS());
|
std::move(stream), cell.mReaderContext.filename, MWBase::Environment::get().getResourceSystem()->getVFS());
|
||||||
|
|
||||||
readerESM4.setEncoder(readers.getStatelessEncoder());
|
readerESM4.setEncoder(readers.getStatelessEncoder());
|
||||||
bool contextValid = cell.mReaderContext.filePos != std::numeric_limits<std::size_t>::max();
|
bool contextValid = cell.mReaderContext.filePos != std::streampos(-1);
|
||||||
if (contextValid)
|
if (contextValid)
|
||||||
readerESM4.restoreContext(cell.mReaderContext);
|
readerESM4.restoreContext(cell.mReaderContext);
|
||||||
|
|
||||||
while ((ESM::RefId::formIdRefId(readerESM4.getContext().currCell) == cell.mId || !contextValid)
|
while (
|
||||||
&& readerESM4.hasMoreRecs())
|
(ESM::RefId::formIdRefId(readerESM4.currCell()) == cell.mId || !contextValid) && readerESM4.hasMoreRecs())
|
||||||
{
|
{
|
||||||
if (!contextValid)
|
if (!contextValid)
|
||||||
readerESM4.exitGroupCheck();
|
readerESM4.exitGroupCheck();
|
||||||
if (!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 && 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;
|
auto onRecord = [&](ESM4::Reader& reader) {
|
||||||
},
|
auto recordType = static_cast<ESM4::RecordTypes>(reader.hdr().record.typeId);
|
||||||
[&](ESM4::Reader& reader) {}))
|
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;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ namespace ESM4
|
||||||
ReaderContext Reader::getContext()
|
ReaderContext Reader::getContext()
|
||||||
{
|
{
|
||||||
mCtx.filePos = mStream->tellg();
|
mCtx.filePos = mStream->tellg();
|
||||||
if (mCtx.filePos == std::numeric_limits<std::size_t>::max())
|
if (mCtx.filePos == std::streampos(-1))
|
||||||
return mCtx;
|
return mCtx;
|
||||||
mCtx.filePos -= mCtx.recHeaderSize; // update file position
|
mCtx.filePos -= mCtx.recHeaderSize; // update file position
|
||||||
return mCtx;
|
return mCtx;
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ namespace ESM4
|
||||||
// case the file was re-opened. default = TES5 size,
|
// case the file was re-opened. default = TES5 size,
|
||||||
// can be reduced for TES4 by setRecHeaderSize()
|
// can be reduced for TES4 by setRecHeaderSize()
|
||||||
|
|
||||||
std::size_t filePos; // assume that the record header will be re-read once
|
std::streampos filePos; // assume that the record header will be re-read once
|
||||||
// the context is restored
|
// the context is restored
|
||||||
|
|
||||||
// for keeping track of things
|
// for keeping track of things
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue