From feb60f5ad825c447979d261aeb67d5202390ddf0 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Thu, 18 May 2023 12:26:25 +0200 Subject: [PATCH] One landsize variable instead of two. fixes issues in constant values. --- components/esm3terrain/storage.cpp | 28 ++++++++++++++-------------- components/terrain/quadtreeworld.cpp | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/components/esm3terrain/storage.cpp b/components/esm3terrain/storage.cpp index 577983dd57..76fc622f9c 100644 --- a/components/esm3terrain/storage.cpp +++ b/components/esm3terrain/storage.cpp @@ -201,9 +201,10 @@ namespace ESMTerrain int startCellX = static_cast(std::floor(origin.x())); int startCellY = static_cast(std::floor(origin.y())); - const int LandSize = ESM::getLandSize(worldspace); + const int landSize = ESM::getLandSize(worldspace); + const int LandSizeInUnits = ESM::getCellSize(worldspace); - size_t numVerts = static_cast(size * (LandSize - 1) / increment + 1); + size_t numVerts = static_cast(size * (landSize - 1) / increment + 1); positions->resize(numVerts * numVerts); normals->resize(numVerts * numVerts); @@ -230,7 +231,6 @@ namespace ESMTerrain const ESM::LandData* heightData = nullptr; const ESM::LandData* normalData = nullptr; const ESM::LandData* colourData = nullptr; - const int LandSizeInUnits = land ? land->getRealSize() : Constants::CellSizeInUnits; if (land) { heightData = land->getData(ESM::Land::DATA_VHGT); @@ -249,12 +249,12 @@ namespace ESMTerrain rowStart += increment; // Only relevant for chunks smaller than (contained in) one cell - rowStart += (origin.x() - startCellX) * LandSize; - colStart += (origin.y() - startCellY) * LandSize; + rowStart += (origin.x() - startCellX) * landSize; + colStart += (origin.y() - startCellY) * landSize; int rowEnd = std::min( - static_cast(rowStart + std::min(1.f, size) * (LandSize - 1) + 1), static_cast(LandSize)); + static_cast(rowStart + std::min(1.f, size) * (landSize - 1) + 1), static_cast(landSize)); int colEnd = std::min( - static_cast(colStart + std::min(1.f, size) * (LandSize - 1) + 1), static_cast(LandSize)); + static_cast(colStart + std::min(1.f, size) * (landSize - 1) + 1), static_cast(landSize)); vertY = vertY_; for (int col = colStart; col < colEnd; col += increment) @@ -262,17 +262,17 @@ namespace ESMTerrain vertX = vertX_; for (int row = rowStart; row < rowEnd; row += increment) { - int srcArrayIndex = col * LandSize * 3 + row * 3; + int srcArrayIndex = col * landSize * 3 + row * 3; - assert(row >= 0 && row < LandSize); - assert(col >= 0 && col < LandSize); + assert(row >= 0 && row < landSize); + assert(col >= 0 && col < landSize); assert(vertX < numVerts); assert(vertY < numVerts); float height = defaultHeight; if (heightData) - height = heightData->getHeights()[col * LandSize + row]; + height = heightData->getHeights()[col * landSize + row]; if (alteration) height += getAlteredHeight(col, row); (*positions)[static_cast(vertX * numVerts + vertY)] @@ -290,11 +290,11 @@ namespace ESMTerrain normal = osg::Vec3f(0, 0, 1); // Normals apparently don't connect seamlessly between cells - if (col == LandSize - 1 || row == LandSize - 1) + if (col == landSize - 1 || row == landSize - 1) fixNormal(normal, cellLocation, col, row, cache); // some corner normals appear to be complete garbage (z < 0) - if ((row == 0 || row == LandSize - 1) && (col == 0 || col == LandSize - 1)) + if ((row == 0 || row == landSize - 1) && (col == 0 || col == landSize - 1)) averageNormal(normal, cellLocation, col, row, cache); assert(normal.z() > 0); @@ -316,7 +316,7 @@ namespace ESMTerrain adjustColor(col, row, heightData, color); // Does nothing by default, override in OpenMW-CS // Unlike normals, colors mostly connect seamlessly between cells, but not always... - if (col == LandSize - 1 || row == LandSize - 1) + if (col == landSize - 1 || row == landSize - 1) fixColour(color, cellLocation, col, row, cache); color.a() = 255; diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 562eb89a00..7e4befcba4 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -475,7 +475,7 @@ namespace Terrain mRootNode->traverseNodes(vd, viewPoint, &lodCallback); } - const float cellWorldSize = ESM::getLandSize(mWorldspace); + const float cellWorldSize = ESM::getCellSize(mWorldspace); for (unsigned int i = 0; i < vd->getNumEntries(); ++i) {