CS: Make the terrain editing error preview match with the new correction

algorithm.
This commit is contained in:
Marius DAVID 2025-08-30 13:14:09 +02:00
parent 0f500df183
commit afa6d8c552
2 changed files with 11 additions and 24 deletions

View File

@ -107,14 +107,14 @@ namespace CSVRender
int TerrainStorage::getUpHeight(int col, int row, std::span<const float> heightData) const
{
return heightData[(col - 1) * ESM::Land::LAND_SIZE + row]
+ mAlteredHeight[static_cast<unsigned int>((col - 1) * ESM::Land::LAND_SIZE + row)];
return heightData[(col + 1) * ESM::Land::LAND_SIZE + row]
+ mAlteredHeight[static_cast<unsigned int>((col + 1) * ESM::Land::LAND_SIZE + row)];
}
int TerrainStorage::getDownHeight(int col, int row, std::span<const float> heightData) const
{
return heightData[(col + 1) * ESM::Land::LAND_SIZE + row]
+ mAlteredHeight[static_cast<unsigned int>((col + 1) * ESM::Land::LAND_SIZE + row)];
return heightData[(col - 1) * ESM::Land::LAND_SIZE + row]
+ mAlteredHeight[static_cast<unsigned int>((col - 1) * ESM::Land::LAND_SIZE + row)];
}
int TerrainStorage::getHeightDifferenceToLeft(int col, int row, std::span<const float> heightData) const
@ -137,29 +137,19 @@ namespace CSVRender
return abs(getThisHeight(col, row, heightData) - getDownHeight(col, row, heightData));
}
bool TerrainStorage::leftOrUpIsOverTheLimit(
int col, int row, int heightWarningLimit, std::span<const float> heightData) const
{
return getHeightDifferenceToLeft(col, row, heightData) >= heightWarningLimit
|| getHeightDifferenceToUp(col, row, heightData) >= heightWarningLimit;
}
bool TerrainStorage::rightOrDownIsOverTheLimit(
int col, int row, int heightWarningLimit, std::span<const float> heightData) const
{
return getHeightDifferenceToRight(col, row, heightData) >= heightWarningLimit
|| getHeightDifferenceToDown(col, row, heightData) >= heightWarningLimit;
}
void TerrainStorage::adjustColor(int col, int row, const ESM::LandData* heightData, osg::Vec4ub& color) const
{
if (!heightData)
return;
// Highlight broken height changes
int heightWarningLimit = 1024;
if (((col > 0 && row > 0) && leftOrUpIsOverTheLimit(col, row, heightWarningLimit, heightData->getHeights()))
|| ((col < ESM::Land::LAND_SIZE - 1 && row < ESM::Land::LAND_SIZE - 1)
&& rightOrDownIsOverTheLimit(col, row, heightWarningLimit, heightData->getHeights())))
if ((row > 0 && (getHeightDifferenceToRight(col, row, heightData->getHeights()) >= heightWarningLimit))
|| (row > 0 && row < ESM::Land::LAND_SIZE
&& (getHeightDifferenceToLeft(col, row, heightData->getHeights()) >= heightWarningLimit))
|| (row == 0 && col > 0
&& (getHeightDifferenceToDown(col, row, heightData->getHeights()) >= heightWarningLimit))
|| (row == 0 && col < ESM::Land::LAND_SIZE
&& (getHeightDifferenceToUp(col, row, heightData->getHeights()) >= heightWarningLimit)))
{
color.r() = 255;
color.g() = 0;

View File

@ -52,9 +52,6 @@ namespace CSVRender
int getHeightDifferenceToRight(int col, int row, std::span<const float> heightData) const;
int getHeightDifferenceToUp(int col, int row, std::span<const float> heightData) const;
int getHeightDifferenceToDown(int col, int row, std::span<const float> heightData) const;
bool leftOrUpIsOverTheLimit(int col, int row, int heightWarningLimit, std::span<const float> heightData) const;
bool rightOrDownIsOverTheLimit(
int col, int row, int heightWarningLimit, std::span<const float> heightData) const;
void adjustColor(int col, int row, const ESM::LandData* heightData, osg::Vec4ub& color) const override;
float getAlteredHeight(int col, int row) const override;