mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-22 19:09:42 +00:00
Reduce code duplification, add bool value to limiting
This commit is contained in:
parent
60c0a25004
commit
ff18595a86
2 changed files with 53 additions and 59 deletions
|
@ -877,7 +877,37 @@ void CSVRender::TerrainShapeMode::fixEdges(const CSMWorld::CellCoordinates& cell
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVRender::TerrainShapeMode::limitAlteredHeights(const CSMWorld::CellCoordinates& cellCoords, bool reverseMode)
|
void CSVRender::TerrainShapeMode::compareAndLimit(const CSMWorld::CellCoordinates& cellCoords, int inCellX, int inCellY, float* limitedAlteredHeightXAxis, float* limitedAlteredHeightYAxis, bool* steepnessIsWithinLimits)
|
||||||
|
{
|
||||||
|
if (limitedAlteredHeightXAxis)
|
||||||
|
{
|
||||||
|
if (limitedAlteredHeightYAxis)
|
||||||
|
{
|
||||||
|
if(std::abs(*limitedAlteredHeightXAxis) >= std::abs(*limitedAlteredHeightYAxis))
|
||||||
|
{
|
||||||
|
alterHeight(cellCoords, inCellX, inCellY, *limitedAlteredHeightXAxis, false);
|
||||||
|
*steepnessIsWithinLimits = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
alterHeight(cellCoords, inCellX, inCellY, *limitedAlteredHeightYAxis, false);
|
||||||
|
*steepnessIsWithinLimits = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
alterHeight(cellCoords, inCellX, inCellY, *limitedAlteredHeightXAxis, false);
|
||||||
|
*steepnessIsWithinLimits = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (limitedAlteredHeightYAxis)
|
||||||
|
{
|
||||||
|
alterHeight(cellCoords, inCellX, inCellY, *limitedAlteredHeightYAxis, false);
|
||||||
|
*steepnessIsWithinLimits = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CSVRender::TerrainShapeMode::limitAlteredHeights(const CSMWorld::CellCoordinates& cellCoords, bool reverseMode)
|
||||||
{
|
{
|
||||||
CSMDoc::Document& document = getWorldspaceWidget().getDocument();
|
CSMDoc::Document& document = getWorldspaceWidget().getDocument();
|
||||||
CSMWorld::IdTable& landTable = dynamic_cast<CSMWorld::IdTable&> (
|
CSMWorld::IdTable& landTable = dynamic_cast<CSMWorld::IdTable&> (
|
||||||
|
@ -889,18 +919,13 @@ void CSVRender::TerrainShapeMode::limitAlteredHeights(const CSMWorld::CellCoordi
|
||||||
int limitHeightChange = 1016.0f; // Limited by save format
|
int limitHeightChange = 1016.0f; // Limited by save format
|
||||||
bool noCell = document.getData().getCells().searchId (cellId) == -1;
|
bool noCell = document.getData().getCells().searchId (cellId) == -1;
|
||||||
bool noLand = document.getData().getLand().searchId (cellId) == -1;
|
bool noLand = document.getData().getLand().searchId (cellId) == -1;
|
||||||
|
bool steepnessIsWithinLimits = true;
|
||||||
|
|
||||||
if (!noCell && !noLand)
|
if (!noCell && !noLand)
|
||||||
{
|
{
|
||||||
const CSMWorld::LandHeightsColumn::DataType landShapePointer =
|
const CSMWorld::LandHeightsColumn::DataType landShapePointer =
|
||||||
landTable.data(landTable.getModelIndex(cellId, landshapeColumn)).value<CSMWorld::LandHeightsColumn::DataType>();
|
landTable.data(landTable.getModelIndex(cellId, landshapeColumn)).value<CSMWorld::LandHeightsColumn::DataType>();
|
||||||
|
|
||||||
if (reverseMode == false)
|
|
||||||
{
|
|
||||||
for(int inCellY = 0; inCellY < landSize; ++inCellY)
|
|
||||||
{
|
|
||||||
for(int inCellX = 0; inCellX < landSize; ++inCellX)
|
|
||||||
{
|
|
||||||
float thisHeight = 0.0f;
|
float thisHeight = 0.0f;
|
||||||
float thisAlteredHeight = 0.0f;
|
float thisAlteredHeight = 0.0f;
|
||||||
float leftHeight = 0.0f;
|
float leftHeight = 0.0f;
|
||||||
|
@ -911,9 +936,15 @@ void CSVRender::TerrainShapeMode::limitAlteredHeights(const CSMWorld::CellCoordi
|
||||||
float rightAlteredHeight = 0.0f;
|
float rightAlteredHeight = 0.0f;
|
||||||
float downHeight = 0.0f;
|
float downHeight = 0.0f;
|
||||||
float downAlteredHeight = 0.0f;
|
float downAlteredHeight = 0.0f;
|
||||||
|
|
||||||
|
if (reverseMode == false)
|
||||||
|
{
|
||||||
|
for(int inCellY = 0; inCellY < landSize; ++inCellY)
|
||||||
|
{
|
||||||
|
for(int inCellX = 0; inCellX < landSize; ++inCellX)
|
||||||
|
{
|
||||||
float* limitedAlteredHeightXAxis = nullptr;
|
float* limitedAlteredHeightXAxis = nullptr;
|
||||||
float* limitedAlteredHeightYAxis = nullptr;
|
float* limitedAlteredHeightYAxis = nullptr;
|
||||||
|
|
||||||
updateKeyHeightValues(cellCoords, inCellX, inCellY, &thisHeight, &thisAlteredHeight, &leftHeight, &leftAlteredHeight,
|
updateKeyHeightValues(cellCoords, inCellX, inCellY, &thisHeight, &thisAlteredHeight, &leftHeight, &leftAlteredHeight,
|
||||||
&upHeight, &upAlteredHeight, &rightHeight, &rightAlteredHeight, &downHeight, &downAlteredHeight);
|
&upHeight, &upAlteredHeight, &rightHeight, &rightAlteredHeight, &downHeight, &downAlteredHeight);
|
||||||
|
|
||||||
|
@ -930,25 +961,9 @@ void CSVRender::TerrainShapeMode::limitAlteredHeights(const CSMWorld::CellCoordi
|
||||||
limitedAlteredHeightYAxis = new float(upHeight + limitHeightChange - (thisHeight - thisAlteredHeight));
|
limitedAlteredHeightYAxis = new float(upHeight + limitHeightChange - (thisHeight - thisAlteredHeight));
|
||||||
|
|
||||||
// Limit altered height value based on x or y, whichever is the smallest
|
// Limit altered height value based on x or y, whichever is the smallest
|
||||||
if (limitedAlteredHeightXAxis)
|
compareAndLimit(cellCoords, inCellX, inCellY, limitedAlteredHeightXAxis, limitedAlteredHeightYAxis, &steepnessIsWithinLimits);
|
||||||
{
|
|
||||||
if (limitedAlteredHeightYAxis)
|
|
||||||
{
|
|
||||||
if(std::abs(*limitedAlteredHeightXAxis) >= std::abs(*limitedAlteredHeightYAxis))
|
|
||||||
alterHeight(cellCoords, inCellX, inCellY, *limitedAlteredHeightXAxis, false);
|
|
||||||
else
|
|
||||||
alterHeight(cellCoords, inCellX, inCellY, *limitedAlteredHeightYAxis, false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
alterHeight(cellCoords, inCellX, inCellY, *limitedAlteredHeightXAxis, false);
|
|
||||||
}
|
|
||||||
else if (limitedAlteredHeightYAxis)
|
|
||||||
{
|
|
||||||
alterHeight(cellCoords, inCellX, inCellY, *limitedAlteredHeightYAxis, false);
|
|
||||||
}
|
|
||||||
delete limitedAlteredHeightXAxis;
|
delete limitedAlteredHeightXAxis;
|
||||||
delete limitedAlteredHeightYAxis;
|
delete limitedAlteredHeightYAxis; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -958,19 +973,8 @@ void CSVRender::TerrainShapeMode::limitAlteredHeights(const CSMWorld::CellCoordi
|
||||||
{
|
{
|
||||||
for(int inCellX = landSize - 1; inCellX >= 0; --inCellX)
|
for(int inCellX = landSize - 1; inCellX >= 0; --inCellX)
|
||||||
{
|
{
|
||||||
float thisHeight = 0.0f;
|
|
||||||
float thisAlteredHeight = 0.0f;
|
|
||||||
float leftHeight = 0.0f;
|
|
||||||
float leftAlteredHeight = 0.0f;
|
|
||||||
float upHeight = 0.0f;
|
|
||||||
float upAlteredHeight = 0.0f;
|
|
||||||
float rightHeight = 0.0f;
|
|
||||||
float rightAlteredHeight = 0.0f;
|
|
||||||
float downHeight = 0.0f;
|
|
||||||
float downAlteredHeight = 0.0f;
|
|
||||||
float* limitedAlteredHeightXAxis = nullptr;
|
float* limitedAlteredHeightXAxis = nullptr;
|
||||||
float* limitedAlteredHeightYAxis = nullptr;
|
float* limitedAlteredHeightYAxis = nullptr;
|
||||||
|
|
||||||
updateKeyHeightValues(cellCoords, inCellX, inCellY, &thisHeight, &thisAlteredHeight, &leftHeight, &leftAlteredHeight,
|
updateKeyHeightValues(cellCoords, inCellX, inCellY, &thisHeight, &thisAlteredHeight, &leftHeight, &leftAlteredHeight,
|
||||||
&upHeight, &upAlteredHeight, &rightHeight, &rightAlteredHeight, &downHeight, &downAlteredHeight);
|
&upHeight, &upAlteredHeight, &rightHeight, &rightAlteredHeight, &downHeight, &downAlteredHeight);
|
||||||
|
|
||||||
|
@ -987,27 +991,13 @@ void CSVRender::TerrainShapeMode::limitAlteredHeights(const CSMWorld::CellCoordi
|
||||||
limitedAlteredHeightYAxis = new float(downHeight + limitHeightChange - (thisHeight - thisAlteredHeight));
|
limitedAlteredHeightYAxis = new float(downHeight + limitHeightChange - (thisHeight - thisAlteredHeight));
|
||||||
|
|
||||||
// Limit altered height value based on x or y, whichever is the smallest
|
// Limit altered height value based on x or y, whichever is the smallest
|
||||||
if (limitedAlteredHeightXAxis)
|
compareAndLimit(cellCoords, inCellX, inCellY, limitedAlteredHeightXAxis, limitedAlteredHeightYAxis, &steepnessIsWithinLimits);
|
||||||
{
|
|
||||||
if (limitedAlteredHeightYAxis)
|
|
||||||
{
|
|
||||||
if(std::abs(*limitedAlteredHeightXAxis) >= std::abs(*limitedAlteredHeightYAxis))
|
|
||||||
alterHeight(cellCoords, inCellX, inCellY, *limitedAlteredHeightXAxis, false);
|
|
||||||
else
|
|
||||||
alterHeight(cellCoords, inCellX, inCellY, *limitedAlteredHeightYAxis, false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
alterHeight(cellCoords, inCellX, inCellY, *limitedAlteredHeightXAxis, false);
|
|
||||||
}
|
|
||||||
else if (limitedAlteredHeightYAxis)
|
|
||||||
{
|
|
||||||
alterHeight(cellCoords, inCellX, inCellY, *limitedAlteredHeightYAxis, false);
|
|
||||||
}
|
|
||||||
delete limitedAlteredHeightXAxis;
|
delete limitedAlteredHeightXAxis;
|
||||||
delete limitedAlteredHeightYAxis; }
|
delete limitedAlteredHeightYAxis; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return steepnessIsWithinLimits;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair<int, int>& vertexCoords, unsigned char selectMode, bool dragOperation)
|
void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair<int, int>& vertexCoords, unsigned char selectMode, bool dragOperation)
|
||||||
|
|
|
@ -101,8 +101,12 @@ namespace CSVRender
|
||||||
/// Bind edge vertices to next cells
|
/// Bind edge vertices to next cells
|
||||||
void fixEdges(const CSMWorld::CellCoordinates& cellCoords);
|
void fixEdges(const CSMWorld::CellCoordinates& cellCoords);
|
||||||
|
|
||||||
/// Check that the edit doesn't break save format limits, fix if necessary
|
///Limit steepness based on either X or Y and return false if steepness is limited
|
||||||
void limitAlteredHeights(const CSMWorld::CellCoordinates& cellCoords, bool reverseMode = false);
|
void compareAndLimit(const CSMWorld::CellCoordinates& cellCoords, int inCellX, int inCellY, float* limitedAlteredHeightXAxis,
|
||||||
|
float* limitedAlteredHeightYAxis, bool* steepnessIsWithinLimits);
|
||||||
|
|
||||||
|
/// Check that the edit doesn't break save format limits, fix if necessary, return true if slope steepness is within limits
|
||||||
|
bool limitAlteredHeights(const CSMWorld::CellCoordinates& cellCoords, bool reverseMode = false);
|
||||||
|
|
||||||
/// Handle brush mechanics for terrain shape selection
|
/// Handle brush mechanics for terrain shape selection
|
||||||
void selectTerrainShapes (const std::pair<int, int>& vertexCoords, unsigned char selectMode, bool dragOperation);
|
void selectTerrainShapes (const std::pair<int, int>& vertexCoords, unsigned char selectMode, bool dragOperation);
|
||||||
|
|
Loading…
Reference in a new issue