From 20129568e644532473a72912425e894ebbfe94db Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 8 Apr 2023 13:33:56 +0200 Subject: [PATCH] Replace VisitorCellIdIsESM3Ext with RefId::getIf function --- apps/openmw/mwworld/worldmodel.cpp | 26 ++------------------------ components/esm/refid.hpp | 6 ++++++ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index d087c5cd57..07a5ee37ee 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -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 - bool operator()(const T&) - { - return false; - } - - std::pair 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()) + return getExterior(exteriorId->getX(), exteriorId->getY()); const ESM4::Cell* cell4 = mStore.get().search(id); CellStore* newCellStore = nullptr; diff --git a/components/esm/refid.hpp b/components/esm/refid.hpp index 3722c8db68..bfed568b79 100644 --- a/components/esm/refid.hpp +++ b/components/esm/refid.hpp @@ -136,6 +136,12 @@ namespace ESM // Serialize into stable text format. std::string serializeText() const; + template + const T* getIf() const + { + return std::get_if(&mValue); + } + friend constexpr bool operator==(const RefId& l, const RefId& r) { return l.mValue == r.mValue; } bool operator==(std::string_view rhs) const;