mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-29 21:45:33 +00:00
fixes errors and warnings
Applies review comments getWorldspaceTerrain => returns a reference because never null crashfix in navigator updateLandPositions fixes naming of it const ESM4::Land* MWWorld::Store<ESM4::Land>::search(ESM::ExteriorCellLocation cellLocation) const removes useless else ExteriorCellLocation uses default initializers get terrain height returns -MAX_FLOAT when there is no esm4 terrain. applied review comments use default initlializer when possible factorise code uses pattern matching in for loop.
This commit is contained in:
parent
f600730459
commit
22dc383f63
11 changed files with 47 additions and 59 deletions
|
@ -82,7 +82,7 @@ namespace CSVRender
|
|||
return &mAlteredHeight[inCellY * ESM::Land::LAND_SIZE + inCellX];
|
||||
}
|
||||
|
||||
void TerrainStorage::getBounds(float& minX, float& maxX, float& minY, float& maxY)
|
||||
void TerrainStorage::getBounds(float& minX, float& maxX, float& minY, float& maxY, ESM::RefId worldspace)
|
||||
{
|
||||
// not needed at the moment - this returns the bounds of the whole world, but we only edit individual cells
|
||||
throw std::runtime_error("getBounds not implemented");
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace CSVRender
|
|||
osg::ref_ptr<const ESMTerrain::LandObject> getLand(ESM::ExteriorCellLocation cellLocation) override;
|
||||
const ESM::LandTexture* getLandTexture(int index, short plugin) override;
|
||||
|
||||
void getBounds(float& minX, float& maxX, float& minY, float& maxY) override;
|
||||
void getBounds(float& minX, float& maxX, float& minY, float& maxY, ESM::RefId worldspace) override;
|
||||
|
||||
int getThisHeight(int col, int row, const ESM::Land::LandData* heightData) const;
|
||||
int getLeftHeight(int col, int row, const ESM::Land::LandData* heightData) const;
|
||||
|
|
|
@ -458,7 +458,7 @@ namespace MWRender
|
|||
mTerrainStorage = std::make_unique<TerrainStorage>(mResourceSystem, normalMapPattern, heightMapPattern,
|
||||
useTerrainNormalMaps, specularMapPattern, useTerrainSpecularMaps);
|
||||
|
||||
mTerrain = getWorldspaceTerrain(ESM::Cell::sDefaultWorldspaceId);
|
||||
mTerrain = &getWorldspaceTerrain(ESM::Cell::sDefaultWorldspaceId);
|
||||
bool groundcover = Settings::Manager::getBool("enabled", "Groundcover");
|
||||
|
||||
if (groundcover)
|
||||
|
@ -758,7 +758,7 @@ namespace MWRender
|
|||
if (store->getCell()->isExterior())
|
||||
{
|
||||
getWorldspaceTerrain(store->getCell()->getWorldSpace())
|
||||
->unloadCell(store->getCell()->getGridX(), store->getCell()->getGridY());
|
||||
.unloadCell(store->getCell()->getGridX(), store->getCell()->getGridY());
|
||||
}
|
||||
|
||||
mWater->removeCell(store);
|
||||
|
@ -770,7 +770,7 @@ namespace MWRender
|
|||
mWater->setCullCallback(nullptr);
|
||||
else
|
||||
{
|
||||
Terrain::World* newTerrain = getWorldspaceTerrain(worldspace);
|
||||
Terrain::World* newTerrain = &getWorldspaceTerrain(worldspace);
|
||||
if (newTerrain != mTerrain)
|
||||
{
|
||||
mTerrain->enable(false);
|
||||
|
@ -1328,11 +1328,11 @@ namespace MWRender
|
|||
mStateUpdater->setFogColor(color);
|
||||
}
|
||||
|
||||
Terrain::World* RenderingManager::getWorldspaceTerrain(ESM::RefId worldspace)
|
||||
Terrain::World& RenderingManager::getWorldspaceTerrain(ESM::RefId worldspace)
|
||||
{
|
||||
auto existingTerrain = mWorldspaceTerrains.find(worldspace);
|
||||
if (existingTerrain != mWorldspaceTerrains.end())
|
||||
return existingTerrain->second.get();
|
||||
return *existingTerrain->second.get();
|
||||
std::unique_ptr<Terrain::World> newTerrain;
|
||||
|
||||
const float lodFactor = Settings::Manager::getFloat("lod factor", "Terrain");
|
||||
|
@ -1366,8 +1366,9 @@ namespace MWRender
|
|||
float distanceMult = std::cos(osg::DegreesToRadians(std::min(mFieldOfView, 140.f)) / 2.f);
|
||||
newTerrain->setViewDistance(mViewDistance * (distanceMult ? 1.f / distanceMult : 1.f));
|
||||
|
||||
mWorldspaceTerrains[worldspace] = std::move(newTerrain);
|
||||
return mWorldspaceTerrains[worldspace].get();
|
||||
Terrain::World* result = newTerrain.get();
|
||||
mWorldspaceTerrains.emplace(worldspace, std::move(newTerrain));
|
||||
return *result;
|
||||
}
|
||||
|
||||
void RenderingManager::reportStats() const
|
||||
|
@ -1473,7 +1474,7 @@ namespace MWRender
|
|||
|
||||
float RenderingManager::getTerrainHeightAt(const osg::Vec3f& pos, ESM::RefId worldspace)
|
||||
{
|
||||
return getWorldspaceTerrain(worldspace)->getHeightAt(pos);
|
||||
return getWorldspaceTerrain(worldspace).getHeightAt(pos);
|
||||
}
|
||||
|
||||
void RenderingManager::overrideFieldOfView(float val)
|
||||
|
|
|
@ -282,7 +282,7 @@ namespace MWRender
|
|||
void updateAmbient();
|
||||
void setFogColor(const osg::Vec4f& color);
|
||||
void updateThirdPersonViewMode();
|
||||
Terrain::World* getWorldspaceTerrain(ESM::RefId worldspace);
|
||||
Terrain::World& getWorldspaceTerrain(ESM::RefId worldspace);
|
||||
|
||||
void reportStats() const;
|
||||
|
||||
|
|
|
@ -34,6 +34,18 @@ namespace MWRender
|
|||
return land != nullptr;
|
||||
}
|
||||
|
||||
static void BoundUnion(float& minX, float& maxX, float& minY, float& maxY, float x, float y)
|
||||
{
|
||||
if (x < minX)
|
||||
minX = x;
|
||||
if (x > maxX)
|
||||
maxX = x;
|
||||
if (y < minY)
|
||||
minY = y;
|
||||
if (y > maxY)
|
||||
maxY = y;
|
||||
}
|
||||
|
||||
void TerrainStorage::getBounds(float& minX, float& maxX, float& minY, float& maxY, ESM::RefId worldspace)
|
||||
{
|
||||
minX = 0;
|
||||
|
@ -46,20 +58,11 @@ namespace MWRender
|
|||
if (ESM::isEsm4Ext(worldspace))
|
||||
{
|
||||
const auto& lands = esmStore.get<ESM4::Land>().getLands();
|
||||
for (const auto& it : lands)
|
||||
for (const auto& [landPos, _] : lands)
|
||||
{
|
||||
if (it.first.mWorldspace == worldspace)
|
||||
if (landPos.mWorldspace == worldspace)
|
||||
{
|
||||
int x = it.first.mX;
|
||||
int y = it.first.mY;
|
||||
if (x < minX)
|
||||
minX = static_cast<float>(x);
|
||||
if (x > maxX)
|
||||
maxX = static_cast<float>(x);
|
||||
if (y < minY)
|
||||
minY = static_cast<float>(y);
|
||||
if (y > maxY)
|
||||
maxY = static_cast<float>(y);
|
||||
BoundUnion(minX, maxX, minY, maxY, static_cast<float>(landPos.mX), static_cast<float>(landPos.mY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,14 +71,7 @@ namespace MWRender
|
|||
MWWorld::Store<ESM::Land>::iterator it = esmStore.get<ESM::Land>().begin();
|
||||
for (; it != esmStore.get<ESM::Land>().end(); ++it)
|
||||
{
|
||||
if (it->mX < minX)
|
||||
minX = static_cast<float>(it->mX);
|
||||
if (it->mX > maxX)
|
||||
maxX = static_cast<float>(it->mX);
|
||||
if (it->mY < minY)
|
||||
minY = static_cast<float>(it->mY);
|
||||
if (it->mY > maxY)
|
||||
maxY = static_cast<float>(it->mY);
|
||||
BoundUnion(minX, maxX, minY, maxY, static_cast<float>(it->mX), static_cast<float>(it->mY));
|
||||
}
|
||||
}
|
||||
// since grid coords are at cell origin, we need to add 1 cell
|
||||
|
|
|
@ -433,7 +433,7 @@ namespace MWWorld
|
|||
return heights;
|
||||
}
|
||||
}();
|
||||
mNavigator.addHeightfield(cellPosition, data->getSize(), shape, navigatorUpdateGuard);
|
||||
mNavigator.addHeightfield(cellPosition, worldsize, shape, navigatorUpdateGuard);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1199,15 +1199,15 @@ namespace MWWorld
|
|||
|
||||
void Store<ESM4::Land>::updateLandPositions(const Store<ESM4::Cell>& cells)
|
||||
{
|
||||
for (auto& it : mStatic)
|
||||
for (const auto& [id, value] : mStatic)
|
||||
{
|
||||
const ESM4::Cell* cell = cells.find(it.second.mCell);
|
||||
mLands[cell->getExteriorCellLocation()] = &it.second;
|
||||
const ESM4::Cell* cell = cells.find(value.mCell);
|
||||
mLands[cell->getExteriorCellLocation()] = &value;
|
||||
}
|
||||
for (auto& it : mDynamic)
|
||||
for (const auto& [id, value] : mDynamic)
|
||||
{
|
||||
const ESM4::Cell* cell = cells.find(it.second.mCell);
|
||||
mLands[cell->getExteriorCellLocation()] = &it.second;
|
||||
const ESM4::Cell* cell = cells.find(value.mCell);
|
||||
mLands[cell->getExteriorCellLocation()] = &value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1216,8 +1216,7 @@ namespace MWWorld
|
|||
auto foundLand = mLands.find(cellLocation);
|
||||
if (foundLand == mLands.end())
|
||||
return nullptr;
|
||||
else
|
||||
return foundLand->second;
|
||||
return foundLand->second;
|
||||
}
|
||||
|
||||
// ESM4 Reference
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <components/esm3/loadland.hpp>
|
||||
#include <components/esm3/loadpgrd.hpp>
|
||||
#include <components/esm4/loadcell.hpp>
|
||||
#include <components/esm4/loadland.hpp>
|
||||
#include <components/esm4/loadrefr.hpp>
|
||||
#include <components/misc/rng.hpp>
|
||||
#include <components/misc/strings/algorithm.hpp>
|
||||
|
|
|
@ -51,14 +51,10 @@ namespace ESM
|
|||
|
||||
struct ExteriorCellLocation
|
||||
{
|
||||
int mX, mY;
|
||||
ESM::RefId mWorldspace;
|
||||
ExteriorCellLocation()
|
||||
: mX(0)
|
||||
, mY(0)
|
||||
, mWorldspace(ESM::Cell::sDefaultWorldspaceId)
|
||||
{
|
||||
}
|
||||
int mX = 0;
|
||||
int mY = 0;
|
||||
ESM::RefId mWorldspace = ESM::Cell::sDefaultWorldspaceId;
|
||||
ExteriorCellLocation() = default;
|
||||
|
||||
ExteriorCellLocation(int x, int y, ESM::RefId worldspace)
|
||||
: mX(x)
|
||||
|
|
|
@ -337,7 +337,7 @@ namespace ESMTerrain
|
|||
|
||||
if (!validHeightDataExists && ESM::isEsm4Ext(worldspace))
|
||||
{
|
||||
for (int iVert = 0; iVert < numVerts * numVerts; iVert++)
|
||||
for (unsigned int iVert = 0; iVert < numVerts * numVerts; iVert++)
|
||||
{
|
||||
(*positions)[static_cast<unsigned int>(iVert)] = osg::Vec3f(0.f, 0.f, 0.f);
|
||||
}
|
||||
|
@ -485,7 +485,7 @@ namespace ESMTerrain
|
|||
|
||||
osg::ref_ptr<const LandObject> land = getLand(ESM::ExteriorCellLocation(cellX, cellY, worldspace));
|
||||
if (!land)
|
||||
return defaultHeight;
|
||||
return ESM::isEsm4Ext(worldspace) ? std::numeric_limits<float>::lowest() : defaultHeight;
|
||||
|
||||
const ESM::LandData* data = land->getData(ESM::Land::DATA_VHGT);
|
||||
if (!data)
|
||||
|
|
|
@ -60,12 +60,7 @@ namespace Terrain
|
|||
{
|
||||
public:
|
||||
virtual ~ChunkManager() {}
|
||||
ChunkManager()
|
||||
: mWorldspace(ESM::RefId())
|
||||
, mViewDistance(0.f)
|
||||
, mMaxLodLevel(~0u)
|
||||
{
|
||||
}
|
||||
ChunkManager() = default;
|
||||
ChunkManager(ESM::RefId worldspace)
|
||||
: ChunkManager()
|
||||
{
|
||||
|
@ -84,11 +79,11 @@ namespace Terrain
|
|||
void setMaxLodLevel(unsigned int level) { mMaxLodLevel = level; }
|
||||
|
||||
protected:
|
||||
ESM::RefId mWorldspace;
|
||||
ESM::RefId mWorldspace = ESM::RefId();
|
||||
|
||||
private:
|
||||
float mViewDistance;
|
||||
unsigned int mMaxLodLevel;
|
||||
float mViewDistance = 0.f;
|
||||
unsigned int mMaxLodLevel = ~0u;
|
||||
};
|
||||
void addChunkManager(ChunkManager*);
|
||||
|
||||
|
|
Loading…
Reference in a new issue