From a027cd898b1118ced2eb3175c886585af65d7ef4 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 12 Aug 2023 00:55:06 +0200 Subject: [PATCH] Use only cell position to detect cell change --- components/esmterrain/storage.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index fe7f450b1f..d2f34f95b9 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -223,20 +223,29 @@ namespace ESMTerrain const osg::Vec2f origin = center - osg::Vec2f(size, size) * 0.5f; const int startCellX = static_cast(std::floor(origin.x())); const int startCellY = static_cast(std::floor(origin.y())); - ESM::ExteriorCellLocation lastCellLocation(startCellX - 1, startCellY - 1, worldspace); - const LandObject* land = nullptr; + std::pair lastCell{ startCellX, startCellY }; + const LandObject* land = getLand(ESM::ExteriorCellLocation(startCellX, startCellY, worldspace), cache); const ESM::LandData* heightData = nullptr; const ESM::LandData* normalData = nullptr; const ESM::LandData* colourData = nullptr; bool validHeightDataExists = false; + if (land != nullptr) + { + heightData = land->getData(ESM::Land::DATA_VHGT); + normalData = land->getData(ESM::Land::DATA_VNML); + colourData = land->getData(ESM::Land::DATA_VCLR); + validHeightDataExists = true; + } + const auto handleSample = [&](std::size_t cellShiftX, std::size_t cellShiftY, std::size_t row, std::size_t col, std::size_t vertX, std::size_t vertY) { const int cellX = startCellX + cellShiftX; const int cellY = startCellY + cellShiftY; + const std::pair cell{ cellX, cellY }; const ESM::ExteriorCellLocation cellLocation(cellX, cellY, worldspace); - if (lastCellLocation != cellLocation) + if (lastCell != cell) { land = getLand(cellLocation, cache); @@ -252,7 +261,7 @@ namespace ESMTerrain validHeightDataExists = true; } - lastCellLocation = cellLocation; + lastCell = cell; } float height = defaultHeight;