diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 3b9aae37d4..24866fe365 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -17,7 +17,6 @@ #include "../mwworld/actionteleport.hpp" #include "../mwworld/actiontrap.hpp" #include "../mwworld/cellstore.hpp" -#include "../mwworld/cellutils.hpp" #include "../mwworld/containerstore.hpp" #include "../mwworld/customdata.hpp" #include "../mwworld/esmstore.hpp" diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index 8c1e0263a3..cedd09b4b2 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -23,7 +23,6 @@ #include "../mwbase/world.hpp" #include "../mwworld/cellstore.hpp" -#include "../mwworld/cellutils.hpp" #include "../mwworld/esmstore.hpp" #include "../mwworld/player.hpp" #include "../mwworld/worldmodel.hpp" @@ -277,7 +276,7 @@ namespace MWGui if (!mInterior) { - cellIndex = MWWorld::positionToCellIndex(worldX, worldY); + cellIndex = ESM::positionToCellIndex(worldX, worldY); nX = (worldX - cellSize * cellIndex.x()) / cellSize; // Image space is -Y up, cells are Y up nY = 1 - (worldY - cellSize * cellIndex.y()) / cellSize; diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 8637e98a06..21d503aac8 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -15,7 +15,6 @@ #include "../mwworld/actionteleport.hpp" #include "../mwworld/cellstore.hpp" -#include "../mwworld/cellutils.hpp" #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" #include "../mwworld/esmstore.hpp" @@ -126,8 +125,7 @@ namespace MWGui { std::string_view cellname = transport[i].mCellName; bool interior = true; - const osg::Vec2i cellIndex - = MWWorld::positionToCellIndex(transport[i].mPos.pos[0], transport[i].mPos.pos[1]); + const osg::Vec2i cellIndex = ESM::positionToCellIndex(transport[i].mPos.pos[0], transport[i].mPos.pos[1]); if (cellname.empty()) { MWWorld::CellStore& cell = MWBase::Environment::get().getWorldModel()->getExterior( @@ -194,7 +192,7 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode(); MWBase::Environment::get().getWindowManager()->fadeScreenOut(1); - osg::Vec2i posCell = MWWorld::positionToCellIndex(pos.pos[0], pos.pos[1]); + osg::Vec2i posCell = ESM::positionToCellIndex(pos.pos[0], pos.pos[1]); ESM::RefId cellId = ESM::Cell::generateIdForCell(!interior, cellname, posCell.x(), posCell.y()); // Teleports any followers, too. diff --git a/apps/openmw/mwlua/worldview.cpp b/apps/openmw/mwlua/worldview.cpp index 9ccc1caaf8..f5699dff89 100644 --- a/apps/openmw/mwlua/worldview.cpp +++ b/apps/openmw/mwlua/worldview.cpp @@ -10,7 +10,6 @@ #include "../mwclass/container.hpp" -#include "../mwworld/cellutils.hpp" #include "../mwworld/class.hpp" #include "../mwworld/timestamp.hpp" #include "../mwworld/worldmodel.hpp" diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index a14a2f0ede..e493f3d911 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -14,7 +14,6 @@ #include "../mwbase/world.hpp" #include "../mwworld/cellstore.hpp" -#include "../mwworld/cellutils.hpp" #include "../mwworld/class.hpp" #include "../mwworld/manualref.hpp" #include "../mwworld/player.hpp" @@ -401,7 +400,7 @@ namespace MWScript store = &worldModel->getCell(cellID); if (store->isExterior()) { - const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y); + const osg::Vec2i cellIndex = ESM::positionToCellIndex(x, y); store = &worldModel->getExterior( ESM::ExteriorCellIndex(cellIndex.x(), cellIndex.y(), store->getCell()->getWorldSpace())); } @@ -417,7 +416,7 @@ namespace MWScript Log(Debug::Warning) << error; if (!isPlayer) return; - const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y); + const osg::Vec2i cellIndex = ESM::positionToCellIndex(x, y); store = &worldModel->getExterior( ESM::ExteriorCellIndex(cellIndex.x(), cellIndex.y(), store->getCell()->getWorldSpace())); } @@ -468,7 +467,7 @@ namespace MWScript { world->getPlayer().setTeleported(true); } - const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y); + const osg::Vec2i cellIndex = ESM::positionToCellIndex(x, y); // another morrowind oddity: player will be moved to the exterior cell at this location, // non-player actors will move within the cell they are in. @@ -569,7 +568,7 @@ namespace MWScript MWWorld::CellStore* store = nullptr; if (player.getCell()->isExterior()) { - const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y); + const osg::Vec2i cellIndex = ESM::positionToCellIndex(x, y); store = &MWBase::Environment::get().getWorldModel()->getExterior(ESM::ExteriorCellIndex( cellIndex.x(), cellIndex.y(), player.getCell()->getCell()->getWorldSpace())); } diff --git a/apps/openmw/mwworld/actionteleport.cpp b/apps/openmw/mwworld/actionteleport.cpp index 03efcff742..926e958e95 100644 --- a/apps/openmw/mwworld/actionteleport.cpp +++ b/apps/openmw/mwworld/actionteleport.cpp @@ -11,7 +11,6 @@ #include "../mwmechanics/creaturestats.hpp" #include "../mwworld/cellstore.hpp" -#include "../mwworld/cellutils.hpp" #include "../mwworld/class.hpp" #include "../mwworld/worldmodel.hpp" diff --git a/apps/openmw/mwworld/cellref.cpp b/apps/openmw/mwworld/cellref.cpp index dcfc7ae6b7..917d9e16d5 100644 --- a/apps/openmw/mwworld/cellref.cpp +++ b/apps/openmw/mwworld/cellref.cpp @@ -10,7 +10,6 @@ #include #include -#include #include namespace MWWorld @@ -89,7 +88,7 @@ namespace MWWorld } else { - const osg::Vec2i index = positionToCellIndex(ref.mDoorDest.pos[0], ref.mDoorDest.pos[1]); + const osg::Vec2i index = ESM::positionToCellIndex(ref.mDoorDest.pos[0], ref.mDoorDest.pos[1]); return ESM::RefId::esm3ExteriorCell(index.x(), index.y()); } }; diff --git a/apps/openmw/mwworld/cellutils.hpp b/apps/openmw/mwworld/cellutils.hpp deleted file mode 100644 index 978e358c8b..0000000000 --- a/apps/openmw/mwworld/cellutils.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef OPENMW_MWWORLD_CELLUTILS_H -#define OPENMW_MWWORLD_CELLUTILS_H - -#include - -#include - -#include - -namespace MWWorld -{ - inline osg::Vec2i positionToCellIndex(float x, float y, bool esm4Ext = false) - { - const float cellSize = esm4Ext ? Constants::ESM4CellSizeInUnits : Constants::CellSizeInUnits; - return { static_cast(std::floor(x / cellSize)), static_cast(std::floor(y / cellSize)) }; - } -} - -#endif diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 5dc35ef2d3..228f0892bb 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -40,7 +40,6 @@ #include "cellpreloader.hpp" #include "cellstore.hpp" -#include "cellutils.hpp" #include "cellvisitors.hpp" #include "class.hpp" #include "esmstore.hpp" @@ -525,7 +524,7 @@ namespace MWWorld if (distance <= maxDistance) return *currentGridCenter; } - return positionToCellIndex(pos.x(), pos.y(), isEsm4Ext); + return ESM::positionToCellIndex(pos.x(), pos.y(), isEsm4Ext); } void Scene::playerMoved(const osg::Vec3f& pos) @@ -1293,7 +1292,7 @@ namespace MWWorld else { osg::Vec3f pos = dest.mPos.asVec3(); - const osg::Vec2i cellIndex = positionToCellIndex(pos.x(), pos.y()); + const osg::Vec2i cellIndex = ESM::positionToCellIndex(pos.x(), pos.y()); preloadCell(mWorld.getWorldModel().getExterior( ESM::ExteriorCellIndex(cellIndex.x(), cellIndex.y(), extWorldspace)), true); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 5d889f5a44..40d774d7d4 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -95,7 +95,6 @@ #include "projectilemanager.hpp" #include "weather.hpp" -#include "cellutils.hpp" #include "contentloader.hpp" #include "esmloader.hpp" @@ -380,7 +379,7 @@ namespace MWWorld pos.rot[1] = 0; pos.rot[2] = 0; - osg::Vec2i exteriorCellPos = positionToCellIndex(pos.pos[0], pos.pos[1]); + osg::Vec2i exteriorCellPos = ESM::positionToCellIndex(pos.pos[0], pos.pos[1]); ESM::RefId cellId = ESM::RefId::esm3ExteriorCell(exteriorCellPos.x(), exteriorCellPos.y()); mWorldScene->changeToExteriorCell(cellId, pos, true); } @@ -1245,7 +1244,7 @@ namespace MWWorld MWWorld::Ptr World::moveObject(const Ptr& ptr, const osg::Vec3f& position, bool movePhysics, bool moveToActive) { - const osg::Vec2i index = positionToCellIndex(position.x(), position.y()); + const osg::Vec2i index = ESM::positionToCellIndex(position.x(), position.y()); CellStore* cell = ptr.getCell(); ESM::RefId worldspaceId @@ -2064,7 +2063,7 @@ namespace MWWorld throw std::runtime_error("copyObjectToCell(): cannot copy object to null cell"); if (cell->isExterior()) { - const osg::Vec2i index = positionToCellIndex(pos.pos[0], pos.pos[1]); + const osg::Vec2i index = ESM::positionToCellIndex(pos.pos[0], pos.pos[1]); cell = &mWorldModel.getExterior( ESM::ExteriorCellIndex(index.x(), index.y(), cell->getCell()->getWorldSpace())); } diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index 16564b4e91..d0c47dd6b1 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -16,7 +16,6 @@ #include "../mwbase/world.hpp" #include "cellstore.hpp" -#include "cellutils.hpp" #include "esmstore.hpp" namespace @@ -333,7 +332,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCellByPosition( { if (cellInSameWorldSpace && !cellInSameWorldSpace->isExterior()) return *cellInSameWorldSpace; - const osg::Vec2i cellIndex = positionToCellIndex(pos.x(), pos.y()); + const osg::Vec2i cellIndex = ESM::positionToCellIndex(pos.x(), pos.y()); ESM::RefId exteriorWorldspace = cellInSameWorldSpace ? cellInSameWorldSpace->getCell()->getWorldSpace() : ESM::Cell::sDefaultWorldspaceId; return getExterior(ESM::ExteriorCellIndex(cellIndex.x(), cellIndex.y(), exteriorWorldspace)); diff --git a/components/esm/util.hpp b/components/esm/util.hpp index d6d9feb3c4..b5eeb1fa65 100644 --- a/components/esm/util.hpp +++ b/components/esm/util.hpp @@ -1,7 +1,10 @@ #ifndef OPENMW_ESM_UTIL_H #define OPENMW_ESM_UTIL_H +#include #include +#include +#include #include #include @@ -80,6 +83,13 @@ namespace ESM { return isESM4Ext ? Constants::ESM4CellSizeInUnits : Constants::CellSizeInUnits; } + + inline osg::Vec2i positionToCellIndex(float x, float y, bool esm4Ext = false) + { + const float cellSize = esm4Ext ? Constants::ESM4CellSizeInUnits : Constants::CellSizeInUnits; + return { static_cast(std::floor(x / cellSize)), static_cast(std::floor(y / cellSize)) }; + } + } namespace std