1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-21 08:09:41 +00:00

Fixed large lambdas that affected readability.

This commit is contained in:
florent.teppe 2023-02-04 17:16:42 +01:00
parent 1caed2de2a
commit f3d5f6345e

View file

@ -40,27 +40,28 @@ namespace MWWorld
const ESM::RefNum& CellRef::getOrAssignRefNum(ESM::RefNum& lastAssignedRefNum) const ESM::RefNum& CellRef::getOrAssignRefNum(ESM::RefNum& lastAssignedRefNum)
{ {
auto esm3Visit = [&](ESM::CellRef& ref) -> const ESM::RefNum& {
if (!ref.mRefNum.isSet())
{
// Generated RefNums have negative mContentFile
assert(lastAssignedRefNum.mContentFile < 0);
lastAssignedRefNum.mIndex++;
if (lastAssignedRefNum.mIndex == 0) // mIndex overflow, so mContentFile should be changed
{
if (lastAssignedRefNum.mContentFile > std::numeric_limits<int32_t>::min())
lastAssignedRefNum.mContentFile--;
else
Log(Debug::Error) << "RefNum counter overflow in CellRef::getOrAssignRefNum";
}
ref.mRefNum = lastAssignedRefNum;
mChanged = true;
}
return ref.mRefNum;
};
return std::visit( return std::visit(
RefVisit{ RefVisit{
[&](ESM4::Reference& /*ref*/) -> const ESM::RefNum& { return emptyRefNum; }, [&](ESM4::Reference& /*ref*/) -> const ESM::RefNum& { return emptyRefNum; },
[&](ESM::CellRef& ref) -> const ESM::RefNum& { esm3Visit,
if (!ref.mRefNum.isSet())
{
// Generated RefNums have negative mContentFile
assert(lastAssignedRefNum.mContentFile < 0);
lastAssignedRefNum.mIndex++;
if (lastAssignedRefNum.mIndex == 0) // mIndex overflow, so mContentFile should be changed
{
if (lastAssignedRefNum.mContentFile > std::numeric_limits<int32_t>::min())
lastAssignedRefNum.mContentFile--;
else
Log(Debug::Error) << "RefNum counter overflow in CellRef::getOrAssignRefNum";
}
ref.mRefNum = lastAssignedRefNum;
mChanged = true;
}
return ref.mRefNum;
},
}, },
mCellRef.mVariant); mCellRef.mVariant);
} }
@ -146,26 +147,27 @@ namespace MWWorld
void CellRef::applyChargeRemainderToBeSubtracted(float chargeRemainder) void CellRef::applyChargeRemainderToBeSubtracted(float chargeRemainder)
{ {
std::visit(RefVisit{ auto esm3Visit = [&](ESM::CellRef& cellRef3) {
[&](ESM4::Reference& /*ref*/) {}, cellRef3.mChargeIntRemainder += std::abs(chargeRemainder);
[&](ESM::CellRef& cellRef3) { if (cellRef3.mChargeIntRemainder > 1.0f)
cellRef3.mChargeIntRemainder += std::abs(chargeRemainder); {
if (cellRef3.mChargeIntRemainder > 1.0f) float newChargeRemainder = (cellRef3.mChargeIntRemainder - std::floor(cellRef3.mChargeIntRemainder));
{ if (cellRef3.mChargeInt <= static_cast<int>(cellRef3.mChargeIntRemainder))
float newChargeRemainder {
= (cellRef3.mChargeIntRemainder - std::floor(cellRef3.mChargeIntRemainder)); cellRef3.mChargeInt = 0;
if (cellRef3.mChargeInt <= static_cast<int>(cellRef3.mChargeIntRemainder)) }
{ else
cellRef3.mChargeInt = 0; {
} cellRef3.mChargeInt -= static_cast<int>(cellRef3.mChargeIntRemainder);
else }
{ cellRef3.mChargeIntRemainder = newChargeRemainder;
cellRef3.mChargeInt -= static_cast<int>(cellRef3.mChargeIntRemainder); }
} };
cellRef3.mChargeIntRemainder = newChargeRemainder; std::visit(
} RefVisit{
}, [&](ESM4::Reference& /*ref*/) {},
}, esm3Visit,
},
mCellRef.mVariant); mCellRef.mVariant);
} }
@ -180,7 +182,6 @@ namespace MWWorld
const std::string& CellRef::getGlobalVariable() const const std::string& CellRef::getGlobalVariable() const
{ {
return std::visit(RefVisit{ return std::visit(RefVisit{
[&](const ESM4::Reference& /*ref*/) -> const std::string& { return emptyString; }, [&](const ESM4::Reference& /*ref*/) -> const std::string& { return emptyString; },
[&](const ESM::CellRef& ref) -> const std::string& { return ref.mGlobalVariable; }, [&](const ESM::CellRef& ref) -> const std::string& { return ref.mGlobalVariable; },