From 216ca71149bdc689696ae6d85b7ad7c92c41826d Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Sat, 28 Jan 2023 12:07:47 +0100 Subject: [PATCH] Applied review comments getEditorName => getNameId restored cosntructor in CoordinateConverter --- apps/openmw/mwgui/mapwindow.cpp | 2 +- apps/openmw/mwgui/windowmanagerimp.cpp | 6 +++--- apps/openmw/mwlua/cellbindings.cpp | 4 ++-- apps/openmw/mwlua/localscripts.cpp | 2 +- apps/openmw/mwmechanics/aifollow.cpp | 2 +- apps/openmw/mwmechanics/aipackage.cpp | 2 +- apps/openmw/mwmechanics/aiwander.cpp | 2 +- apps/openmw/mwmechanics/spelleffects.cpp | 2 +- apps/openmw/mwworld/cell.hpp | 5 ++++- apps/openmw/mwworld/scene.cpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 14 +++++++------- components/detournavigator/navigatorimpl.cpp | 2 +- components/esm/esmbridge.hpp | 2 -- components/esm3/loadcell.hpp | 2 ++ components/misc/coordinateconverter.hpp | 5 +++++ 15 files changed, 31 insertions(+), 23 deletions(-) diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index c64489bae5..d94ada37e9 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -705,7 +705,7 @@ namespace MWGui ESM::Position markedPosition; MWBase::Environment::get().getWorld()->getPlayer().getMarkedPosition(markedCell, markedPosition); if (markedCell && markedCell->isExterior() == !mInterior - && (!mInterior || Misc::StringUtils::ciEqual(markedCell->getCell()->getEditorName(), mPrefix))) + && (!mInterior || Misc::StringUtils::ciEqual(markedCell->getCell()->getNameId(), mPrefix))) { MarkerUserData markerPos(mLocalMapRender); MyGUI::ImageBox* markerWidget = mLocalMap->createWidget("ImageBox", diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index e22d1302b1..6bd1ea7757 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -958,7 +958,7 @@ namespace MWGui if (cellCommon->isExterior()) { - if (!cellCommon->getEditorName().empty()) + if (!cellCommon->getNameId().empty()) mMap->addVisitedLocation(name, cellCommon->getGridX(), cellCommon->getGridY()); mMap->cellExplored(cellCommon->getGridX(), cellCommon->getGridY()); @@ -967,8 +967,8 @@ namespace MWGui } else { - mMap->setCellPrefix(std::string(cellCommon->getEditorName())); - mHud->setCellPrefix(std::string(cellCommon->getEditorName())); + mMap->setCellPrefix(std::string(cellCommon->getNameId())); + mHud->setCellPrefix(std::string(cellCommon->getNameId())); osg::Vec3f worldPos; if (!MWBase::Environment::get().getWorld()->findInteriorPositionInWorldSpace(cell, worldPos)) diff --git a/apps/openmw/mwlua/cellbindings.cpp b/apps/openmw/mwlua/cellbindings.cpp index c43f8dd21a..dc50a79eef 100644 --- a/apps/openmw/mwlua/cellbindings.cpp +++ b/apps/openmw/mwlua/cellbindings.cpp @@ -35,11 +35,11 @@ namespace MWLua if (cell->isExterior()) res << "exterior(" << cell->getGridX() << ", " << cell->getGridY() << ")"; else - res << "interior(" << cell->getEditorName() << ")"; + res << "interior(" << cell->getNameId() << ")"; return res.str(); }; - cellT["name"] = sol::readonly_property([](const CellT& c) { return c.mStore->getCell()->getEditorName(); }); + cellT["name"] = sol::readonly_property([](const CellT& c) { return c.mStore->getCell()->getNameId(); }); cellT["region"] = sol::readonly_property([](const CellT& c) { return c.mStore->getCell()->getRegion().getRefIdString(); }); cellT["gridX"] = sol::readonly_property([](const CellT& c) { return c.mStore->getCell()->getGridX(); }); diff --git a/apps/openmw/mwlua/localscripts.cpp b/apps/openmw/mwlua/localscripts.cpp index 88c824cc59..883afb5328 100644 --- a/apps/openmw/mwlua/localscripts.cpp +++ b/apps/openmw/mwlua/localscripts.cpp @@ -181,7 +181,7 @@ namespace MWLua ai.stack(MWMechanics::AiEscort(refId, gameHoursDuration, dest.x(), dest.y(), dest.z(), false), ptr); else ai.stack(MWMechanics::AiEscort( - refId, esmCell->getEditorName(), gameHoursDuration, dest.x(), dest.y(), dest.z(), false), + refId, esmCell->getNameId(), gameHoursDuration, dest.x(), dest.y(), dest.z(), false), ptr); }; selfAPI["_startAiWander"] = [](SelfObject& self, int distance, float duration) { diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index 6185535a67..55a5e2534c 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -175,7 +175,7 @@ namespace MWMechanics } } else if (Misc::StringUtils::ciEqual( - mCellId, actor.getCell()->getCell()->getEditorName())) // Cell to travel to + mCellId, actor.getCell()->getCell()->getNameId())) // Cell to travel to { mRemainingDuration = mDuration; return true; diff --git a/apps/openmw/mwmechanics/aipackage.cpp b/apps/openmw/mwmechanics/aipackage.cpp index c966f704e9..8e7b38fa2f 100644 --- a/apps/openmw/mwmechanics/aipackage.cpp +++ b/apps/openmw/mwmechanics/aipackage.cpp @@ -418,7 +418,7 @@ bool MWMechanics::AiPackage::isNearInactiveCell(osg::Vec3f position) if (playerCell->isExterior()) { // get actor's distance from origin of center cell - Misc::CoordinateConverter(ESM::CellVariant(*playerCell)).toLocal(position); + Misc::CoordinateConverter(playerCell).toLocal(position); // currently assumes 3 x 3 grid for exterior cells, with player at center cell. // AI shuts down actors before they reach edges of 3 x 3 grid. diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index a421f7e8cd..f7a7141ecd 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -839,7 +839,7 @@ namespace MWMechanics if (mDistance && storage.mCanWanderAlongPathGrid && !actor.getClass().isPureWaterCreature(actor)) { // get NPC's position in local (i.e. cell) coordinates - auto converter = Misc::CoordinateConverter(ESM::CellVariant(*cell)); + auto converter = Misc::CoordinateConverter(cell); const osg::Vec3f npcPos = converter.toLocalVec3(mInitialActorPosition); // Find closest pathgrid point diff --git a/apps/openmw/mwmechanics/spelleffects.cpp b/apps/openmw/mwmechanics/spelleffects.cpp index 66b572f1d3..31b82b4a14 100644 --- a/apps/openmw/mwmechanics/spelleffects.cpp +++ b/apps/openmw/mwmechanics/spelleffects.cpp @@ -489,7 +489,7 @@ namespace MWMechanics { std::string_view dest; if (!markedCell->isExterior()) - dest = markedCell->getCell()->getEditorName(); + dest = markedCell->getCell()->getNameId(); MWWorld::ActionTeleport action(dest, markedPosition, false); action.execute(target); if (!caster.isEmpty()) diff --git a/apps/openmw/mwworld/cell.hpp b/apps/openmw/mwworld/cell.hpp index 7507b76993..3a0d063e02 100644 --- a/apps/openmw/mwworld/cell.hpp +++ b/apps/openmw/mwworld/cell.hpp @@ -1,6 +1,8 @@ #ifndef OPENW_MWORLD_CELL #define OPENW_MWORLD_CELL +#include + #include #include #include @@ -43,7 +45,8 @@ namespace MWWorld bool noSleep() const { return mFlags.noSleep; } const ESM::CellId& getCellId() const { return mCellId; } const ESM::RefId& getRegion() const { return mRegion; } - std::string_view getEditorName() const { return mNameID; } + std::string_view getNameId() const { return mNameID; } + std::string_view getDisplayName() const { return mDisplayname; } std::string getDescription() const; const MoodData& getMood() const { return mMood; } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 0075289808..d77e729c35 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -747,7 +747,7 @@ namespace MWWorld { assert(!(*iter)->getCell()->isExterior()); - if (it->mName == (*iter)->getCell()->getEditorName()) + if (it->mName == (*iter)->getCell()->getNameId()) { unloadCell(*iter, navigatorUpdateGuard.get()); break; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index c7ec164348..39d324a80d 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -639,8 +639,8 @@ namespace MWWorld std::string_view World::getCellName(const MWWorld::Cell& cell) const { - if (!cell.isExterior() || !cell.getEditorName().empty()) - return cell.getEditorName(); + if (!cell.isExterior() || !cell.getNameId().empty()) + return cell.getNameId(); if (!cell.isEsm4()) { @@ -1139,7 +1139,7 @@ namespace MWWorld { if (!newCell->isExterior()) { - changeToInteriorCell(newCell->getCell()->getEditorName(), pos, false); + changeToInteriorCell(newCell->getCell()->getNameId(), pos, false); removeContainerScripts(getPlayerPtr()); } else @@ -1400,7 +1400,7 @@ namespace MWWorld esmPos.pos[2] = traced.z(); std::string_view cell; if (!actor.getCell()->isExterior()) - cell = actor.getCell()->getCell()->getEditorName(); + cell = actor.getCell()->getCell()->getNameId(); MWWorld::ActionTeleport(cell, esmPos, false).execute(actor); } } @@ -3270,7 +3270,7 @@ namespace MWWorld std::set checkedCells; std::set currentCells; std::set nextCells; - nextCells.insert(cell->getCell()->getEditorName()); + nextCells.insert(cell->getCell()->getNameId()); while (!nextCells.empty()) { @@ -3325,7 +3325,7 @@ namespace MWWorld std::set nextCells; MWWorld::ConstPtr closestMarker; - nextCells.insert(ptr.getCell()->getCell()->getEditorName()); + nextCells.insert(ptr.getCell()->getCell()->getNameId()); while (!nextCells.empty()) { currentCells = nextCells; @@ -3420,7 +3420,7 @@ namespace MWWorld std::string_view cellName = ""; if (!closestMarker.mCell->isExterior()) - cellName = closestMarker.mCell->getCell()->getEditorName(); + cellName = closestMarker.mCell->getCell()->getNameId(); MWWorld::ActionTeleport action(cellName, closestMarker.getRefData().getPosition(), false); action.execute(ptr); diff --git a/components/detournavigator/navigatorimpl.cpp b/components/detournavigator/navigatorimpl.cpp index f064842f6b..0978f69c24 100644 --- a/components/detournavigator/navigatorimpl.cpp +++ b/components/detournavigator/navigatorimpl.cpp @@ -134,7 +134,7 @@ namespace DetourNavigator void NavigatorImpl::addPathgrid(const ESM::Cell& cell, const ESM::Pathgrid& pathgrid) { - Misc::CoordinateConverter converter = Misc::CoordinateConverter(ESM::CellVariant(cell)); + Misc::CoordinateConverter converter(&cell); for (const auto& edge : pathgrid.mEdges) { const auto src = Misc::Convert::makeOsgVec3f(converter.toWorldPoint(pathgrid.mPoints[edge.mV0])); diff --git a/components/esm/esmbridge.hpp b/components/esm/esmbridge.hpp index 753f0690e0..e50b73e61b 100644 --- a/components/esm/esmbridge.hpp +++ b/components/esm/esmbridge.hpp @@ -43,10 +43,8 @@ namespace ESM struct ReferenceVariant { - protected: std::variant mVariant; - public: explicit ReferenceVariant(const ESM4::Reference& ref) : mVariant(ref) { diff --git a/components/esm3/loadcell.hpp b/components/esm3/loadcell.hpp index 8bd707d825..3cf1834dfa 100644 --- a/components/esm3/loadcell.hpp +++ b/components/esm3/loadcell.hpp @@ -156,6 +156,8 @@ namespace ESM int getGridY() const { return mData.mY; } + bool hasWater() const { return ((mData.mFlags & HasWater) != 0) || isExterior(); } + bool hasAmbient() const { return mHasAmbi; } void setHasAmbient(bool hasAmbi) { mHasAmbi = hasAmbi; } diff --git a/components/misc/coordinateconverter.hpp b/components/misc/coordinateconverter.hpp index 7865ed9c5f..9c829e91cd 100644 --- a/components/misc/coordinateconverter.hpp +++ b/components/misc/coordinateconverter.hpp @@ -26,6 +26,11 @@ namespace Misc { } + explicit CoordinateConverter(const ESM::Cell* cell) + : CoordinateConverter(cell->isExterior(), cell->getGridX(), cell->getGridY()) + { + } + /// in-place conversion from local to world void toWorld(ESM::Pathgrid::Point& point) const {