diff --git a/apps/essimporter/importercontext.hpp b/apps/essimporter/importercontext.hpp index 788946b762..03ea9d0943 100644 --- a/apps/essimporter/importercontext.hpp +++ b/apps/essimporter/importercontext.hpp @@ -60,7 +60,7 @@ namespace ESSImport , mHour(0.f) , mNextActorId(0) { - mPlayer.mCellId = ESM::Cell::generateIdForExteriorCell(0, 0); + mPlayer.mCellId = ESM::RefId::esm3ExteriorCell(0, 0); mPlayer.mLastKnownExteriorPosition[0] = mPlayer.mLastKnownExteriorPosition[1] = mPlayer.mLastKnownExteriorPosition[2] = 0.0f; mPlayer.mHasMark = 0; diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp index 5d67900c10..125a684f86 100644 --- a/apps/opencs/model/world/refcollection.cpp +++ b/apps/opencs/model/world/refcollection.cpp @@ -73,7 +73,7 @@ void CSMWorld::RefCollection::load(ESM::ESMReader& reader, int cellIndex, bool b // Autocalculate the cell index from coordinates first std::pair index = ref.getCellIndex(); - ref.mCell = ESM::RefId::vec2i(index); + ref.mCell = ESM::RefId::esm3ExteriorCell(index.first, index.second); // Handle non-base moved references if (!base && isMoved) @@ -89,7 +89,7 @@ void CSMWorld::RefCollection::load(ESM::ESMReader& reader, int cellIndex, bool b if (index.first != mref.mTarget[0] || index.second != mref.mTarget[1]) { ESM::RefId indexCell = ref.mCell; - ref.mCell = ESM::RefId::vec2i({ mref.mTarget[0], mref.mTarget[1] }); + ref.mCell = ESM::RefId::esm3ExteriorCell(mref.mTarget[0], mref.mTarget[1]); CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Cell, mCells.getId(cellIndex)); messages.add(id, "The position of the moved reference " + ref.mRefID.toDebugString() + " (cell " + indexCell.toDebugString() + ")" diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index eb1099720f..abd233b07f 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -1109,7 +1109,7 @@ namespace MWGui void MapWindow::setGlobalMapMarkerTooltip(MyGUI::Widget* markerWidget, int x, int y) { - ESM::RefId cellRefId = ESM::Cell::generateIdForExteriorCell(x, y); + ESM::RefId cellRefId = ESM::RefId::esm3ExteriorCell(x, y); CustomMarkerCollection::RangeType markers = mCustomMarkers.getMarkers(cellRefId); std::vector destNotes; for (CustomMarkerCollection::ContainerType::const_iterator it = markers.first; it != markers.second; ++it) diff --git a/apps/openmw/mwworld/cellref.cpp b/apps/openmw/mwworld/cellref.cpp index cdfc211124..ced128db40 100644 --- a/apps/openmw/mwworld/cellref.cpp +++ b/apps/openmw/mwworld/cellref.cpp @@ -90,7 +90,7 @@ namespace MWWorld else { const osg::Vec2i index = positionToCellIndex(ref.mDoorDest.pos[0], ref.mDoorDest.pos[1]); - return ESM::Cell::generateIdForExteriorCell(index.x(), index.y()); + return ESM::RefId::esm3ExteriorCell(index.x(), index.y()); } }; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 265a7316ee..8d0bc5782e 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -379,7 +379,7 @@ namespace MWWorld pos.rot[2] = 0; osg::Vec2i exteriorCellPos = positionToCellIndex(pos.pos[0], pos.pos[1]); - ESM::RefId cellId = ESM::Cell::generateIdForExteriorCell(exteriorCellPos.x(), exteriorCellPos.y()); + ESM::RefId cellId = ESM::RefId::esm3ExteriorCell(exteriorCellPos.x(), exteriorCellPos.y()); mWorldScene->changeToExteriorCell(cellId, pos, true); } } @@ -984,7 +984,7 @@ namespace MWWorld } removeContainerScripts(getPlayerPtr()); osg::Vec2i exteriorCellPos = positionToCellIndex(position.pos[0], position.pos[1]); - ESM::RefId cellId = ESM::Cell::generateIdForExteriorCell(exteriorCellPos.x(), exteriorCellPos.y()); + ESM::RefId cellId = ESM::RefId::esm3ExteriorCell(exteriorCellPos.x(), exteriorCellPos.y()); mWorldScene->changeToExteriorCell(cellId, position, adjustPlayerPos, changeEvent); addContainerScripts(getPlayerPtr(), getPlayerPtr().getCell()); mRendering->getCamera()->instantTransition(); diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index 098821d26d..f1e11e295d 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -226,9 +226,9 @@ MWWorld::CellStore* MWWorld::WorldModel::getInterior(std::string_view name) struct VisitorCellIdIsESM3Ext { - bool operator()(const ESM::Vec2iRefId& id) + bool operator()(const ESM::ESM3ExteriorCellRefId& id) { - coordOut = { id.getValue().first, id.getValue().second }; + coordOut = { id.getX(), id.getY() }; return true; } diff --git a/apps/openmw_test_suite/mwworld/test_store.cpp b/apps/openmw_test_suite/mwworld/test_store.cpp index 1b89e79f54..6a38b1cd5b 100644 --- a/apps/openmw_test_suite/mwworld/test_store.cpp +++ b/apps/openmw_test_suite/mwworld/test_store.cpp @@ -448,7 +448,7 @@ namespace refId = RecordType::indexToRefId(index); else if constexpr (std::is_same_v) { - refId = ESM::Cell::generateIdForExteriorCell(0, 0); + refId = ESM::RefId::esm3ExteriorCell(0, 0); } else refId = ESM::StringRefId(stringId); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index a6fcd4604e..55fb7a76d4 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -91,7 +91,7 @@ add_component_dir(esm attr common defs esmcommon records util luascripts format generatedrefid indexrefid serializerefid - vec2irefid + esm3exteriorcellrefid ) add_component_dir(fx pass technique lexer widgets stateupdater) diff --git a/components/esm/esm3exteriorcellrefid.cpp b/components/esm/esm3exteriorcellrefid.cpp new file mode 100644 index 0000000000..c4c210032a --- /dev/null +++ b/components/esm/esm3exteriorcellrefid.cpp @@ -0,0 +1,26 @@ +#include "esm3exteriorcellrefid.hpp" + +#include +#include + +namespace ESM +{ + std::string ESM3ExteriorCellRefId::toString() const + { + std::ostringstream stream; + stream << "# " << mY << ", " << mY; + return stream.str(); + } + + std::string ESM3ExteriorCellRefId::toDebugString() const + { + std::ostringstream stream; + stream << *this; + return stream.str(); + } + + std::ostream& operator<<(std::ostream& stream, ESM3ExteriorCellRefId value) + { + return stream << "Vec2i{" << value.mX << "," << value.mY << '}'; + } +} diff --git a/components/esm/esm3exteriorcellrefid.hpp b/components/esm/esm3exteriorcellrefid.hpp new file mode 100644 index 0000000000..00dd3ae26a --- /dev/null +++ b/components/esm/esm3exteriorcellrefid.hpp @@ -0,0 +1,55 @@ +#ifndef OPENMW_COMPONENTS_ESM_ESM3EXTERIORCELLREFID_HPP +#define OPENMW_COMPONENTS_ESM_ESM3EXTERIORCELLREFID_HPP + +#include +#include + +#include + +namespace ESM +{ + class ESM3ExteriorCellRefId + { + public: + constexpr ESM3ExteriorCellRefId() = default; + + constexpr explicit ESM3ExteriorCellRefId(int32_t x, int32_t y) noexcept + : mX(x) + , mY(y) + { + } + + std::string toString() const; + + std::string toDebugString() const; + + int32_t getX() const { return mX; } + int32_t getY() const { return mY; } + + constexpr bool operator==(ESM3ExteriorCellRefId rhs) const noexcept { return mX == rhs.mX && mY == rhs.mY; } + + constexpr bool operator<(ESM3ExteriorCellRefId rhs) const noexcept { return mX < rhs.mX && mY < rhs.mY; } + + friend std::ostream& operator<<(std::ostream& stream, ESM3ExteriorCellRefId value); + + friend struct std::hash; + + private: + int32_t mX = 0; + int32_t mY = 0; + }; +} + +namespace std +{ + template <> + struct hash + { + std::size_t operator()(ESM::ESM3ExteriorCellRefId value) const noexcept + { + return (53 + std::hash{}(value.mX)) * 53 + std::hash{}(value.mY); + } + }; +} + +#endif diff --git a/components/esm/refid.hpp b/components/esm/refid.hpp index a2c5a7174e..e4b97ceb7b 100644 --- a/components/esm/refid.hpp +++ b/components/esm/refid.hpp @@ -10,11 +10,11 @@ #include +#include "esm3exteriorcellrefid.hpp" #include "formidrefid.hpp" #include "generatedrefid.hpp" #include "indexrefid.hpp" #include "stringrefid.hpp" -#include "vec2irefid.hpp" namespace ESM { @@ -39,7 +39,7 @@ namespace ESM FormId = 3, Generated = 4, Index = 5, - Vec2i = 6, + ESM3ExteriorCell = 6, }; // RefId is used to represent an Id that identifies an ESM record. These Ids can then be used in @@ -72,7 +72,7 @@ namespace ESM // identified by index (i.e. ESM3 SKIL). static RefId index(RecNameInts recordType, std::uint32_t value) { return RefId(IndexRefId(recordType, value)); } - static RefId vec2i(std::pair value) { return RefId(Vec2iRefId(value)); } + static RefId esm3ExteriorCell(int32_t x, int32_t y) { return RefId(ESM3ExteriorCellRefId(x, y)); } constexpr RefId() = default; @@ -101,7 +101,7 @@ namespace ESM { } - constexpr RefId(Vec2iRefId value) noexcept + constexpr RefId(ESM3ExteriorCellRefId value) noexcept : mValue(value) { } diff --git a/components/esm/vec2irefid.cpp b/components/esm/vec2irefid.cpp deleted file mode 100644 index feae473a4e..0000000000 --- a/components/esm/vec2irefid.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "vec2irefid.hpp" - -#include -#include - -namespace ESM -{ - std::string Vec2iRefId::toString() const - { - std::ostringstream stream; - stream << "# " << mValue.first << ", " << mValue.second; - return stream.str(); - } - - std::string Vec2iRefId::toDebugString() const - { - std::ostringstream stream; - stream << *this; - return stream.str(); - } - - std::ostream& operator<<(std::ostream& stream, Vec2iRefId value) - { - return stream << "Vec2i{" << value.mValue.first << "," << value.mValue.second << '}'; - } -} diff --git a/components/esm/vec2irefid.hpp b/components/esm/vec2irefid.hpp deleted file mode 100644 index a8b0d0ea63..0000000000 --- a/components/esm/vec2irefid.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef OPENMW_COMPONENTS_ESM_VEC2IREFID_HPP -#define OPENMW_COMPONENTS_ESM_VEC2IREFID_HPP - -#include -#include - -#include - -namespace ESM -{ - class Vec2iRefId - { - public: - constexpr Vec2iRefId() = default; - - constexpr explicit Vec2iRefId(std::pair value) noexcept - : mValue(value) - { - } - - std::pair getValue() const { return mValue; } - - std::string toString() const; - - std::string toDebugString() const; - - constexpr bool operator==(Vec2iRefId rhs) const noexcept { return mValue == rhs.mValue; } - - constexpr bool operator<(Vec2iRefId rhs) const noexcept { return mValue < rhs.mValue; } - - friend std::ostream& operator<<(std::ostream& stream, Vec2iRefId value); - - friend struct std::hash; - - private: - std::pair mValue = std::pair(0, 0); - }; -} - -namespace std -{ - template <> - struct hash - { - std::size_t operator()(ESM::Vec2iRefId value) const noexcept - { - return (53 + std::hash{}(value.mValue.first)) * 53 + std::hash{}(value.mValue.second); - } - }; -} - -#endif diff --git a/components/esm3/cellid.cpp b/components/esm3/cellid.cpp index 00a0b93ca4..1c9382f546 100644 --- a/components/esm3/cellid.cpp +++ b/components/esm3/cellid.cpp @@ -50,11 +50,11 @@ namespace ESM out.mIndex = { 0, 0 }; return out; } - CellId operator()(const ESM::Vec2iRefId& id) + CellId operator()(const ESM::ESM3ExteriorCellRefId& id) { CellId out; out.mPaged = true; - out.mIndex = { id.getValue().first, id.getValue().second }; + out.mIndex = { id.getX(), id.getY() }; return out; } diff --git a/components/esm3/esmreader.cpp b/components/esm3/esmreader.cpp index 2cc1a81ef8..6c7c6cc5a7 100644 --- a/components/esm3/esmreader.cpp +++ b/components/esm3/esmreader.cpp @@ -96,7 +96,7 @@ namespace ESM cellId.load(*this); if (cellId.mPaged) { - return ESM::Cell::generateIdForExteriorCell(cellId.mIndex.mX, cellId.mIndex.mY); + return ESM::RefId::esm3ExteriorCell(cellId.mIndex.mX, cellId.mIndex.mY); } else { @@ -491,12 +491,12 @@ namespace ESM getExact(&index, sizeof(std::uint32_t)); return RefId::index(recordType, index); } - case RefIdType::Vec2i: + case RefIdType::ESM3ExteriorCell: { - std::pair vec2i; - getExact(&vec2i.first, sizeof(std::int32_t)); - getExact(&vec2i.second, sizeof(std::int32_t)); - return RefId::vec2i(vec2i); + int32_t x, y; + getExact(&x, sizeof(std::int32_t)); + getExact(&y, sizeof(std::int32_t)); + return RefId::esm3ExteriorCell(x, y); } } diff --git a/components/esm3/esmwriter.cpp b/components/esm3/esmwriter.cpp index 595d34ff3a..a536169970 100644 --- a/components/esm3/esmwriter.cpp +++ b/components/esm3/esmwriter.cpp @@ -62,11 +62,11 @@ namespace ESM mWriter.writeT(v.getValue()); } - void operator()(Vec2iRefId v) const + void operator()(ESM3ExteriorCellRefId v) const { - mWriter.writeT(RefIdType::Vec2i); - mWriter.writeT(v.getValue().first); - mWriter.writeT(v.getValue().second); + mWriter.writeT(RefIdType::ESM3ExteriorCell); + mWriter.writeT(v.getX()); + mWriter.writeT(v.getY()); } }; } diff --git a/components/esm3/loadcell.cpp b/components/esm3/loadcell.cpp index 04e7027e9b..73fd8967bd 100644 --- a/components/esm3/loadcell.cpp +++ b/components/esm3/loadcell.cpp @@ -64,11 +64,6 @@ namespace ESM return mId; } - ESM::RefId Cell::generateIdForExteriorCell(int x, int y) - { - return ESM::RefId::vec2i({ x, y }); - } - ESM::RefId Cell::generateIdForCell(bool exterior, std::string_view cellName, int x, int y) { if (!exterior) @@ -77,7 +72,7 @@ namespace ESM } else { - return generateIdForExteriorCell(x, y); + return ESM::RefId::esm3ExteriorCell(x, y); } } diff --git a/components/esm3/loadcell.hpp b/components/esm3/loadcell.hpp index 077fc4213d..c889a5a620 100644 --- a/components/esm3/loadcell.hpp +++ b/components/esm3/loadcell.hpp @@ -193,7 +193,6 @@ namespace ESM const ESM::RefId& updateId(); - static ESM::RefId generateIdForExteriorCell(int x, int y); static ESM::RefId generateIdForCell(bool exterior, std::string_view cellName, int x, int y); }; }