mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 07:45:39 +00:00
Replace VisitorCellIdIsESM3Ext with RefId::getIf function
This commit is contained in:
parent
4fd8ed8f13
commit
20129568e6
2 changed files with 8 additions and 24 deletions
|
@ -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…
Reference in a new issue