diff --git a/apps/openmw/mwlua/landbindings.cpp b/apps/openmw/mwlua/landbindings.cpp index 5176c7909c..aef7ab47c6 100644 --- a/apps/openmw/mwlua/landbindings.cpp +++ b/apps/openmw/mwlua/landbindings.cpp @@ -11,40 +11,43 @@ #include "../mwbase/world.hpp" #include "../mwworld/esmstore.hpp" -static const ESM::RefId worldspaceAt(const osg::Vec3f& pos, sol::object cellOrName) +namespace { - ESM::RefId worldspace; - if (cellOrName.is()) - worldspace = cellOrName.as().mStore->getCell()->getWorldSpace(); - else if (cellOrName.is() && !cellOrName.as().empty()) - worldspace = MWBase::Environment::get() - .getWorldModel() - ->getCell(cellOrName.as()) - .getCell() - ->getWorldSpace(); - else - worldspace = ESM::Cell::sDefaultWorldspaceId; + const ESM::RefId worldspaceAt(const osg::Vec3f& pos, sol::object cellOrName) + { + ESM::RefId worldspace; + if (cellOrName.is()) + worldspace = cellOrName.as().mStore->getCell()->getWorldSpace(); + else if (cellOrName.is() && !cellOrName.as().empty()) + worldspace = MWBase::Environment::get() + .getWorldModel() + ->getCell(cellOrName.as()) + .getCell() + ->getWorldSpace(); + else + worldspace = ESM::Cell::sDefaultWorldspaceId; - return worldspace; -} + return worldspace; + } -static bool fillLandData(const MWWorld::Store* landStore, const osg::Vec3f& pos, const float cellSize, - const ESM::Land** land, const ESM::Land::LandData** landData) -{ - int cellX = static_cast(std::floor(pos.x() / cellSize)); - int cellY = static_cast(std::floor(pos.y() / cellSize)); + bool fillLandData(const MWWorld::Store& landStore, const osg::Vec3f& pos, const float cellSize, + const ESM::Land::LandData*& landData) + { + int cellX = static_cast(std::floor(pos.x() / cellSize)); + int cellY = static_cast(std::floor(pos.y() / cellSize)); - *land = landStore->search(cellX, cellY); + const ESM::Land* land = landStore.search(cellX, cellY); - if (*land != nullptr) - *landData = (*land)->getLandData(ESM::Land::DATA_VTEX); + if (land != nullptr) + landData = land->getLandData(ESM::Land::DATA_VTEX); - // If we fail to preload land data, return, we need to be able to get *any* land to know how to correct - // the position used to sample terrain - if (*landData == nullptr) - return false; + // If we fail to preload land data, return, we need to be able to get *any* land to know how to correct + // the position used to sample terrain + if (landData == nullptr) + return false; - return true; + return true; + } } namespace MWLua @@ -72,10 +75,9 @@ namespace MWLua // as it differs between tes3 and tes4. It's equal - // Once we know the value, we will calculate the offset and retrieve a sample again, this time // with the offset taken into account. - const ESM::Land* land = nullptr; const ESM::Land::LandData* landData = nullptr; - if (!fillLandData(&landStore, pos, cellSize, &land, &landData)) + if (!fillLandData(landStore, pos, cellSize, landData)) return values; // Use landData to get amount of sampler per cell edge (sLandTextureSize) @@ -86,7 +88,7 @@ namespace MWLua const ESM::Land* correctedLand = nullptr; const ESM::Land::LandData* correctedLandData = nullptr; - if (!fillLandData(&landStore, correctedPos, cellSize, &correctedLand, &correctedLandData)) + if (!fillLandData(landStore, correctedPos, cellSize, correctedLandData)) return values; // We're passing in sLandTextureSize, NOT sLandSize like with getHeightAt diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index 360e2b6822..c4adda54a1 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -505,8 +505,6 @@ namespace ESMTerrain float Storage::getHeightAt( const std::span data, const int landSize, const osg::Vec3f& worldPos, const float cellSize) { - // if (!data) - // return defaultHeight; int cellX = static_cast(std::floor(worldPos.x() / cellSize)); int cellY = static_cast(std::floor(worldPos.y() / cellSize));