mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-10 12:59:58 -04:00
landbindings - static to anonymous namespace + use references
This commit is contained in:
parent
ea02c69186
commit
940e73a356
@ -11,40 +11,43 @@
|
|||||||
#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
|
||||||
{
|
{
|
||||||
ESM::RefId worldspace;
|
const ESM::RefId worldspaceAt(const osg::Vec3f& pos, sol::object cellOrName)
|
||||||
if (cellOrName.is<MWLua::GCell>())
|
{
|
||||||
worldspace = cellOrName.as<MWLua::GCell>().mStore->getCell()->getWorldSpace();
|
ESM::RefId worldspace;
|
||||||
else if (cellOrName.is<std::string_view>() && !cellOrName.as<std::string_view>().empty())
|
if (cellOrName.is<MWLua::GCell>())
|
||||||
worldspace = MWBase::Environment::get()
|
worldspace = cellOrName.as<MWLua::GCell>().mStore->getCell()->getWorldSpace();
|
||||||
.getWorldModel()
|
else if (cellOrName.is<std::string_view>() && !cellOrName.as<std::string_view>().empty())
|
||||||
->getCell(cellOrName.as<std::string_view>())
|
worldspace = MWBase::Environment::get()
|
||||||
.getCell()
|
.getWorldModel()
|
||||||
->getWorldSpace();
|
->getCell(cellOrName.as<std::string_view>())
|
||||||
else
|
.getCell()
|
||||||
worldspace = ESM::Cell::sDefaultWorldspaceId;
|
->getWorldSpace();
|
||||||
|
else
|
||||||
|
worldspace = ESM::Cell::sDefaultWorldspaceId;
|
||||||
|
|
||||||
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
|
||||||
|
@ -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));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user