landbindings - static to anonymous namespace + use references

This commit is contained in:
Sebastian Fieber 2025-01-08 21:05:08 +01:00
parent ea02c69186
commit 940e73a356
2 changed files with 32 additions and 32 deletions

View File

@ -11,7 +11,9 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
static const ESM::RefId worldspaceAt(const osg::Vec3f& pos, sol::object cellOrName) namespace
{
const ESM::RefId worldspaceAt(const osg::Vec3f& pos, sol::object cellOrName)
{ {
ESM::RefId worldspace; ESM::RefId worldspace;
if (cellOrName.is<MWLua::GCell>()) if (cellOrName.is<MWLua::GCell>())
@ -28,24 +30,25 @@ static const ESM::RefId worldspaceAt(const osg::Vec3f& pos, sol::object cellOrNa
return worldspace; return worldspace;
} }
static bool fillLandData(const MWWorld::Store<ESM::Land>* landStore, const osg::Vec3f& pos, const float cellSize, bool fillLandData(const MWWorld::Store<ESM::Land>& landStore, const osg::Vec3f& pos, const float cellSize,
const ESM::Land** land, const ESM::Land::LandData** landData) const ESM::Land::LandData*& landData)
{ {
int cellX = static_cast<int>(std::floor(pos.x() / cellSize)); int cellX = static_cast<int>(std::floor(pos.x() / cellSize));
int cellY = static_cast<int>(std::floor(pos.y() / cellSize)); int cellY = static_cast<int>(std::floor(pos.y() / cellSize));
*land = landStore->search(cellX, cellY); const ESM::Land* land = landStore.search(cellX, cellY);
if (*land != nullptr) if (land != nullptr)
*landData = (*land)->getLandData(ESM::Land::DATA_VTEX); 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 // 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 // the position used to sample terrain
if (*landData == nullptr) if (landData == nullptr)
return false; return false;
return true; return true;
} }
}
namespace MWLua namespace MWLua
{ {
@ -72,10 +75,9 @@ namespace MWLua
// as it differs between tes3 and tes4. It's equal - // 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 // Once we know the value, we will calculate the offset and retrieve a sample again, this time
// with the offset taken into account. // with the offset taken into account.
const ESM::Land* land = nullptr;
const ESM::Land::LandData* landData = nullptr; const ESM::Land::LandData* landData = nullptr;
if (!fillLandData(&landStore, pos, cellSize, &land, &landData)) if (!fillLandData(landStore, pos, cellSize, landData))
return values; return values;
// Use landData to get amount of sampler per cell edge (sLandTextureSize) // 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* correctedLand = nullptr;
const ESM::Land::LandData* correctedLandData = nullptr; const ESM::Land::LandData* correctedLandData = nullptr;
if (!fillLandData(&landStore, correctedPos, cellSize, &correctedLand, &correctedLandData)) if (!fillLandData(landStore, correctedPos, cellSize, correctedLandData))
return values; return values;
// We're passing in sLandTextureSize, NOT sLandSize like with getHeightAt // We're passing in sLandTextureSize, NOT sLandSize like with getHeightAt

View File

@ -505,8 +505,6 @@ namespace ESMTerrain
float Storage::getHeightAt( float Storage::getHeightAt(
const std::span<const float> data, const int landSize, const osg::Vec3f& worldPos, const float cellSize) const std::span<const float> data, const int landSize, const osg::Vec3f& worldPos, const float cellSize)
{ {
// if (!data)
// return defaultHeight;
int cellX = static_cast<int>(std::floor(worldPos.x() / cellSize)); int cellX = static_cast<int>(std::floor(worldPos.x() / cellSize));
int cellY = static_cast<int>(std::floor(worldPos.y() / cellSize)); int cellY = static_cast<int>(std::floor(worldPos.y() / cellSize));