From cb82d379923e6d1c24e599e8489bd9296fe823f2 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sat, 20 Sep 2025 11:39:31 +0200 Subject: [PATCH] Address remaining conversion warnings in components --- components/detournavigator/navmeshdb.cpp | 10 +++--- components/esmterrain/storage.cpp | 39 ++++++++++++------------ components/fx/widgets.hpp | 18 +++++------ components/lua/serialization.cpp | 34 ++++++++++----------- components/misc/color.cpp | 6 ++-- components/nifosg/nifloader.cpp | 3 +- components/resource/scenemanager.cpp | 4 +-- components/terrain/quadtreeworld.cpp | 4 +-- components/widgets/box.cpp | 16 +++++----- 9 files changed, 66 insertions(+), 68 deletions(-) diff --git a/components/detournavigator/navmeshdb.cpp b/components/detournavigator/navmeshdb.cpp index bfc6dd5ecb..e3ef995cd7 100644 --- a/components/detournavigator/navmeshdb.cpp +++ b/components/detournavigator/navmeshdb.cpp @@ -195,7 +195,7 @@ namespace DetourNavigator TileId NavMeshDb::getMaxTileId() { TileId tileId{ 0 }; - request(*mDb, mGetMaxTileId, &tileId, 1); + request(*mDb, mGetMaxTileId, &tileId.mValue, 1); return tileId; } @@ -203,7 +203,7 @@ namespace DetourNavigator ESM::RefId worldspace, const TilePosition& tilePosition, const std::vector& input) { Tile result; - auto row = std::tie(result.mTileId, result.mVersion); + auto row = std::tie(result.mTileId.mValue, result.mVersion.mValue); const std::vector compressedInput = Misc::compress(input); if (&row == request(*mDb, mFindTile, &row, 1, worldspace.serializeText(), tilePosition, compressedInput)) return {}; @@ -214,7 +214,7 @@ namespace DetourNavigator ESM::RefId worldspace, const TilePosition& tilePosition, const std::vector& input) { TileData result; - auto row = std::tie(result.mTileId, result.mVersion, result.mData); + auto row = std::tie(result.mTileId.mValue, result.mVersion.mValue, result.mData); const std::vector compressedInput = Misc::compress(input); if (&row == request(*mDb, mGetTileData, &row, 1, worldspace.serializeText(), tilePosition, compressedInput)) return {}; @@ -255,14 +255,14 @@ namespace DetourNavigator ShapeId NavMeshDb::getMaxShapeId() { ShapeId shapeId{ 0 }; - request(*mDb, mGetMaxShapeId, &shapeId, 1); + request(*mDb, mGetMaxShapeId, &shapeId.mValue, 1); return shapeId; } std::optional NavMeshDb::findShapeId(std::string_view name, ShapeType type, const Sqlite3::ConstBlob& hash) { ShapeId shapeId; - if (&shapeId == request(*mDb, mFindShapeId, &shapeId, 1, name, type, hash)) + if (&shapeId.mValue == request(*mDb, mFindShapeId, &shapeId.mValue, 1, name, type, hash)) return {}; return shapeId; } diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index 73030ab96a..4ff61dc00a 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -130,11 +130,11 @@ namespace ESMTerrain osg::ref_ptr land = getLand(ESM::ExteriorCellLocation(cellX, cellY, worldspace)); const ESM::LandData* data = land ? land->getData(ESM::Land::DATA_VHGT) : nullptr; const int landSize = ESM::getLandSize(worldspace); - int startRow = (origin.x() - cellX) * landSize; - int startColumn = (origin.y() - cellY) * landSize; + int startRow = static_cast((origin.x() - cellX) * landSize); + int startColumn = static_cast((origin.y() - cellY) * landSize); - int endRow = startRow + size * (landSize - 1) + 1; - int endColumn = startColumn + size * (landSize - 1) + 1; + int endRow = static_cast(startRow + size * (landSize - 1) + 1); + int endColumn = static_cast(startColumn + size * (landSize - 1) + 1); if (data) { @@ -283,8 +283,8 @@ namespace ESMTerrain 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 int cellX = startCellX + static_cast(cellShiftX); + const int cellY = startCellY + static_cast(cellShiftY); const std::pair cell{ cellX, cellY }; const ESM::ExteriorCellLocation cellLocation(cellX, cellY, worldspace); @@ -311,7 +311,7 @@ namespace ESMTerrain if (heightData != nullptr) height = heightData->getHeights()[col * cellSize + row]; if (alteration) - height += getAlteredHeight(col, row); + height += getAlteredHeight(static_cast(col), static_cast(row)); const std::size_t vertIndex = vertX * numVerts + vertY; @@ -325,7 +325,7 @@ namespace ESMTerrain if (normalData != nullptr) { - for (std::size_t i = 0; i < 3; ++i) + for (unsigned short i = 0; i < 3; ++i) normal[i] = normalData->getNormals()[srcArrayIndex + i]; normal.normalize(); @@ -333,11 +333,11 @@ namespace ESMTerrain // Normals apparently don't connect seamlessly between cells if (col == cellSize - 1 || row == cellSize - 1) - fixNormal(normal, cellLocation, col, row, cache); + fixNormal(normal, cellLocation, static_cast(col), static_cast(row), cache); // some corner normals appear to be complete garbage (z < 0) if ((row == 0 || row == cellSize - 1) && (col == 0 || col == cellSize - 1)) - averageNormal(normal, cellLocation, col, row, cache); + averageNormal(normal, cellLocation, static_cast(col), static_cast(row), cache); assert(normal.z() > 0); @@ -346,16 +346,16 @@ namespace ESMTerrain osg::Vec4ub color(255, 255, 255, 255); if (colourData != nullptr) - for (std::size_t i = 0; i < 3; ++i) + for (unsigned short i = 0; i < 3; ++i) color[i] = colourData->getColors()[srcArrayIndex + i]; // Does nothing by default, override in OpenMW-CS if (alteration) - adjustColor(col, row, heightData, color); + adjustColor(static_cast(col), static_cast(row), heightData, color); // Unlike normals, colors mostly connect seamlessly between cells, but not always... if (col == cellSize - 1 || row == cellSize - 1) - fixColour(color, cellLocation, col, row, cache); + fixColour(color, cellLocation, static_cast(col), static_cast(row), cache); colours[vertIndex] = color; }; @@ -445,7 +445,7 @@ namespace ESMTerrain unsigned char* const baseBlendmap = getOrCreateBlendmap(ESM::FormId::fromUint32(ltex.base.formId)); int starty = (static_cast(sample.mDstCol) - 1) * quadSize; - int startx = sample.mDstRow * quadSize; + int startx = static_cast(sample.mDstRow) * quadSize; for (int y = std::max(0, starty + 1); y <= starty + quadSize && y < blendmapSize; ++y) { unsigned char* const row = baseBlendmap + (blendmapSize - y - 1) * blendmapSize; @@ -465,9 +465,9 @@ namespace ESMTerrain { continue; } - int index = (blendmapSize - starty - y - 1) * blendmapSize + startx + x; - int delta = std::clamp(static_cast(v.opacity * 255), 0, 255); - baseBlendmap[index] = std::max(0, baseBlendmap[index] - delta); + size_t index = static_cast((blendmapSize - starty - y - 1) * blendmapSize + startx + x); + auto delta = static_cast(std::clamp(static_cast(v.opacity * 255.f), 0, 255)); + baseBlendmap[index] = std::max(0, baseBlendmap[index] - delta); layerBlendmap[index] = delta; } } @@ -567,7 +567,7 @@ namespace ESMTerrain float Storage::getHeightAt(const osg::Vec3f& worldPos, ESM::RefId worldspace) { - const float cellSize = ESM::getCellSize(worldspace); + const float cellSize = static_cast(ESM::getCellSize(worldspace)); int cellX = static_cast(std::floor(worldPos.x() / cellSize)); int cellY = static_cast(std::floor(worldPos.y() / cellSize)); @@ -645,7 +645,8 @@ namespace ESMTerrain */ // Solve plane equation for z - return (-plane.getNormal().x() * nX - plane.getNormal().y() * nY - plane[3]) / plane.getNormal().z() * cellSize; + return static_cast( + (-plane.getNormal().x() * nX - plane.getNormal().y() * nY - plane[3]) / plane.getNormal().z() * cellSize); } const LandObject* Storage::getLand(ESM::ExteriorCellLocation cellLocation, LandCache& cache) diff --git a/components/fx/widgets.hpp b/components/fx/widgets.hpp index dd7b9343bf..2f563865d5 100644 --- a/components/fx/widgets.hpp +++ b/components/fx/widgets.hpp @@ -97,8 +97,8 @@ namespace Fx if constexpr (std::is_fundamental_v) { mUniform->template setValue(mValue); - range = mUniform->template getMax() - mUniform->template getMin(); - min = mUniform->template getMin(); + range = static_cast(mUniform->template getMax() - mUniform->template getMin()); + min = static_cast(mUniform->template getMin()); } else { @@ -155,9 +155,9 @@ namespace Fx void notifyMouseWheel(MyGUI::Widget* /*sender*/, int rel) { if (rel > 0) - increment(mUniform->mStep); + increment(static_cast(mUniform->mStep)); else - increment(-mUniform->mStep); + increment(static_cast(-mUniform->mStep)); } void notifyMouseButtonDragged(MyGUI::Widget* /*sender*/, int left, int top, MyGUI::MouseButton id) @@ -169,15 +169,15 @@ namespace Fx // allow finer tuning when shift is pressed constexpr double scaling = 20.0; - T step - = MyGUI::InputManager::getInstance().isShiftPressed() ? mUniform->mStep / scaling : mUniform->mStep; + T step = static_cast( + MyGUI::InputManager::getInstance().isShiftPressed() ? mUniform->mStep / scaling : mUniform->mStep); if (step == 0) { if constexpr (std::is_integral_v) step = 1; else - step = mUniform->mStep; + step = static_cast(mUniform->mStep); } if (delta > 0) @@ -209,9 +209,9 @@ namespace Fx void notifyButtonClicked(MyGUI::Widget* sender) { if (sender == mButtonDecrease) - increment(-mUniform->mStep); + increment(static_cast(-mUniform->mStep)); else if (sender == mButtonIncrease) - increment(mUniform->mStep); + increment(static_cast(mUniform->mStep)); } MyGUI::Button* mButtonDecrease{ nullptr }; diff --git a/components/lua/serialization.cpp b/components/lua/serialization.cpp index 2a66702589..8a878ae51a 100644 --- a/components/lua/serialization.cpp +++ b/components/lua/serialization.cpp @@ -68,7 +68,7 @@ namespace LuaUtil else { appendType(out, SerializedType::LONG_STRING); - appendValue(out, str.size()); + appendValue(out, static_cast(str.size())); } out.append(str.data(), str.size()); } @@ -83,14 +83,14 @@ namespace LuaUtil assert(!typeName.empty() && typeName.size() <= 64); if (typeName.size() <= 8 && dataSize < 16) { // Compact form: 0b1SSSSTTT. SSSS = dataSize, TTT = (typeName size - 1). - unsigned char t = CUSTOM_COMPACT_FLAG | (dataSize << 3) | (typeName.size() - 1); + auto t = static_cast(CUSTOM_COMPACT_FLAG | (dataSize << 3) | (typeName.size() - 1)); out.push_back(t); } else { // Full form: 0b01TTTTTT + 32bit dataSize. - unsigned char t = CUSTOM_FULL_FLAG | (typeName.size() - 1); + auto t = static_cast(CUSTOM_FULL_FLAG | (typeName.size() - 1)); out.push_back(t); - appendValue(out, dataSize); + appendValue(out, static_cast(dataSize)); } out.append(typeName.data(), typeName.size()); appendData(out, data, dataSize); @@ -156,8 +156,8 @@ namespace LuaUtil { appendType(out, SerializedType::TRANSFORM_M); osg::Matrixf matrix = data.as().mM; - for (size_t i = 0; i < 4; i++) - for (size_t j = 0; j < 4; j++) + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) appendValue(out, matrix(i, j)); return; } @@ -165,7 +165,7 @@ namespace LuaUtil { appendType(out, SerializedType::TRANSFORM_Q); osg::Quat quat = data.as().mQ; - for (size_t i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) appendValue(out, quat[i]); return; } @@ -304,16 +304,16 @@ namespace LuaUtil throw std::runtime_error("Unexpected end of table during deserialization."); case SerializedType::VEC2: { - float x = getValue(binaryData); - float y = getValue(binaryData); + float x = static_cast(getValue(binaryData)); + float y = static_cast(getValue(binaryData)); sol::stack::push(lua, osg::Vec2f(x, y)); return; } case SerializedType::VEC3: { - float x = getValue(binaryData); - float y = getValue(binaryData); - float z = getValue(binaryData); + float x = static_cast(getValue(binaryData)); + float y = static_cast(getValue(binaryData)); + float z = static_cast(getValue(binaryData)); sol::stack::push(lua, osg::Vec3f(x, y, z)); return; } @@ -322,7 +322,7 @@ namespace LuaUtil osg::Matrixf mat; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) - mat(i, j) = getValue(binaryData); + mat(i, j) = static_cast(getValue(binaryData)); sol::stack::push(lua, asTransform(mat)); return; } @@ -336,10 +336,10 @@ namespace LuaUtil } case SerializedType::VEC4: { - float x = getValue(binaryData); - float y = getValue(binaryData); - float z = getValue(binaryData); - float w = getValue(binaryData); + float x = static_cast(getValue(binaryData)); + float y = static_cast(getValue(binaryData)); + float z = static_cast(getValue(binaryData)); + float w = static_cast(getValue(binaryData)); sol::stack::push(lua, osg::Vec4f(x, y, z, w)); return; } diff --git a/components/misc/color.cpp b/components/misc/color.cpp index 5ad52580d4..bfb711a5b1 100644 --- a/components/misc/color.cpp +++ b/components/misc/color.cpp @@ -28,10 +28,10 @@ namespace Misc throw std::logic_error(std::string("Invalid hex color: ") += hex); Color col; col.mValue.a() = 1; - for (size_t i = 0; i < 3; i++) + for (unsigned i = 0; i < 3; i++) { auto sub = hex.substr(i * 2, 2); - int v = 0; + unsigned char v = 0; auto [_, ec] = std::from_chars(sub.data(), sub.data() + sub.size(), v, 16); if (ec != std::errc()) throw std::logic_error(std::string("Invalid hex color: ") += hex); @@ -53,7 +53,7 @@ namespace Misc std::string Color::toHex() const { std::string result(6, '0'); - for (size_t i = 0; i < 3; i++) + for (unsigned i = 0; i < 3; i++) { int b = static_cast(mValue[i] * 255.0f); char* start = result.data() + i * 2; diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index f36dc9e6ce..12aae46a49 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -1554,8 +1554,7 @@ namespace NifOsg const auto& uvlist = niGeometryData->mUVList; int textureStage = 0; - for (std::vector::const_iterator it = boundTextures.begin(); it != boundTextures.end(); - ++it, ++textureStage) + for (auto it = boundTextures.begin(); it != boundTextures.end(); ++it, ++textureStage) { unsigned int uvSet = *it; if (uvSet >= uvlist.size()) diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index d309174fcf..a2722c1b8f 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -169,10 +169,8 @@ namespace Resource { if (NifOsg::FlipController* flipctrl = dynamic_cast(&ctrl)) { - for (std::vector>::iterator it = flipctrl->getTextures().begin(); - it != flipctrl->getTextures().end(); ++it) + for (const osg::ref_ptr& tex : flipctrl->getTextures()) { - osg::Texture* tex = *it; tex->setFilter(osg::Texture::MIN_FILTER, mMinFilter); tex->setFilter(osg::Texture::MAG_FILTER, mMagFilter); tex->setMaxAnisotropy(mMaxAnisotropy); diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index c0e3bc7384..8a91941fe0 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -283,8 +283,8 @@ namespace Terrain Storage* storage, unsigned int nodeMask, unsigned int preCompileMask, unsigned int borderMask, int compMapResolution, float compMapLevel, float lodFactor, int vertexLodMod, float maxCompGeometrySize, bool debugChunks, ESM::RefId worldspace, double expiryDelay) - : TerrainGrid(parent, compileRoot, resourceSystem, storage, nodeMask, worldspace, expiryDelay, preCompileMask, - borderMask) + : TerrainGrid( + parent, compileRoot, resourceSystem, storage, nodeMask, worldspace, expiryDelay, preCompileMask, borderMask) , mViewDataMap(new ViewDataMap) , mQuadTreeBuilt(false) , mLodFactor(lodFactor) diff --git a/components/widgets/box.cpp b/components/widgets/box.cpp index 49e10b49e8..db939d3e3f 100644 --- a/components/widgets/box.cpp +++ b/components/widgets/box.cpp @@ -176,14 +176,14 @@ namespace Gui void HBox::align() { - unsigned int count = getChildCount(); - size_t hStretchedCount = 0; + const size_t count = getChildCount(); + int hStretchedCount = 0; int totalWidth = 0; int totalHeight = 0; std::vector> sizes; sizes.resize(count); - for (unsigned int i = 0; i < count; ++i) + for (size_t i = 0; i < count; ++i) { MyGUI::Widget* w = getChildAt(i); bool hstretch = w->getUserString("HStretch") == "true"; @@ -221,7 +221,7 @@ namespace Gui } int curX = 0; - for (unsigned int i = 0; i < count; ++i) + for (size_t i = 0; i < count; ++i) { if (i == 0) curX += mPadding; @@ -328,13 +328,13 @@ namespace Gui void VBox::align() { - unsigned int count = getChildCount(); - size_t vStretchedCount = 0; + const size_t count = getChildCount(); + int vStretchedCount = 0; int totalHeight = 0; int totalWidth = 0; std::vector> sizes; sizes.resize(count); - for (unsigned int i = 0; i < count; ++i) + for (size_t i = 0; i < count; ++i) { MyGUI::Widget* w = getChildAt(i); @@ -375,7 +375,7 @@ namespace Gui } int curY = 0; - for (unsigned int i = 0; i < count; ++i) + for (size_t i = 0; i < count; ++i) { if (i == 0) curY += mPadding;