1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-21 17:39:40 +00:00

change manual memory management to std::unique_ptr

This commit is contained in:
Nelsson Huotari 2019-10-04 01:22:47 +03:00
parent da4abcd7c1
commit 388edfd8cc

View file

@ -977,27 +977,25 @@ bool CSVRender::TerrainShapeMode::limitAlteredHeights(const CSMWorld::CellCoordi
{ {
for(int inCellX = 0; inCellX < ESM::Land::LAND_SIZE; ++inCellX) for(int inCellX = 0; inCellX < ESM::Land::LAND_SIZE; ++inCellX)
{ {
float* limitedAlteredHeightXAxis = nullptr; std::unique_ptr<float> limitedAlteredHeightXAxis(nullptr);
float* limitedAlteredHeightYAxis = nullptr; std::unique_ptr<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);
// Check for height limits on x-axis // Check for height limits on x-axis
if (leftHeight - thisHeight > limitHeightChange) if (leftHeight - thisHeight > limitHeightChange)
limitedAlteredHeightXAxis = new float(leftHeight - limitHeightChange - (thisHeight - thisAlteredHeight)); limitedAlteredHeightXAxis.reset(new float(leftHeight - limitHeightChange - (thisHeight - thisAlteredHeight)));
else if (leftHeight - thisHeight < -limitHeightChange) else if (leftHeight - thisHeight < -limitHeightChange)
limitedAlteredHeightXAxis = new float(leftHeight + limitHeightChange - (thisHeight - thisAlteredHeight)); limitedAlteredHeightXAxis.reset(new float(leftHeight + limitHeightChange - (thisHeight - thisAlteredHeight)));
// Check for height limits on y-axis // Check for height limits on y-axis
if (upHeight - thisHeight > limitHeightChange) if (upHeight - thisHeight > limitHeightChange)
limitedAlteredHeightYAxis = new float(upHeight - limitHeightChange - (thisHeight - thisAlteredHeight)); limitedAlteredHeightYAxis.reset(new float(upHeight - limitHeightChange - (thisHeight - thisAlteredHeight)));
else if (upHeight - thisHeight < -limitHeightChange) else if (upHeight - thisHeight < -limitHeightChange)
limitedAlteredHeightYAxis = new float(upHeight + limitHeightChange - (thisHeight - thisAlteredHeight)); limitedAlteredHeightYAxis.reset(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
compareAndLimit(cellCoords, inCellX, inCellY, limitedAlteredHeightXAxis, limitedAlteredHeightYAxis, &steepnessIsWithinLimits); compareAndLimit(cellCoords, inCellX, inCellY, limitedAlteredHeightXAxis.get(), limitedAlteredHeightYAxis.get(), &steepnessIsWithinLimits);
delete limitedAlteredHeightXAxis;
delete limitedAlteredHeightYAxis;
} }
} }
} }
@ -1008,27 +1006,25 @@ bool CSVRender::TerrainShapeMode::limitAlteredHeights(const CSMWorld::CellCoordi
{ {
for(int inCellX = ESM::Land::LAND_SIZE - 1; inCellX >= 0; --inCellX) for(int inCellX = ESM::Land::LAND_SIZE - 1; inCellX >= 0; --inCellX)
{ {
float* limitedAlteredHeightXAxis = nullptr; std::unique_ptr<float> limitedAlteredHeightXAxis(nullptr);
float* limitedAlteredHeightYAxis = nullptr; std::unique_ptr<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);
// Check for height limits on x-axis // Check for height limits on x-axis
if (rightHeight - thisHeight > limitHeightChange) if (rightHeight - thisHeight > limitHeightChange)
limitedAlteredHeightXAxis = new float(rightHeight - limitHeightChange - (thisHeight - thisAlteredHeight)); limitedAlteredHeightXAxis.reset(new float(rightHeight - limitHeightChange - (thisHeight - thisAlteredHeight)));
else if (rightHeight - thisHeight < -limitHeightChange) else if (rightHeight - thisHeight < -limitHeightChange)
limitedAlteredHeightXAxis = new float(rightHeight + limitHeightChange - (thisHeight - thisAlteredHeight)); limitedAlteredHeightXAxis.reset(new float(rightHeight + limitHeightChange - (thisHeight - thisAlteredHeight)));
// Check for height limits on y-axis // Check for height limits on y-axis
if (downHeight - thisHeight > limitHeightChange) if (downHeight - thisHeight > limitHeightChange)
limitedAlteredHeightYAxis = new float(downHeight - limitHeightChange - (thisHeight - thisAlteredHeight)); limitedAlteredHeightYAxis.reset(new float(downHeight - limitHeightChange - (thisHeight - thisAlteredHeight)));
else if (downHeight - thisHeight < -limitHeightChange) else if (downHeight - thisHeight < -limitHeightChange)
limitedAlteredHeightYAxis = new float(downHeight + limitHeightChange - (thisHeight - thisAlteredHeight)); limitedAlteredHeightYAxis.reset(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
compareAndLimit(cellCoords, inCellX, inCellY, limitedAlteredHeightXAxis, limitedAlteredHeightYAxis, &steepnessIsWithinLimits); compareAndLimit(cellCoords, inCellX, inCellY, limitedAlteredHeightXAxis.get(), limitedAlteredHeightYAxis.get(), &steepnessIsWithinLimits);
delete limitedAlteredHeightXAxis;
delete limitedAlteredHeightYAxis;
} }
} }
} }