mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-29 17:15:32 +00:00
Remove globals, const int& -> int, values to const ref.
This commit is contained in:
parent
1dcee833a1
commit
3becacf6d1
6 changed files with 41 additions and 59 deletions
|
@ -8,13 +8,6 @@
|
|||
#include <components/esm/loadland.hpp>
|
||||
#include <components/misc/constants.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
const int cellSize {ESM::Land::REAL_SIZE};
|
||||
const int landSize {ESM::Land::LAND_SIZE};
|
||||
const int landTextureSize {ESM::Land::LAND_TEXTURE_SIZE};
|
||||
}
|
||||
|
||||
CSMWorld::CellCoordinates::CellCoordinates() : mX (0), mY (0) {}
|
||||
|
||||
CSMWorld::CellCoordinates::CellCoordinates (int x, int y) : mX (x), mY (y) {}
|
||||
|
@ -76,10 +69,10 @@ std::pair<int, int> CSMWorld::CellCoordinates::coordinatesToCellIndex (float x,
|
|||
return std::make_pair (std::floor (x / Constants::CellSizeInUnits), std::floor (y / Constants::CellSizeInUnits));
|
||||
}
|
||||
|
||||
std::pair<int, int> CSMWorld::CellCoordinates::toTextureCoords(osg::Vec3d worldPos)
|
||||
std::pair<int, int> CSMWorld::CellCoordinates::toTextureCoords(const osg::Vec3d& worldPos)
|
||||
{
|
||||
const auto xd = static_cast<float>(worldPos.x() * landTextureSize / cellSize - 0.25f);
|
||||
const auto yd = static_cast<float>(worldPos.y() * landTextureSize / cellSize + 0.25f);
|
||||
const auto xd = static_cast<float>(worldPos.x() * ESM::Land::LAND_TEXTURE_SIZE / ESM::Land::REAL_SIZE - 0.25f);
|
||||
const auto yd = static_cast<float>(worldPos.y() * ESM::Land::LAND_TEXTURE_SIZE / ESM::Land::REAL_SIZE + 0.25f);
|
||||
|
||||
const auto x = static_cast<int>(std::floor(xd));
|
||||
const auto y = static_cast<int>(std::floor(yd));
|
||||
|
@ -87,10 +80,10 @@ std::pair<int, int> CSMWorld::CellCoordinates::toTextureCoords(osg::Vec3d worldP
|
|||
return std::make_pair(x, y);
|
||||
}
|
||||
|
||||
std::pair<int, int> CSMWorld::CellCoordinates::toVertexCoords(osg::Vec3d worldPos)
|
||||
std::pair<int, int> CSMWorld::CellCoordinates::toVertexCoords(const osg::Vec3d& worldPos)
|
||||
{
|
||||
const auto xd = static_cast<float>(worldPos.x() * (landSize - 1) / cellSize + 0.5f);
|
||||
const auto yd = static_cast<float>(worldPos.y() * (landSize - 1) / cellSize + 0.5f);
|
||||
const auto xd = static_cast<float>(worldPos.x() * (ESM::Land::LAND_SIZE - 1) / ESM::Land::REAL_SIZE + 0.5f);
|
||||
const auto yd = static_cast<float>(worldPos.y() * (ESM::Land::LAND_SIZE - 1) / ESM::Land::REAL_SIZE + 0.5f);
|
||||
|
||||
const auto x = static_cast<int>(std::floor(xd));
|
||||
const auto y = static_cast<int>(std::floor(yd));
|
||||
|
@ -100,30 +93,30 @@ std::pair<int, int> CSMWorld::CellCoordinates::toVertexCoords(osg::Vec3d worldPo
|
|||
|
||||
float CSMWorld::CellCoordinates::textureSelectionToWorldCoords(int pos)
|
||||
{
|
||||
return cellSize * static_cast<float>(pos) / landTextureSize;
|
||||
return ESM::Land::REAL_SIZE * static_cast<float>(pos) / ESM::Land::LAND_TEXTURE_SIZE;
|
||||
}
|
||||
|
||||
float CSMWorld::CellCoordinates::vertexSelectionToWorldCoords(int pos)
|
||||
{
|
||||
return cellSize * static_cast<float>(pos) / (landSize - 1);
|
||||
return ESM::Land::REAL_SIZE * static_cast<float>(pos) / (ESM::Land::LAND_SIZE - 1);
|
||||
}
|
||||
|
||||
int CSMWorld::CellCoordinates::vertexSelectionToInCellCoords(int pos)
|
||||
{
|
||||
return static_cast<int>(pos - std::floor(static_cast<float>(pos) / (landSize - 1)) * (landSize - 1));
|
||||
return static_cast<int>(pos - std::floor(static_cast<float>(pos) / (ESM::Land::LAND_SIZE - 1)) * (ESM::Land::LAND_SIZE - 1));
|
||||
}
|
||||
|
||||
std::string CSMWorld::CellCoordinates::textureGlobalToCellId(std::pair<int, int> textureGlobal)
|
||||
std::string CSMWorld::CellCoordinates::textureGlobalToCellId(const std::pair<int, int>& textureGlobal)
|
||||
{
|
||||
int x = std::floor(static_cast<float>(textureGlobal.first) / landTextureSize);
|
||||
int y = std::floor(static_cast<float>(textureGlobal.second) / landTextureSize);
|
||||
int x = std::floor(static_cast<float>(textureGlobal.first) / ESM::Land::LAND_TEXTURE_SIZE);
|
||||
int y = std::floor(static_cast<float>(textureGlobal.second) / ESM::Land::LAND_TEXTURE_SIZE);
|
||||
return generateId(x, y);
|
||||
}
|
||||
|
||||
std::string CSMWorld::CellCoordinates::vertexGlobalToCellId(std::pair<int, int> vertexGlobal)
|
||||
std::string CSMWorld::CellCoordinates::vertexGlobalToCellId(const std::pair<int, int>& vertexGlobal)
|
||||
{
|
||||
int x = std::floor(static_cast<float>(vertexGlobal.first) / (landSize - 1));
|
||||
int y = std::floor(static_cast<float>(vertexGlobal.second) / (landSize - 1));
|
||||
int x = std::floor(static_cast<float>(vertexGlobal.first) / (ESM::Land::LAND_SIZE - 1));
|
||||
int y = std::floor(static_cast<float>(vertexGlobal.second) / (ESM::Land::LAND_SIZE - 1));
|
||||
return generateId(x, y);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,10 +49,10 @@ namespace CSMWorld
|
|||
static std::pair<int, int> coordinatesToCellIndex (float x, float y);
|
||||
|
||||
///Converts worldspace coordinates to global texture selection, taking in account the texture offset.
|
||||
static std::pair<int, int> toTextureCoords(osg::Vec3d worldPos);
|
||||
static std::pair<int, int> toTextureCoords(const osg::Vec3d& worldPos);
|
||||
|
||||
///Converts worldspace coordinates to global vertex selection.
|
||||
static std::pair<int, int> toVertexCoords(osg::Vec3d worldPos);
|
||||
static std::pair<int, int> toVertexCoords(const osg::Vec3d& worldPos);
|
||||
|
||||
///Converts global texture coordinate to worldspace coordinate that is at the upper left corner of the selected texture.
|
||||
static float textureSelectionToWorldCoords(int);
|
||||
|
@ -63,10 +63,10 @@ namespace CSMWorld
|
|||
///Converts local cell's heightmap coordinates from the global vertex coordinate
|
||||
static int vertexSelectionToInCellCoords(int);
|
||||
|
||||
static std::string textureGlobalToCellId(std::pair<int, int>);
|
||||
static std::string textureGlobalToCellId(const std::pair<int, int>&);
|
||||
|
||||
///Converts global vertex coordinates to cell id
|
||||
static std::string vertexGlobalToCellId(std::pair<int, int>);
|
||||
static std::string vertexGlobalToCellId(const std::pair<int, int>&);
|
||||
};
|
||||
|
||||
bool operator== (const CellCoordinates& left, const CellCoordinates& right);
|
||||
|
|
|
@ -15,13 +15,6 @@
|
|||
#include "cell.hpp"
|
||||
#include "worldspacewidget.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
const int cellSize {ESM::Land::REAL_SIZE};
|
||||
const int landSize {ESM::Land::LAND_SIZE};
|
||||
const int landTextureSize {ESM::Land::LAND_TEXTURE_SIZE};
|
||||
}
|
||||
|
||||
CSVRender::TerrainSelection::TerrainSelection(osg::Group* parentNode, WorldspaceWidget *worldspaceWidget, TerrainSelectionType type):
|
||||
mParentNode(parentNode), mWorldspaceWidget (worldspaceWidget), mDraggedOperationFlag(false), mSelectionType(type)
|
||||
{
|
||||
|
@ -180,10 +173,10 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptr<osg::V
|
|||
{
|
||||
// Nudge selection by 1/4th of a texture size, similar how blendmaps are nudged
|
||||
const float nudgePercentage = 0.25f;
|
||||
const int nudgeOffset = (cellSize / landTextureSize) * nudgePercentage;
|
||||
const int landHeightsNudge = (cellSize / landSize) / (landSize - 1); // Does this work with all land size configurations?
|
||||
const int nudgeOffset = (ESM::Land::REAL_SIZE / ESM::Land::LAND_TEXTURE_SIZE) * nudgePercentage;
|
||||
const int landHeightsNudge = (ESM::Land::REAL_SIZE / ESM::Land::LAND_SIZE) / (ESM::Land::LAND_SIZE - 1); // Does this work with all land size configurations?
|
||||
|
||||
const int textureSizeToLandSizeModifier = (landSize - 1) / landTextureSize;
|
||||
const int textureSizeToLandSizeModifier = (ESM::Land::LAND_SIZE - 1) / ESM::Land::LAND_TEXTURE_SIZE;
|
||||
|
||||
for (std::pair<int, int> &localPos : mSelection)
|
||||
{
|
||||
|
@ -203,8 +196,8 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptr<osg::V
|
|||
{
|
||||
for(int i = 1; i < (textureSizeToLandSizeModifier + 1); i++)
|
||||
{
|
||||
float drawPreviousX = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x)+(i-1)*(cellSize / (landSize - 1));
|
||||
float drawCurrentX = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x)+i*(cellSize / (landSize - 1));
|
||||
float drawPreviousX = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x) + (i - 1) * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1));
|
||||
float drawCurrentX = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x) + i * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1));
|
||||
vertices->push_back(osg::Vec3f(drawPreviousX + nudgeOffset, CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y + 1) - nudgeOffset, calculateLandHeight(x1+(i-1), y2)+2));
|
||||
vertices->push_back(osg::Vec3f(drawCurrentX + nudgeOffset, CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y + 1) - nudgeOffset, calculateLandHeight(x1+i, y2)+2));
|
||||
}
|
||||
|
@ -215,8 +208,8 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptr<osg::V
|
|||
{
|
||||
for(int i = 1; i < (textureSizeToLandSizeModifier + 1); i++)
|
||||
{
|
||||
float drawPreviousX = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x)+(i-1)*(cellSize / (landSize - 1));
|
||||
float drawCurrentX = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x)+i*(cellSize / (landSize - 1));
|
||||
float drawPreviousX = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x) + (i - 1) *(ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1));
|
||||
float drawCurrentX = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x) + i * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1));
|
||||
vertices->push_back(osg::Vec3f(drawPreviousX + nudgeOffset, CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y) - nudgeOffset, calculateLandHeight(x1+(i-1), y1)+2));
|
||||
vertices->push_back(osg::Vec3f(drawCurrentX + nudgeOffset, CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y) - nudgeOffset, calculateLandHeight(x1+i, y1)+2));
|
||||
}
|
||||
|
@ -227,8 +220,8 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptr<osg::V
|
|||
{
|
||||
for(int i = 1; i < (textureSizeToLandSizeModifier + 1); i++)
|
||||
{
|
||||
float drawPreviousY = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y)+(i-1)*(cellSize / (landSize - 1));
|
||||
float drawCurrentY = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y)+i*(cellSize / (landSize - 1));
|
||||
float drawPreviousY = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y) + (i - 1) * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1));
|
||||
float drawCurrentY = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y) + i * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1));
|
||||
vertices->push_back(osg::Vec3f(CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x + 1) + nudgeOffset, drawPreviousY - nudgeOffset, calculateLandHeight(x2, y1+(i-1))+2));
|
||||
vertices->push_back(osg::Vec3f(CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x + 1) + nudgeOffset, drawCurrentY - nudgeOffset, calculateLandHeight(x2, y1+i)+2));
|
||||
}
|
||||
|
@ -239,8 +232,8 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptr<osg::V
|
|||
{
|
||||
for(int i = 1; i < (textureSizeToLandSizeModifier + 1); i++)
|
||||
{
|
||||
float drawPreviousY = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y)+(i-1)*(cellSize / (landSize - 1));
|
||||
float drawCurrentY = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y)+i*(cellSize / (landSize - 1));
|
||||
float drawPreviousY = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y) + (i - 1) * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1));
|
||||
float drawCurrentY = CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y) + i * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1));
|
||||
vertices->push_back(osg::Vec3f(CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x) + nudgeOffset, drawPreviousY - nudgeOffset, calculateLandHeight(x1, y1+(i-1))+2));
|
||||
vertices->push_back(osg::Vec3f(CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x) + nudgeOffset, drawCurrentY - nudgeOffset, calculateLandHeight(x1, y1+i)+2));
|
||||
}
|
||||
|
@ -251,10 +244,10 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptr<osg::V
|
|||
|
||||
int CSVRender::TerrainSelection::calculateLandHeight(int x, int y) // global vertex coordinates
|
||||
{
|
||||
int cellX = std::floor((1.0f*x / (landSize - 1)));
|
||||
int cellY = std::floor((1.0f*y / (landSize - 1)));
|
||||
int localX = x - cellX * (landSize - 1);
|
||||
int localY = y - cellY * (landSize - 1);
|
||||
int cellX = std::floor((1.0f*x / (ESM::Land::LAND_SIZE - 1)));
|
||||
int cellY = std::floor((1.0f*y / (ESM::Land::LAND_SIZE - 1)));
|
||||
int localX = x - cellX * (ESM::Land::LAND_SIZE - 1);
|
||||
int localY = y - cellY * (ESM::Land::LAND_SIZE - 1);
|
||||
|
||||
std::string cellId = CSMWorld::CellCoordinates::generateId(cellX, cellY);
|
||||
|
||||
|
@ -264,5 +257,5 @@ int CSVRender::TerrainSelection::calculateLandHeight(int x, int y) // global ver
|
|||
int landshapeColumn = landTable.findColumnIndex(CSMWorld::Columns::ColumnId_LandHeightsIndex);
|
||||
const CSMWorld::LandHeightsColumn::DataType mPointer = landTable.data(landTable.getModelIndex(cellId, landshapeColumn)).value<CSMWorld::LandHeightsColumn::DataType>();
|
||||
|
||||
return mPointer[localY*landSize + localX];
|
||||
return mPointer[localY*ESM::Land::LAND_SIZE + localX];
|
||||
}
|
||||
|
|
|
@ -46,10 +46,6 @@ namespace CSVRender
|
|||
|
||||
protected:
|
||||
|
||||
void addToSelection(osg::Vec3d worldPos);
|
||||
void toggleSelection(osg::Vec3d worldPos);
|
||||
void deselect();
|
||||
|
||||
void update();
|
||||
|
||||
void drawShapeSelection(const osg::ref_ptr<osg::Vec3Array> vertices);
|
||||
|
|
|
@ -492,7 +492,7 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe
|
|||
}
|
||||
}
|
||||
|
||||
bool CSVRender::TerrainTextureMode::isInCellSelection(const int& globalSelectionX, const int& globalSelectionY)
|
||||
bool CSVRender::TerrainTextureMode::isInCellSelection(int globalSelectionX, int globalSelectionY)
|
||||
{
|
||||
if (CSVRender::PagedWorldspaceWidget *paged = dynamic_cast<CSVRender::PagedWorldspaceWidget *> (&getWorldspaceWidget()))
|
||||
{
|
||||
|
@ -732,12 +732,12 @@ void CSVRender::TerrainTextureMode::setBrushShape(int brushShape)
|
|||
|
||||
for(auto const& value: terrainSelection)
|
||||
{
|
||||
selectionCenterX = selectionCenterX + value.first;
|
||||
selectionCenterY = selectionCenterY + value.second;
|
||||
selectionCenterX += value.first;
|
||||
selectionCenterY += value.second;
|
||||
++selectionAmount;
|
||||
}
|
||||
selectionCenterX = selectionCenterX / selectionAmount;
|
||||
selectionCenterY = selectionCenterY / selectionAmount;
|
||||
selectionCenterX /= selectionAmount;
|
||||
selectionCenterY /= selectionAmount;
|
||||
|
||||
mCustomBrushShape.clear();
|
||||
for (auto const& value: terrainSelection)
|
||||
|
|
|
@ -85,7 +85,7 @@ namespace CSVRender
|
|||
void editTerrainTextureGrid (const WorldspaceHitResult& hit);
|
||||
|
||||
/// \brief Check if global selection coordinate belongs to cell in view
|
||||
bool isInCellSelection(const int& globalSelectionX, const int& globalSelectionY);
|
||||
bool isInCellSelection(int globalSelectionX, int globalSelectionY);
|
||||
|
||||
/// \brief Handle brush mechanics for texture selection
|
||||
void selectTerrainTextures (const std::pair<int, int>& texCoords, unsigned char selectMode, bool dragOperation);
|
||||
|
|
Loading…
Reference in a new issue