Replace VisitorCellIdIsESM3Ext with RefId::getIf function

depth-refraction
elsid 2 years ago
parent 4fd8ed8f13
commit 20129568e6
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -224,36 +224,14 @@ MWWorld::CellStore* MWWorld::WorldModel::getInterior(std::string_view name)
return result->second;
}
struct VisitorCellIdIsESM3Ext
{
bool operator()(const ESM::ESM3ExteriorCellRefId& id)
{
coordOut = { id.getX(), id.getY() };
return true;
}
template <typename T>
bool operator()(const T&)
{
return false;
}
std::pair<int32_t, int32_t> coordOut = {};
};
MWWorld::CellStore* MWWorld::WorldModel::getCell(const ESM::RefId& id)
{
auto result = mCells.find(id);
if (result != mCells.end())
return &result->second;
VisitorCellIdIsESM3Ext isESM3ExteriorVisitor;
if (visit(isESM3ExteriorVisitor, id)) // That is an exterior cell Id
{
return getExterior(isESM3ExteriorVisitor.coordOut.first, isESM3ExteriorVisitor.coordOut.second);
}
if (const auto* exteriorId = id.getIf<ESM::ESM3ExteriorCellRefId>())
return getExterior(exteriorId->getX(), exteriorId->getY());
const ESM4::Cell* cell4 = mStore.get<ESM4::Cell>().search(id);
CellStore* newCellStore = nullptr;

@ -136,6 +136,12 @@ namespace ESM
// Serialize into stable text format.
std::string serializeText() const;
template <class T>
const T* getIf() const
{
return std::get_if<T>(&mValue);
}
friend constexpr bool operator==(const RefId& l, const RefId& r) { return l.mValue == r.mValue; }
bool operator==(std::string_view rhs) const;

Loading…
Cancel
Save