From f7292680d6f53ca8956b538d6b86ed9483d6d2f9 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Thu, 18 Sep 2025 22:00:55 +0200 Subject: [PATCH] Fix most conversion warnings in components --- components/debug/debugdraw.cpp | 71 ++++++++-------- components/debug/gldebug.cpp | 3 +- .../detournavigator/asyncnavmeshupdater.cpp | 4 +- components/detournavigator/raycast.cpp | 2 +- .../detournavigator/recastmeshbuilder.cpp | 9 ++- components/detournavigator/settingsutils.hpp | 8 +- components/detournavigator/tilebounds.hpp | 6 +- components/esm3/aisequence.cpp | 4 +- components/esm3/loadmgef.cpp | 5 +- components/fontloader/fontloader.cpp | 2 +- components/fx/types.hpp | 6 +- components/lua/scriptscontainer.cpp | 6 +- components/lua_ui/image.cpp | 4 +- components/lua_ui/layers.hpp | 2 +- components/lua_ui/properties.hpp | 13 ++- components/lua_ui/widget.cpp | 15 ++-- components/lua_ui/window.cpp | 4 +- .../myguiplatform/myguirendermanager.cpp | 9 ++- components/nif/niffile.cpp | 2 +- components/nif/node.cpp | 10 +-- components/nifosg/nifloader.cpp | 69 ++++++++-------- components/nifosg/particle.cpp | 3 +- components/resource/bulletshapemanager.cpp | 4 +- components/resource/scenemanager.cpp | 29 ++++--- components/resource/scenemanager.hpp | 4 +- components/sceneutil/lightmanager.cpp | 19 +++-- components/sceneutil/mwshadowtechnique.cpp | 2 +- components/sceneutil/pathgridutil.cpp | 25 ++++-- components/sceneutil/waterutil.cpp | 3 +- components/sdlutil/sdlinputwrapper.cpp | 10 +-- components/shader/shadermanager.cpp | 3 +- components/stereo/multiview.cpp | 2 +- components/stereo/stereomanager.cpp | 6 +- components/stereo/stereomanager.hpp | 8 +- components/stereo/types.cpp | 21 ++--- components/terrain/buffercache.cpp | 81 ++++++++++--------- components/terrain/cellborder.cpp | 6 +- components/terrain/chunkmanager.cpp | 11 +-- components/terrain/compositemaprenderer.cpp | 6 +- components/terrain/compositemaprenderer.hpp | 4 +- components/terrain/material.cpp | 9 +-- components/terrain/quadtreenode.hpp | 2 +- components/terrain/quadtreeworld.cpp | 28 ++++--- components/terrain/quadtreeworld.hpp | 2 +- components/terrain/storage.hpp | 6 +- components/terrain/terraindrawable.cpp | 6 +- 46 files changed, 298 insertions(+), 256 deletions(-) diff --git a/components/debug/debugdraw.cpp b/components/debug/debugdraw.cpp index e013af0e11..f1a38bde57 100644 --- a/components/debug/debugdraw.cpp +++ b/components/debug/debugdraw.cpp @@ -13,7 +13,7 @@ static osg::Vec3 sphereCoordToCartesian(float theta, float phi, float r) { osg::Vec3 returnVec = osg::Vec3(0.0, 0.0, 0.0); - float phiToHorizontal = osg::PI_2 - phi; + float phiToHorizontal = osg::PI_2f - phi; returnVec.x() = std::cos(theta); returnVec.y() = std::sin(theta); returnVec.z() = std::sin(phiToHorizontal); @@ -36,9 +36,9 @@ static void generateWireCube(osg::Geometry& geom, float dim) for (int i = 0; i < 4; i++) { - osg::Vec3 vert1 = osg::Vec3(indexPos[i].x() - 0.5, indexPos[i].y() - 0.5, 0.5); + osg::Vec3 vert1 = osg::Vec3(indexPos[i].x() - 0.5f, indexPos[i].y() - 0.5f, 0.5f); int next = (i + 1) % 4; - osg::Vec3 vert2 = osg::Vec3(indexPos[next].x() - 0.5, indexPos[next].y() - 0.5, 0.5); + osg::Vec3 vert2 = osg::Vec3(indexPos[next].x() - 0.5f, indexPos[next].y() - 0.5f, 0.5f); vertices->push_back(vert1 * dim); vertices->push_back(vert2 * dim); @@ -59,7 +59,7 @@ static void generateWireCube(osg::Geometry& geom, float dim) geom.setVertexArray(vertices); geom.setNormalArray(normals, osg::Array::BIND_PER_VERTEX); - geom.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size())); + geom.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, static_cast(vertices->size()))); } static void generateCube(osg::Geometry& geom, float dim) @@ -68,14 +68,13 @@ static void generateCube(osg::Geometry& geom, float dim) osg::ref_ptr normals = new osg::Vec3Array; osg::ref_ptr indices = new osg::DrawElementsUShort(osg::DrawElementsUShort::TRIANGLES, 0); - for (int iFace = 0; iFace < 6; iFace++) + for (GLushort iFace = 0; iFace < 6; iFace++) { osg::Vec3f normale(0., 0., 0.); osg::Vec3f u(0., 0., 0.); osg::Vec3f v(0., 0., 0.); - int axis = iFace / 2; - int dir = iFace % 2 == 0 ? -1 : 1; - float floatDir = dir; + GLushort axis = iFace / 2; + float floatDir = iFace % 2 == 0 ? -1.f : 1.f; normale[axis] = floatDir; u[(axis + 1) % 3] = 1.0; v[(axis + 2) % 3] = 1.0; @@ -85,20 +84,20 @@ static void generateCube(osg::Geometry& geom, float dim) float iu = iPoint % 2 == 1 ? floatDir : -floatDir; // This is to get the right triangle orientation when the normal changes* - float iv = iPoint / 2 == 1 ? 1.0 : -1.0; + float iv = iPoint / 2 == 1 ? 1.f : -1.f; osg::Vec3f point = (u * iu) + (v * iv); point = (point + normale); point = point * (dim * 0.5f); vertices->push_back(point); normals->push_back(normale); } - int startVertex(iFace * 4); - int newFace1[] = { startVertex, startVertex + 1, startVertex + 2 }; + GLushort startVertex(iFace * 4); + GLushort newFace1[] = { startVertex, startVertex + 1u, startVertex + 2u }; for (int i = 0; i < 3; i++) { indices->push_back(newFace1[i]); } - int newFace2[] = { startVertex + 2, startVertex + 1, startVertex + 3 }; + GLushort newFace2[] = { startVertex + 2u, startVertex + 1u, startVertex + 3u }; for (int i = 0; i < 3; i++) { indices->push_back(newFace2[i]); @@ -123,25 +122,25 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in // top disk for (int i = 0; i < subdiv; i++) { - float theta = (float(i) / float(subdiv)) * osg::PI * 2.; - osg::Vec3 pos = sphereCoordToCartesian(theta, osg::PI_2f, 1.); + float theta = (float(i) / float(subdiv)) * osg::PIf * 2.f; + osg::Vec3 pos = sphereCoordToCartesian(theta, osg::PI_2f, 1.f); pos *= radius; - pos.z() = height / 2.; + pos.z() = height / 2.f; vertices->push_back(pos); normals->push_back(topNormal); iVertex += 1; } - auto centerTop = iVertex; + auto centerTop = static_cast(iVertex); // centerTop { - vertices->push_back(osg::Vec3(0., 0., height / 2.)); + vertices->push_back(osg::Vec3(0.f, 0.f, height / 2.f)); normals->push_back(topNormal); iVertex += 1; } - auto centerBot = iVertex; + auto centerBot = static_cast(iVertex); // centerBot { - vertices->push_back(osg::Vec3(0., 0., -height / 2)); + vertices->push_back(osg::Vec3(0.f, 0.f, -height / 2)); normals->push_back(-topNormal); iVertex += 1; } @@ -149,10 +148,10 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in auto beginBot = iVertex; for (int i = 0; i < subdiv; i++) { - float theta = float(i) / float(subdiv) * osg::PI * 2.; - osg::Vec3 pos = sphereCoordToCartesian(theta, osg::PI_2f, 1.); + float theta = float(i) / float(subdiv) * osg::PIf * 2.f; + osg::Vec3 pos = sphereCoordToCartesian(theta, osg::PI_2f, 1.f); pos *= radius; - pos.z() = -height / 2.; + pos.z() = -height / 2.f; vertices->push_back(pos); normals->push_back(-topNormal); iVertex += 1; @@ -161,13 +160,13 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in int beginSide = iVertex; for (int i = 0; i < subdiv; i++) { - float theta = float(i) / float(subdiv) * osg::PI * 2.; - osg::Vec3 normal = sphereCoordToCartesian(theta, osg::PI_2f, 1.); + float theta = float(i) / float(subdiv) * osg::PIf * 2.f; + osg::Vec3 normal = sphereCoordToCartesian(theta, osg::PI_2f, 1.f); auto posTop = normal; posTop *= radius; auto posBot = posTop; - posTop.z() = height / 2.; - posBot.z() = -height / 2.; + posTop.z() = height / 2.f; + posBot.z() = -height / 2.f; vertices->push_back(posTop); normals->push_back(normal); iVertex += 1; @@ -180,10 +179,10 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in for (int i = 0; i < subdiv; i++) { auto nextVert = (i + 1) % subdiv; - auto v1 = (beginSide + 2 * i); - auto v2 = (beginSide + 2 * i + 1); - auto v3 = (beginSide + 2 * nextVert); - auto v4 = (beginSide + 2 * nextVert + 1); + auto v1 = static_cast(beginSide + 2 * i); + auto v2 = static_cast(beginSide + 2 * i + 1); + auto v3 = static_cast(beginSide + 2 * nextVert); + auto v4 = static_cast(beginSide + 2 * nextVert + 1); indices->push_back(v1); indices->push_back(v2); indices->push_back(v4); @@ -195,11 +194,11 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in for (int i = 0; i < subdiv; i++) { auto nextVert = (i + 1) % subdiv; - auto top1 = (beginTop + i); - auto top2 = (beginTop + nextVert); + auto top1 = static_cast(beginTop + i); + auto top2 = static_cast(beginTop + nextVert); - auto bot1 = (beginBot + i); - auto bot2 = (beginBot + nextVert); + auto bot1 = static_cast(beginBot + i); + auto bot2 = static_cast(beginBot + nextVert); indices->push_back(top2); indices->push_back(centerTop); @@ -239,7 +238,7 @@ namespace Debug lines.setVertexArray(vertices); lines.setNormalArray(color, osg::Array::BIND_PER_VERTEX); - lines.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size())); + lines.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, static_cast(vertices->size()))); } DebugCustomDraw::DebugCustomDraw() @@ -395,5 +394,5 @@ void Debug::DebugDrawer::addLine(const osg::Vec3& start, const osg::Vec3& end, c colors->push_back(color); colors->dirty(); - primitive->setCount(vertices->size()); + primitive->setCount(static_cast(vertices->size())); } diff --git a/components/debug/gldebug.cpp b/components/debug/gldebug.cpp index 482755b761..b9bebb675d 100644 --- a/components/debug/gldebug.cpp +++ b/components/debug/gldebug.cpp @@ -273,7 +273,8 @@ namespace Debug void DebugGroup::push(osg::State& state) const { if (isValid()) - PushDebugGroup::sInstance->glPushDebugGroup(mSource, mId, mMessage.size(), mMessage.c_str()); + PushDebugGroup::sInstance->glPushDebugGroup( + mSource, mId, static_cast(mMessage.size()), mMessage.c_str()); } void DebugGroup::pop(osg::State& state) const diff --git a/components/detournavigator/asyncnavmeshupdater.cpp b/components/detournavigator/asyncnavmeshupdater.cpp index 4a4137170a..d7eaafce9a 100644 --- a/components/detournavigator/asyncnavmeshupdater.cpp +++ b/components/detournavigator/asyncnavmeshupdater.cpp @@ -1039,7 +1039,7 @@ namespace DetourNavigator if (const auto& cachedTileData = job->mCachedTileData) { Log(Debug::Debug) << "Update db tile by job " << job->mId; - job->mGeneratedNavMeshData->mUserId = cachedTileData->mTileId; + job->mGeneratedNavMeshData->mUserId = static_cast(cachedTileData->mTileId); mDb->updateTile(cachedTileData->mTileId, mVersion, serialize(*job->mGeneratedNavMeshData)); return; } @@ -1051,7 +1051,7 @@ namespace DetourNavigator return; } - job->mGeneratedNavMeshData->mUserId = mNextTileId; + job->mGeneratedNavMeshData->mUserId = static_cast(mNextTileId); Log(Debug::Debug) << "Insert db tile by job " << job->mId; mDb->insertTile(mNextTileId, job->mWorldspace, job->mChangedTile, mVersion, job->mInput, serialize(*job->mGeneratedNavMeshData)); diff --git a/components/detournavigator/raycast.cpp b/components/detournavigator/raycast.cpp index 7456912c08..431ac731ab 100644 --- a/components/detournavigator/raycast.cpp +++ b/components/detournavigator/raycast.cpp @@ -22,7 +22,7 @@ namespace DetourNavigator std::array path; dtRaycastHit hit; hit.path = path.data(); - hit.maxPath = path.size(); + hit.maxPath = static_cast(path.size()); if (dtStatus status = navMeshQuery.raycast(ref, start.ptr(), end.ptr(), &queryFilter, options, &hit); dtStatusFailed(status) || hit.pathCount == 0) return {}; diff --git a/components/detournavigator/recastmeshbuilder.cpp b/components/detournavigator/recastmeshbuilder.cpp index d443a5e5b2..eb03ee569b 100644 --- a/components/detournavigator/recastmeshbuilder.cpp +++ b/components/detournavigator/recastmeshbuilder.cpp @@ -122,10 +122,10 @@ namespace DetourNavigator triangles.emplace_back(makeRecastMeshTriangle(vertices, AreaType_ground)); }); shape.processAllTriangles(&callback, aabbMin, aabbMax); - const osg::Vec2f aabbShift - = (osg::Vec2f(aabbMax.x(), aabbMax.y()) - osg::Vec2f(aabbMin.x(), aabbMin.y())) * 0.5; + const btVector3 aabbShift = (aabbMax - aabbMin) * 0.5; const osg::Vec2f tileShift = osg::Vec2f(heightfield.mMinX, heightfield.mMinY) * scale; - const osg::Vec2f localShift = aabbShift + tileShift; + const osg::Vec2f localShift + = osg::Vec2f(static_cast(aabbShift.x()), static_cast(aabbShift.y())) + tileShift; const float cellSize = static_cast(heightfield.mCellSize); const osg::Vec3f cellShift(heightfield.mCellPosition.x() * cellSize, heightfield.mCellPosition.y() * cellSize, (heightfield.mMinHeight + heightfield.mMaxHeight) * 0.5f); @@ -238,7 +238,8 @@ namespace DetourNavigator const float stepSize = getHeightfieldScale(cellSize, size); const int halfCellSize = cellSize / 2; const auto local = [&](float v, float offset) { return (v - offset + halfCellSize) / stepSize; }; - const auto index = [&](float v, int add) { return std::clamp(static_cast(v) + add, 0, size); }; + const auto index + = [&](float v, int add) { return std::clamp(static_cast(v) + add, 0, static_cast(size)); }; const std::size_t minX = index(std::round(local(intersection->mMin.x(), shift.x())), -1); const std::size_t minY = index(std::round(local(intersection->mMin.y(), shift.y())), -1); const std::size_t maxX = index(std::round(local(intersection->mMax.x(), shift.x())), 1); diff --git a/components/detournavigator/settingsutils.hpp b/components/detournavigator/settingsutils.hpp index c9d8665d51..8e368ab46e 100644 --- a/components/detournavigator/settingsutils.hpp +++ b/components/detournavigator/settingsutils.hpp @@ -79,8 +79,10 @@ namespace DetourNavigator inline TileBounds makeTileBounds(const RecastSettings& settings, const TilePosition& tilePosition) { return TileBounds{ - osg::Vec2f(tilePosition.x(), tilePosition.y()) * getTileSize(settings), - osg::Vec2f(tilePosition.x() + 1, tilePosition.y() + 1) * getTileSize(settings), + osg::Vec2f(static_cast(tilePosition.x()), static_cast(tilePosition.y())) + * getTileSize(settings), + osg::Vec2f(static_cast(tilePosition.x() + 1), static_cast(tilePosition.y() + 1)) + * getTileSize(settings), }; } @@ -97,7 +99,7 @@ namespace DetourNavigator inline float getMaxNavmeshAreaRadius(const Settings& settings) { - return std::floor(std::sqrt(settings.mMaxTilesNumber / osg::PI)) - 1; + return std::floor(std::sqrt(settings.mMaxTilesNumber / osg::PIf)) - 1; } // Returns tile bounds in real coordinates diff --git a/components/detournavigator/tilebounds.hpp b/components/detournavigator/tilebounds.hpp index 62304c1d21..8364f433e6 100644 --- a/components/detournavigator/tilebounds.hpp +++ b/components/detournavigator/tilebounds.hpp @@ -56,8 +56,10 @@ namespace DetourNavigator inline TileBounds maxCellTileBounds(const osg::Vec2i& position, int size) { - return TileBounds{ osg::Vec2f(static_cast(position.x()), static_cast(position.y())) * static_cast(size), - osg::Vec2f(static_cast(position.x() + 1), static_cast(position.y() + 1)) * static_cast(size) }; + return TileBounds{ osg::Vec2f(static_cast(position.x()), static_cast(position.y())) + * static_cast(size), + osg::Vec2f(static_cast(position.x() + 1), static_cast(position.y() + 1)) + * static_cast(size) }; } inline TileBounds makeObjectTileBounds(const btCollisionShape& shape, const btTransform& transform) diff --git a/components/esm3/aisequence.cpp b/components/esm3/aisequence.cpp index c316c2db86..ba28ca3e92 100644 --- a/components/esm3/aisequence.cpp +++ b/components/esm3/aisequence.cpp @@ -84,7 +84,7 @@ namespace ESM // The exact value of mDuration only matters for repeating packages. // Previously mRemainingDuration could be negative even when mDuration was 0. Checking for > 0 should // fix old saves. - mData.mDuration = std::max(mRemainingDuration > 0, mRemainingDuration); + mData.mDuration = static_cast(std::max(mRemainingDuration > 0, mRemainingDuration)); } } @@ -121,7 +121,7 @@ namespace ESM // The exact value of mDuration only matters for repeating packages. // Previously mRemainingDuration could be negative even when mDuration was 0. Checking for > 0 should // fix old saves. - mData.mDuration = std::max(mRemainingDuration > 0, mRemainingDuration); + mData.mDuration = static_cast(std::max(mRemainingDuration > 0, mRemainingDuration)); } } diff --git a/components/esm3/loadmgef.cpp b/components/esm3/loadmgef.cpp index 1d3102e4a1..fd75d071cb 100644 --- a/components/esm3/loadmgef.cpp +++ b/components/esm3/loadmgef.cpp @@ -145,7 +145,8 @@ namespace ESM effects[i] = MagicEffect::Effects::ResistMagicka; for (short i = MagicEffect::Effects::AbsorbAttribute; i <= MagicEffect::Effects::AbsorbSkill; ++i) effects[i] = MagicEffect::Effects::ResistMagicka; - for (short i = MagicEffect::Effects::WeaknessToFire; i <= MagicEffect::Effects::WeaknessToNormalWeapons; ++i) + for (short i = MagicEffect::Effects::WeaknessToFire; i <= MagicEffect::Effects::WeaknessToNormalWeapons; + ++i) effects[i] = MagicEffect::Effects::ResistMagicka; effects[MagicEffect::Effects::Burden] = MagicEffect::Effects::ResistMagicka; @@ -541,7 +542,7 @@ namespace ESM { std::map map; for (size_t i = 0; i < strings.size(); i++) - map[strings[i]] = i; + map[strings[i]] = static_cast(i); return map; } diff --git a/components/fontloader/fontloader.cpp b/components/fontloader/fontloader.cpp index 14a3baa2e9..34a6514e6a 100644 --- a/components/fontloader/fontloader.cpp +++ b/components/fontloader/fontloader.cpp @@ -591,7 +591,7 @@ namespace Gui // Underscore, use for NotDefined marker (used for glyphs not existing in the font) additional.emplace(95, MyGUI::FontCodeType::NotDefined); - for (int i = 0; i < 256; i++) + for (unsigned char i = 0; i < 256; i++) { float x1 = data[i].top_left.x * width; float y1 = data[i].top_left.y * height; diff --git a/components/fx/types.hpp b/components/fx/types.hpp index bdb46a76c1..a61e5dbeb7 100644 --- a/components/fx/types.hpp +++ b/components/fx/types.hpp @@ -29,12 +29,12 @@ namespace Fx int scaledHeight = height; if (mWidthRatio) - scaledWidth = width * mWidthRatio.value(); + scaledWidth = static_cast(width * mWidthRatio.value()); else if (mWidth) scaledWidth = mWidth.value(); if (mHeightRatio > 0.f) - scaledHeight = height * mHeightRatio.value(); + scaledHeight = static_cast(height * mHeightRatio.value()); else if (mHeight) scaledHeight = mHeight.value(); @@ -190,7 +190,7 @@ namespace Fx if (arg.isArray()) { for (size_t i = 0; i < arg.getArray().size(); ++i) - uniform->setElement(i, arg.getArray()[i]); + uniform->setElement(static_cast(i), arg.getArray()[i]); uniform->dirty(); } else diff --git a/components/lua/scriptscontainer.cpp b/components/lua/scriptscontainer.cpp index f5b5605e37..538ed48929 100644 --- a/components/lua/scriptscontainer.cpp +++ b/components/lua/scriptscontainer.cpp @@ -334,8 +334,8 @@ namespace LuaUtil void ScriptsContainer::insertHandler(std::vector& list, int scriptId, sol::function fn) { + size_t pos = list.size(); list.emplace_back(); - int pos = list.size() - 1; while (pos > 0 && list[pos - 1].mScriptId > scriptId) { list[pos] = std::move(list[pos - 1]); @@ -370,9 +370,9 @@ namespace LuaUtil return; } EventHandlerList& list = it->second; - for (int i = list.size() - 1; i >= 0; --i) + for (size_t i = list.size(); i > 0; --i) { - const Handler& h = list[i]; + const Handler& h = list[i - 1]; try { sol::object res = LuaUtil::call({ this, h.mScriptId }, h.mFn, object); diff --git a/components/lua_ui/image.cpp b/components/lua_ui/image.cpp index 45e7843d61..f73f722699 100644 --- a/components/lua_ui/image.cpp +++ b/components/lua_ui/image.cpp @@ -20,9 +20,9 @@ namespace LuaUi // mCoord could be zero, prevent division by 0 // use arbitrary large numbers to prevent performance issues if (mTileSize.width <= 0) - mTileSize.width = 1e7; + mTileSize.width = 10000000; if (mTileSize.height <= 0) - mTileSize.height = 1e7; + mTileSize.height = 10000000; MyGUI::TileRect::_updateView(); } diff --git a/components/lua_ui/layers.hpp b/components/lua_ui/layers.hpp index 50fab79d6a..a5b09df4cf 100644 --- a/components/lua_ui/layers.hpp +++ b/components/lua_ui/layers.hpp @@ -26,7 +26,7 @@ namespace LuaUi { MyGUI::ILayer* p = refresh(); MyGUI::IntSize size = p->getSize(); - return osg::Vec2f(size.width, size.height); + return osg::Vec2f(static_cast(size.width), static_cast(size.height)); } struct Options diff --git a/components/lua_ui/properties.hpp b/components/lua_ui/properties.hpp index 81fb272f17..f6e81f7200 100644 --- a/components/lua_ui/properties.hpp +++ b/components/lua_ui/properties.hpp @@ -11,11 +11,16 @@ namespace LuaUi { + template + constexpr bool isMyGuiIntVector() + { + return std::is_same() || std::is_same(); + } + template constexpr bool isMyGuiVector() { - return std::is_same() || std::is_same() - || std::is_same() || std::is_same(); + return isMyGuiIntVector() || std::is_same() || std::is_same(); } template @@ -42,7 +47,9 @@ namespace LuaUi return sol::nullopt; LuaT luaT = opt.as(); - if constexpr (isMyGuiVector()) + if constexpr (isMyGuiIntVector()) + return T(static_cast(luaT.x()), static_cast(luaT.y())); + else if constexpr (isMyGuiVector()) return T(luaT.x(), luaT.y()); else if constexpr (isMyGuiColor()) return T(luaT.r(), luaT.g(), luaT.b(), luaT.a()); diff --git a/components/lua_ui/widget.cpp b/components/lua_ui/widget.cpp index a126fd9f7b..e910be0711 100644 --- a/components/lua_ui/widget.cpp +++ b/components/lua_ui/widget.cpp @@ -179,16 +179,17 @@ namespace LuaUi auto keySym = SDL_Keysym(); keySym.sym = SDLUtil::myGuiKeyToSdl(code); keySym.scancode = SDL_GetScancodeFromKey(keySym.sym); - keySym.mod = SDL_GetModState(); + keySym.mod = static_cast(SDL_GetModState()); return sol::make_object(lua(), keySym); } sol::object WidgetExtension::mouseEvent( int left, int top, MyGUI::MouseButton button = MyGUI::MouseButton::None) const { - osg::Vec2f position(left, top); + osg::Vec2f position(static_cast(left), static_cast(top)); MyGUI::IntPoint absolutePosition = mWidget->getAbsolutePosition(); - osg::Vec2f offset = position - osg::Vec2f(absolutePosition.left, absolutePosition.top); + osg::Vec2f offset = position + - osg::Vec2f(static_cast(absolutePosition.left), static_cast(absolutePosition.top)); sol::table table = makeTable(); int sdlButton = SDLUtil::myGuiMouseButtonToSdl(button); table["position"] = position; @@ -328,8 +329,8 @@ namespace LuaUi MyGUI::IntSize pSize = parentSize(); MyGUI::IntSize newSize; newSize = mAbsoluteCoord.size(); - newSize.width += mRelativeCoord.width * pSize.width; - newSize.height += mRelativeCoord.height * pSize.height; + newSize.width += static_cast(mRelativeCoord.width * pSize.width); + newSize.height += static_cast(mRelativeCoord.height * pSize.height); return newSize; } @@ -340,8 +341,8 @@ namespace LuaUi MyGUI::IntSize pSize = parentSize(); MyGUI::IntPoint newPosition; newPosition = mAbsoluteCoord.point(); - newPosition.left += mRelativeCoord.left * pSize.width - mAnchor.width * size.width; - newPosition.top += mRelativeCoord.top * pSize.height - mAnchor.height * size.height; + newPosition.left += static_cast(mRelativeCoord.left * pSize.width - mAnchor.width * size.width); + newPosition.top += static_cast(mRelativeCoord.top * pSize.height - mAnchor.height * size.height); return newPosition; } diff --git a/components/lua_ui/window.cpp b/components/lua_ui/window.cpp index a06da14972..3331dd47b1 100644 --- a/components/lua_ui/window.cpp +++ b/components/lua_ui/window.cpp @@ -79,8 +79,8 @@ namespace LuaUi mPreviousMouse.top = top; sol::table table = makeTable(); - table["position"] = osg::Vec2f(mCoord.left, mCoord.top); - table["size"] = osg::Vec2f(mCoord.width, mCoord.height); + table["position"] = osg::Vec2f(static_cast(mCoord.left), static_cast(mCoord.top)); + table["size"] = osg::Vec2f(static_cast(mCoord.width), static_cast(mCoord.height)); triggerEvent("windowDrag", table); } } diff --git a/components/myguiplatform/myguirendermanager.cpp b/components/myguiplatform/myguirendermanager.cpp index 85afcde462..67781554d8 100644 --- a/components/myguiplatform/myguirendermanager.cpp +++ b/components/myguiplatform/myguirendermanager.cpp @@ -141,7 +141,7 @@ namespace MyGUIPlatform reinterpret_cast(vbo->getArray(0)->getDataPointer()) + 16); } - glDrawArrays(GL_TRIANGLES, 0, batch.mVertexCount); + glDrawArrays(GL_TRIANGLES, 0, static_cast(batch.mVertexCount)); if (batch.mStateSet) { @@ -328,7 +328,8 @@ namespace MyGUIPlatform osg::UByteArray* OSGVertexBuffer::create() { - mVertexArray[mCurrentBuffer] = new osg::UByteArray(mNeedVertexCount * sizeof(MyGUI::Vertex)); + mVertexArray[mCurrentBuffer] + = new osg::UByteArray(static_cast(mNeedVertexCount * sizeof(MyGUI::Vertex))); mBuffer[mCurrentBuffer] = new osg::VertexBufferObject; mBuffer[mCurrentBuffer]->setDataVariance(osg::Object::DYNAMIC); @@ -404,7 +405,7 @@ namespace MyGUIPlatform mSceneRoot->addChild(mGuiRoot.get()); osg::ref_ptr vp = mViewer->getCamera()->getViewport(); - setViewSize(vp->width(), vp->height()); + setViewSize(static_cast(vp->width()), static_cast(vp->height())); MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized"); mIsInitialise = true; @@ -500,7 +501,7 @@ namespace MyGUIPlatform mGuiRoot->setViewport(0, 0, width, height); - mViewSize.set(width * mInvScalingFactor, height * mInvScalingFactor); + mViewSize.set(static_cast(width * mInvScalingFactor), static_cast(height * mInvScalingFactor)); mInfo.maximumDepth = 1; mInfo.hOffset = 0; diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index 02b110a5a6..02233a2b3c 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -699,7 +699,7 @@ namespace Nif assert(r != nullptr); assert(r->recType != RC_MISSING); r->recName = std::move(rec); - r->recIndex = i; + r->recIndex = static_cast(i); r->read(&nif); mRecords[i] = std::move(r); } diff --git a/components/nif/node.cpp b/components/nif/node.cpp index c2655a3e9c..7dba288164 100644 --- a/components/nif/node.cpp +++ b/components/nif/node.cpp @@ -664,13 +664,13 @@ namespace Nif mDynamicVertexSize = (data & 0xF0) >> 0x04; mUV1Offset = (data & 0xF00) >> 0x08; mUV2Offset = (data & 0xF000) >> 0x0C; - mNormalOffset = (data & 0xF0000) >> 0x10; - mTangentOffset = (data & 0xF00000) >> 0x14; + mNormalOffset = static_cast((data & 0xF0000) >> 0x10); + mTangentOffset = static_cast((data & 0xF00000) >> 0x14); mColorOffset = (data & 0xF000000) >> 0x18; mSkinningDataOffset = (data & 0xF0000000) >> 0x1C; - mLandscapeDataOffset = (data & 0xF00000000) >> 0x20; - mEyeDataOffset = (data & 0xF000000000) >> 0x24; - mFlags = (data & 0xFFF00000000000) >> 0x2C; + mLandscapeDataOffset = static_cast((data & 0xF00000000) >> 0x20); + mEyeDataOffset = static_cast((data & 0xF000000000) >> 0x24); + mFlags = static_cast((data & 0xFFF00000000000) >> 0x2C); if (nif->getBethVersion() == NIFFile::BethVersion::BETHVER_SSE) mFlags |= BSVertexDesc::VertexAttribute::Full_Precision; } diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 23fb9f7439..f36dc9e6ce 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -165,7 +165,7 @@ namespace osg::Matrix modelView = *cv->getModelViewMatrix(); // attempt to preserve scale - float mag[3]; + double mag[3]; for (int i = 0; i < 3; ++i) { mag[i] = std::sqrt(modelView(0, i) * modelView(0, i) + modelView(1, i) * modelView(1, i) @@ -1083,7 +1083,7 @@ namespace NifOsg texture2d->setTextureSize(image->s(), image->t()); texture2d->setWrap(osg::Texture::WRAP_S, wrapS ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE); texture2d->setWrap(osg::Texture::WRAP_T, wrapT ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE); - unsigned int texUnit = boundTextures.size(); + auto texUnit = static_cast(boundTextures.size()); if (stateset) { stateset->setTextureAttributeAndModes(texUnit, texture2d, osg::StateAttribute::ON); @@ -1244,12 +1244,12 @@ namespace NifOsg auto particleNode = static_cast(nifNode); if (particleNode->mData.empty()) { - partsys->setQuota(partctrl->mParticles.size()); + partsys->setQuota(static_cast(partctrl->mParticles.size())); return; } auto particledata = static_cast(particleNode->mData.getPtr()); - partsys->setQuota(particledata->mNumParticles); + partsys->setQuota(static_cast(particledata->mNumParticles)); osg::BoundingBox box; @@ -1342,7 +1342,7 @@ namespace NifOsg { for (const auto& emitterPair : mEmitterQueue) { - size_t recIndex = emitterPair.first; + auto recIndex = static_cast(emitterPair.first); FindGroupByRecIndex findEmitterNode(recIndex); rootNode->accept(findEmitterNode); osg::Group* emitterNode = findEmitterNode.mFound; @@ -1488,15 +1488,15 @@ namespace NifOsg const std::vector& trueTriangles = partition.mTrueTriangles; if (!trueTriangles.empty()) { - geometry->addPrimitiveSet(new osg::DrawElementsUShort( - osg::PrimitiveSet::TRIANGLES, trueTriangles.size(), trueTriangles.data())); + geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, + static_cast(trueTriangles.size()), trueTriangles.data())); } for (const auto& strip : partition.mTrueStrips) { if (strip.size() < 3) continue; geometry->addPrimitiveSet(new osg::DrawElementsUShort( - osg::PrimitiveSet::TRIANGLE_STRIP, strip.size(), strip.data())); + osg::PrimitiveSet::TRIANGLE_STRIP, static_cast(strip.size()), strip.data())); } } } @@ -1511,8 +1511,8 @@ namespace NifOsg const std::vector& triangles = data->mTriangles; if (triangles.empty()) return; - geometry->addPrimitiveSet( - new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, triangles.size(), triangles.data())); + geometry->addPrimitiveSet(new osg::DrawElementsUShort( + osg::PrimitiveSet::TRIANGLES, static_cast(triangles.size()), triangles.data())); } else if (niGeometry->recType == Nif::RC_NiTriStrips) { @@ -1522,8 +1522,8 @@ namespace NifOsg { if (strip.size() < 3) continue; - geometry->addPrimitiveSet( - new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP, strip.size(), strip.data())); + geometry->addPrimitiveSet(new osg::DrawElementsUShort( + osg::PrimitiveSet::TRIANGLE_STRIP, static_cast(strip.size()), strip.data())); hasGeometry = true; } if (!hasGeometry) @@ -1535,8 +1535,8 @@ namespace NifOsg const auto& line = data->mLines; if (line.empty()) return; - geometry->addPrimitiveSet( - new osg::DrawElementsUShort(osg::PrimitiveSet::LINES, line.size(), line.data())); + geometry->addPrimitiveSet(new osg::DrawElementsUShort( + osg::PrimitiveSet::LINES, static_cast(line.size()), line.data())); } } @@ -1544,17 +1544,18 @@ namespace NifOsg const auto& normals = niGeometryData->mNormals; const auto& colors = niGeometryData->mColors; if (!vertices.empty()) - geometry->setVertexArray(new osg::Vec3Array(vertices.size(), vertices.data())); + geometry->setVertexArray(new osg::Vec3Array(static_cast(vertices.size()), vertices.data())); if (!normals.empty()) - geometry->setNormalArray( - new osg::Vec3Array(normals.size(), normals.data()), osg::Array::BIND_PER_VERTEX); + geometry->setNormalArray(new osg::Vec3Array(static_cast(normals.size()), normals.data()), + osg::Array::BIND_PER_VERTEX); if (!colors.empty()) - geometry->setColorArray(new osg::Vec4Array(colors.size(), colors.data()), osg::Array::BIND_PER_VERTEX); + geometry->setColorArray(new osg::Vec4Array(static_cast(colors.size()), colors.data()), + osg::Array::BIND_PER_VERTEX); const auto& uvlist = niGeometryData->mUVList; int textureStage = 0; for (std::vector::const_iterator it = boundTextures.begin(); it != boundTextures.end(); - ++it, ++textureStage) + ++it, ++textureStage) { unsigned int uvSet = *it; if (uvSet >= uvlist.size()) @@ -1566,7 +1567,8 @@ namespace NifOsg uvSet = 0; } - geometry->setTexCoordArray(textureStage, new osg::Vec2Array(uvlist[uvSet].size(), uvlist[uvSet].data()), + geometry->setTexCoordArray(textureStage, + new osg::Vec2Array(static_cast(uvlist[uvSet].size()), uvlist[uvSet].data()), osg::Array::BIND_PER_VERTEX); } @@ -1650,8 +1652,9 @@ namespace NifOsg osg::ref_ptr morphGeom = new SceneUtil::MorphGeometry; morphGeom->setSourceGeometry(geom); for (unsigned int i = 0; i < morphs.size(); ++i) - morphGeom->addMorphTarget( - new osg::Vec3Array(morphs[i].mVertices.size(), morphs[i].mVertices.data()), 0.f); + morphGeom->addMorphTarget(new osg::Vec3Array(static_cast(morphs[i].mVertices.size()), + morphs[i].mVertices.data()), + 0.f); osg::ref_ptr morphctrl = new GeomMorpherController(nimorphctrl); setupController(ctrl.getPtr(), morphctrl, animflags); @@ -1678,8 +1681,8 @@ namespace NifOsg return; osg::ref_ptr geometry(new osg::Geometry); - geometry->addPrimitiveSet( - new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, triangles.size(), triangles.data())); + geometry->addPrimitiveSet(new osg::DrawElementsUShort( + osg::PrimitiveSet::TRIANGLES, static_cast(triangles.size()), triangles.data())); osg::ref_ptr drawable = geometry; @@ -1743,16 +1746,16 @@ namespace NifOsg } if (!vertices.empty()) - geometry->setVertexArray(new osg::Vec3Array(vertices.size(), vertices.data())); + geometry->setVertexArray(new osg::Vec3Array(static_cast(vertices.size()), vertices.data())); if (!normals.empty()) - geometry->setNormalArray( - new osg::Vec3Array(normals.size(), normals.data()), osg::Array::BIND_PER_VERTEX); + geometry->setNormalArray(new osg::Vec3Array(static_cast(normals.size()), normals.data()), + osg::Array::BIND_PER_VERTEX); if (!colors.empty()) - geometry->setColorArray( - new osg::Vec4ubArray(colors.size(), colors.data()), osg::Array::BIND_PER_VERTEX); + geometry->setColorArray(new osg::Vec4ubArray(static_cast(colors.size()), colors.data()), + osg::Array::BIND_PER_VERTEX); if (!uvlist.empty()) - geometry->setTexCoordArray( - 0, new osg::Vec2Array(uvlist.size(), uvlist.data()), osg::Array::BIND_PER_VERTEX); + geometry->setTexCoordArray(0, new osg::Vec2Array(static_cast(uvlist.size()), uvlist.data()), + osg::Array::BIND_PER_VERTEX); // This is the skinning data Fallout 4 provides // TODO: support Skyrim SE skinning data @@ -2124,7 +2127,7 @@ namespace NifOsg } } - const unsigned int texUnit = boundTextures.size(); + const auto texUnit = static_cast(boundTextures.size()); if (tex.mEnabled) { if (tex.mSourceTexture.empty() && texprop->mController.empty()) @@ -2632,7 +2635,7 @@ namespace NifOsg if (!texprop->mSourceTexture.empty()) { const unsigned int uvSet = 0; - unsigned int texUnit = boundTextures.size(); + unsigned int texUnit = static_cast(boundTextures.size()); attachExternalTexture("diffuseMap", texprop->mSourceTexture, texprop->wrapS(), texprop->wrapT(), uvSet, stateset, boundTextures); { diff --git a/components/nifosg/particle.cpp b/components/nifosg/particle.cpp index 21fd280812..a554c986de 100644 --- a/components/nifosg/particle.cpp +++ b/components/nifosg/particle.cpp @@ -487,7 +487,8 @@ namespace NifOsg } else { - int randomIndex = static_cast(std::floor(Misc::Rng::rollClosedProbability() * (mTargets.size() - 1))); + int randomIndex + = static_cast(std::floor(Misc::Rng::rollClosedProbability() * (mTargets.size() - 1))); recIndex = mTargets[randomIndex]; } diff --git a/components/resource/bulletshapemanager.cpp b/components/resource/bulletshapemanager.cpp index d8594f9a99..58ef3252ea 100644 --- a/components/resource/bulletshapemanager.cpp +++ b/components/resource/bulletshapemanager.cpp @@ -86,8 +86,8 @@ namespace Resource shape->mCollisionBox.mExtents[0] = static_cast(aabbMax[0] - aabbMin[0]) / 2.0f; shape->mCollisionBox.mExtents[1] = static_cast(aabbMax[1] - aabbMin[1]) / 2.0f; shape->mCollisionBox.mExtents[2] = static_cast(aabbMax[2] - aabbMin[2]) / 2.0f; - shape->mCollisionBox.mCenter = osg::Vec3f( - static_cast(aabbMax[0] + aabbMin[0]) / 2.0f, static_cast(aabbMax[1] + aabbMin[1]) / 2.0f, static_cast(aabbMax[2] + aabbMin[2]) / 2.0f); + shape->mCollisionBox.mCenter = osg::Vec3f(static_cast(aabbMax[0] + aabbMin[0]) / 2.0f, + static_cast(aabbMax[1] + aabbMin[1]) / 2.0f, static_cast(aabbMax[2] + aabbMin[2]) / 2.0f); shape->mCollisionShape.reset(triangleMeshShape.release()); return shape; diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index 84ba08c0b3..d309174fcf 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -141,9 +141,9 @@ namespace Resource class SharedStateManager : public osgDB::SharedStateManager { public: - unsigned int getNumSharedTextures() const { return _sharedTextureList.size(); } + size_t getNumSharedTextures() const { return _sharedTextureList.size(); } - unsigned int getNumSharedStateSets() const { return _sharedStateSetList.size(); } + size_t getNumSharedStateSets() const { return _sharedStateSetList.size(); } void clearCache() { @@ -158,7 +158,7 @@ namespace Resource { public: SetFilterSettingsControllerVisitor( - osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, int maxAnisotropy) + osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, float maxAnisotropy) : mMinFilter(minFilter) , mMagFilter(magFilter) , mMaxAnisotropy(maxAnisotropy) @@ -170,7 +170,7 @@ namespace Resource if (NifOsg::FlipController* flipctrl = dynamic_cast(&ctrl)) { for (std::vector>::iterator it = flipctrl->getTextures().begin(); - it != flipctrl->getTextures().end(); ++it) + it != flipctrl->getTextures().end(); ++it) { osg::Texture* tex = *it; tex->setFilter(osg::Texture::MIN_FILTER, mMinFilter); @@ -183,7 +183,7 @@ namespace Resource private: osg::Texture::FilterMode mMinFilter; osg::Texture::FilterMode mMagFilter; - int mMaxAnisotropy; + float mMaxAnisotropy; }; /// Set texture filtering settings on textures contained in StateSets. @@ -191,7 +191,7 @@ namespace Resource { public: SetFilterSettingsVisitor( - osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, int maxAnisotropy) + osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, float maxAnisotropy) : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) , mMinFilter(minFilter) , mMagFilter(magFilter) @@ -233,7 +233,7 @@ namespace Resource private: osg::Texture::FilterMode mMinFilter; osg::Texture::FilterMode mMagFilter; - int mMaxAnisotropy; + float mMaxAnisotropy; }; // Check Collada extra descriptions @@ -461,7 +461,7 @@ namespace Resource , mBgsmFileManager(bgsmFileManager) , mMinFilter(osg::Texture::LINEAR_MIPMAP_LINEAR) , mMagFilter(osg::Texture::LINEAR) - , mMaxAnisotropy(1) + , mMaxAnisotropy(1.f) , mUnRefImageDataAfterApply(false) , mParticleSystemMask(~0u) { @@ -1129,7 +1129,7 @@ namespace Resource } void SceneManager::setFilterSettings( - const std::string& magfilter, const std::string& minfilter, const std::string& mipmap, int maxAnisotropy) + const std::string& magfilter, const std::string& minfilter, const std::string& mipmap, float maxAnisotropy) { osg::Texture::FilterMode min = osg::Texture::LINEAR; osg::Texture::FilterMode mag = osg::Texture::LINEAR; @@ -1163,7 +1163,7 @@ namespace Resource mMinFilter = min; mMagFilter = mag; - mMaxAnisotropy = std::max(1, maxAnisotropy); + mMaxAnisotropy = std::max(1.f, maxAnisotropy); SetFilterSettingsControllerVisitor setFilterSettingsControllerVisitor(mMinFilter, mMagFilter, mMaxAnisotropy); SetFilterSettingsVisitor setFilterSettingsVisitor(mMinFilter, mMagFilter, mMaxAnisotropy); @@ -1225,13 +1225,16 @@ namespace Resource if (mIncrementalCompileOperation) { std::lock_guard lock(*mIncrementalCompileOperation->getToCompiledMutex()); - stats->setAttribute(frameNumber, "Compiling", mIncrementalCompileOperation->getToCompile().size()); + stats->setAttribute( + frameNumber, "Compiling", static_cast(mIncrementalCompileOperation->getToCompile().size())); } { std::lock_guard lock(mSharedStateMutex); - stats->setAttribute(frameNumber, "Texture", mSharedStateManager->getNumSharedTextures()); - stats->setAttribute(frameNumber, "StateSet", mSharedStateManager->getNumSharedStateSets()); + stats->setAttribute( + frameNumber, "Texture", static_cast(mSharedStateManager->getNumSharedTextures())); + stats->setAttribute( + frameNumber, "StateSet", static_cast(mSharedStateManager->getNumSharedStateSets())); } Resource::reportStats("Node", frameNumber, mCache->getStats(), *stats); diff --git a/components/resource/scenemanager.hpp b/components/resource/scenemanager.hpp index 370383975d..d0769b2b02 100644 --- a/components/resource/scenemanager.hpp +++ b/components/resource/scenemanager.hpp @@ -207,7 +207,7 @@ namespace Resource /// @warning It is unsafe to call this method while the draw thread is using textures! call /// Viewer::stopThreading first. void setFilterSettings( - const std::string& magfilter, const std::string& minfilter, const std::string& mipmap, int maxAnisotropy); + const std::string& magfilter, const std::string& minfilter, const std::string& mipmap, float maxAnisotropy); /// Apply filter settings to the given texture. Note, when loading an object through this scene manager (i.e. /// calling getTemplate or createInstance) the filter settings are applied automatically. This method is @@ -263,7 +263,7 @@ namespace Resource osg::Texture::FilterMode mMinFilter; osg::Texture::FilterMode mMagFilter; - int mMaxAnisotropy; + float mMaxAnisotropy; bool mUnRefImageDataAfterApply; osg::ref_ptr mIncrementalCompileOperation; diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index 26532f3f6e..86482350e9 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -314,7 +314,7 @@ namespace SceneUtil bool getModeUsage(ModeUsage& usage) const override { - usage.usesMode(GL_LIGHT0 + mIndex); + usage.usesMode(static_cast(GL_LIGHT0 + mIndex)); return true; } @@ -325,7 +325,7 @@ namespace SceneUtil void apply(osg::State& state) const override { - int lightNum = GL_LIGHT0 + mIndex; + GLenum lightNum = static_cast(GL_LIGHT0 + mIndex); glLightfv(lightNum, GL_AMBIENT, mNullptr.ptr()); glLightfv(lightNum, GL_DIFFUSE, mNullptr.ptr()); glLightfv(lightNum, GL_SPECULAR, mNullptr.ptr()); @@ -365,7 +365,7 @@ namespace SceneUtil bool getModeUsage(ModeUsage& usage) const override { for (size_t i = 0; i < mLights.size(); ++i) - usage.usesMode(GL_LIGHT0 + static_cast(mIndex) + i); + usage.usesMode(static_cast(GL_LIGHT0 + mIndex + i)); return true; } @@ -424,7 +424,7 @@ namespace SceneUtil { LightManager* mLightManager; - virtual ~StateSetGenerator() {} + virtual ~StateSetGenerator() = default; virtual osg::ref_ptr generate(const LightManager::LightList& lightList, size_t frameNum) = 0; @@ -451,7 +451,8 @@ namespace SceneUtil new FFPLightStateAttribute(mLightManager->getStartLight(), std::move(lights)), osg::StateAttribute::ON); for (size_t i = 0; i < lightList.size(); ++i) - stateset->setMode(GL_LIGHT0 + mLightManager->getStartLight() + static_cast(i), osg::StateAttribute::ON); + stateset->setMode( + GL_LIGHT0 + mLightManager->getStartLight() + static_cast(i), osg::StateAttribute::ON); // need to push some dummy attributes to ensure proper state tracking // lights need to reset to their default when the StateSet is popped @@ -774,7 +775,8 @@ namespace SceneUtil int stride = -1; ext->glGetActiveUniformBlockiv(handle, 0, GL_UNIFORM_BLOCK_DATA_SIZE, &totalBlockSize); - ext->glGetActiveUniformsiv(handle, static_cast(index.size()), index.data(), GL_UNIFORM_ARRAY_STRIDE, &stride); + ext->glGetActiveUniformsiv( + handle, static_cast(index.size()), index.data(), GL_UNIFORM_ARRAY_STRIDE, &stride); std::array names = { "LightBuffer[0].packedColors", @@ -785,7 +787,8 @@ namespace SceneUtil std::vector offsets(names.size()); ext->glGetUniformIndices(handle, static_cast(names.size()), names.data(), indices.data()); - ext->glGetActiveUniformsiv(handle, static_cast(indices.size()), indices.data(), GL_UNIFORM_OFFSET, offsets.data()); + ext->glGetActiveUniformsiv( + handle, static_cast(indices.size()), indices.data(), GL_UNIFORM_OFFSET, offsets.data()); mTemplate->configureLayout(offsets[0], offsets[1], offsets[2], totalBlockSize, stride); } @@ -1291,7 +1294,7 @@ namespace SceneUtil const osg::Transform* transform = node->asTransform(); if (transform) { - for (size_t i = 0; i < transform->getNumChildren(); ++i) + for (unsigned int i = 0; i < transform->getNumChildren(); ++i) nodeBound.expandBy(transform->getChild(i)->getBound()); } else diff --git a/components/sceneutil/mwshadowtechnique.cpp b/components/sceneutil/mwshadowtechnique.cpp index 053650a4e3..fa0269776c 100644 --- a/components/sceneutil/mwshadowtechnique.cpp +++ b/components/sceneutil/mwshadowtechnique.cpp @@ -3344,7 +3344,7 @@ void SceneUtil::MWShadowTechnique::DebugHUD::addAnotherShadowMap() size_t shadowMapNumber = mDebugCameras.size(); mDebugCameras.push_back(new osg::Camera); - mDebugCameras[shadowMapNumber]->setViewport(200 * shadowMapNumber, 0, 200, 200); + mDebugCameras[shadowMapNumber]->setViewport(static_cast(200 * shadowMapNumber), 0, 200, 200); mDebugCameras[shadowMapNumber]->setRenderOrder(osg::Camera::POST_RENDER); mDebugCameras[shadowMapNumber]->setClearColor(osg::Vec4(1.0, 1.0, 0.0, 1.0)); mDebugCameras[shadowMapNumber]->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); diff --git a/components/sceneutil/pathgridutil.cpp b/components/sceneutil/pathgridutil.cpp index 5891783d3b..013e45998d 100644 --- a/components/sceneutil/pathgridutil.cpp +++ b/components/sceneutil/pathgridutil.cpp @@ -52,14 +52,17 @@ namespace SceneUtil assert(edgeIndexCount < std::numeric_limits::max()); osg::ref_ptr vertices = new osg::Vec3Array(static_cast(vertexCount)); osg::ref_ptr colors = new osg::Vec4Array(static_cast(vertexCount)); - osg::ref_ptr pointIndices = new PType(osg::PrimitiveSet::TRIANGLES, static_cast(pointIndexCount)); - osg::ref_ptr lineIndices = new LType(osg::PrimitiveSet::LINES, static_cast(edgeIndexCount)); + osg::ref_ptr pointIndices + = new PType(osg::PrimitiveSet::TRIANGLES, static_cast(pointIndexCount)); + osg::ref_ptr lineIndices + = new LType(osg::PrimitiveSet::LINES, static_cast(edgeIndexCount)); // Add each point/node for (size_t pointIndex = 0; pointIndex < pathgrid.mPoints.size(); ++pointIndex) { const ESM::Pathgrid::Point& point = pathgrid.mPoints[pointIndex]; - osg::Vec3f position = osg::Vec3f(static_cast(point.mX), static_cast(point.mY), static_cast(point.mZ)); + osg::Vec3f position = osg::Vec3f( + static_cast(point.mX), static_cast(point.mY), static_cast(point.mZ)); size_t vertexOffset = pointIndex * DiamondTotalVertexCount; size_t indexOffset = pointIndex * DiamondIndexCount; @@ -73,7 +76,8 @@ namespace SceneUtil for (unsigned short i = 0; i < DiamondIndexCount; ++i) { - pointIndices->setElement(static_cast(indexOffset + i), static_cast(vertexOffset + DiamondIndices[i])); + pointIndices->setElement(static_cast(indexOffset + i), + static_cast(vertexOffset + DiamondIndices[i])); } // Connectors @@ -96,8 +100,10 @@ namespace SceneUtil const ESM::Pathgrid::Point& from = pathgrid.mPoints[edge.mV0]; const ESM::Pathgrid::Point& to = pathgrid.mPoints[edge.mV1]; - osg::Vec3f fromPos = osg::Vec3f(static_cast(from.mX), static_cast(from.mY), static_cast(from.mZ)); - osg::Vec3f toPos = osg::Vec3f(static_cast(to.mX), static_cast(to.mY), static_cast(to.mZ)); + osg::Vec3f fromPos + = osg::Vec3f(static_cast(from.mX), static_cast(from.mY), static_cast(from.mZ)); + osg::Vec3f toPos + = osg::Vec3f(static_cast(to.mX), static_cast(to.mY), static_cast(to.mZ)); osg::Vec3f dir = toPos - fromPos; dir.normalize(); @@ -153,7 +159,9 @@ namespace SceneUtil for (size_t it = 0; it < selected.size(); ++it) { const ESM::Pathgrid::Point& point = pathgrid.mPoints[selected[it]]; - osg::Vec3f position = osg::Vec3f(static_cast(point.mX), static_cast(point.mY), static_cast(point.mZ)) + wireOffset; + osg::Vec3f position = osg::Vec3f(static_cast(point.mX), static_cast(point.mY), + static_cast(point.mZ)) + + wireOffset; size_t vertexOffset = it * DiamondVertexCount; size_t indexOffset = it * DiamondWireframeIndexCount; @@ -171,7 +179,8 @@ namespace SceneUtil for (unsigned short i = 0; i < DiamondWireframeIndexCount; ++i) { - indices->setElement(static_cast(indexOffset + i), static_cast(vertexOffset + DiamondWireframeIndices[i])); + indices->setElement(static_cast(indexOffset + i), + static_cast(vertexOffset + DiamondWireframeIndices[i])); } } diff --git a/components/sceneutil/waterutil.cpp b/components/sceneutil/waterutil.cpp index b5fe3019d3..4066fd2319 100644 --- a/components/sceneutil/waterutil.cpp +++ b/components/sceneutil/waterutil.cpp @@ -58,7 +58,8 @@ namespace SceneUtil normal->push_back(osg::Vec3f(0, 0, 1)); waterGeom->setNormalArray(normal, osg::Array::BIND_OVERALL); - waterGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, static_cast(verts->size()))); + waterGeom->addPrimitiveSet( + new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, static_cast(verts->size()))); waterGeom->setComputeBoundingBoxCallback(new WaterBoundCallback); waterGeom->setCullingActive(false); return waterGeom; diff --git a/components/sdlutil/sdlinputwrapper.cpp b/components/sdlutil/sdlinputwrapper.cpp index 5786517b88..8bb802bb7c 100644 --- a/components/sdlutil/sdlinputwrapper.cpp +++ b/components/sdlutil/sdlinputwrapper.cpp @@ -39,7 +39,7 @@ namespace SDLUtil _setWindowScale(); } - InputWrapper::~InputWrapper() {} + InputWrapper::~InputWrapper() = default; void InputWrapper::_setWindowScale() { @@ -47,8 +47,8 @@ namespace SDLUtil SDL_GetWindowSize(mSDLWindow, &w, &h); int dw, dh; SDL_GL_GetDrawableSize(mSDLWindow, &dw, &dh); - mScaleX = dw / w; - mScaleY = dh / h; + mScaleX = static_cast(dw / w); + mScaleY = static_cast(dh / h); } void InputWrapper::capture(bool windowEventsOnly) @@ -320,8 +320,8 @@ namespace SDLUtil { SDL_WarpMouseInWindow(mSDLWindow, x, y); mWarpCompensate = true; - mWarpX = x; - mWarpY = y; + mWarpX = static_cast(x); + mWarpY = static_cast(y); } /// \brief Locks the pointer to the window diff --git a/components/shader/shadermanager.cpp b/components/shader/shadermanager.cpp index f44c8f475d..82fbc90480 100644 --- a/components/shader/shadermanager.cpp +++ b/components/shader/shadermanager.cpp @@ -69,7 +69,8 @@ namespace { lineDirectivePosition = 0; } - lineNumber += std::count(source.begin() + lineDirectivePosition, source.begin() + foundPos, '\n'); + lineNumber + += static_cast(std::count(source.begin() + lineDirectivePosition, source.begin() + foundPos, '\n')); return lineNumber; } } diff --git a/components/stereo/multiview.cpp b/components/stereo/multiview.cpp index 25b0ccfc21..3e76222955 100644 --- a/components/stereo/multiview.cpp +++ b/components/stereo/multiview.cpp @@ -52,7 +52,7 @@ namespace Stereo bool getTextureViewSupportedImpl(unsigned int contextID) { - if (!osg::isGLExtensionOrVersionSupported(contextID, "ARB_texture_view", 4.3)) + if (!osg::isGLExtensionOrVersionSupported(contextID, "ARB_texture_view", 4.3f)) { Log(Debug::Verbose) << "Disabling texture views (opengl extension \"ARB_texture_view\" not supported)"; return false; diff --git a/components/stereo/stereomanager.cpp b/components/stereo/stereomanager.cpp index a2b7b2c7f3..e089229699 100644 --- a/components/stereo/stereomanager.cpp +++ b/components/stereo/stereomanager.cpp @@ -114,7 +114,7 @@ namespace Stereo return *sInstance; } - Manager::Manager(osgViewer::Viewer* viewer, bool enableStereo, double near, double far) + Manager::Manager(osgViewer::Viewer* viewer, bool enableStereo, float near, float far) : mViewer(viewer) , mMainCamera(mViewer->getCamera()) , mUpdateCallback(new StereoUpdateCallback(this)) @@ -182,8 +182,8 @@ namespace Stereo { if (mEyeResolutionOverriden) return mEyeResolutionOverride; - auto width = mMainCamera->getViewport()->width() / 2; - auto height = mMainCamera->getViewport()->height(); + auto width = static_cast(mMainCamera->getViewport()->width() / 2); + auto height = static_cast(mMainCamera->getViewport()->height()); return osg::Vec2i(width, height); } diff --git a/components/stereo/stereomanager.hpp b/components/stereo/stereomanager.hpp index 8ed88da550..3e4c66f24d 100644 --- a/components/stereo/stereomanager.hpp +++ b/components/stereo/stereomanager.hpp @@ -78,13 +78,13 @@ namespace Stereo //! @Param enableMultiview whether or not to make use of the GL_OVR_Multiview extension, if supported. //! @Param near defines distance to near camera clipping plane from view point. //! @Param far defines distance to far camera clipping plane from view point. - explicit Manager(osgViewer::Viewer* viewer, bool enableStereo, double near, double far); + explicit Manager(osgViewer::Viewer* viewer, bool enableStereo, float near, float far); ~Manager(); //! Called during update traversal void update(); - void updateSettings(double near, double far) + void updateSettings(float near, float far) { mNear = near; mFar = far; @@ -146,8 +146,8 @@ namespace Stereo std::shared_ptr mMultiviewFramebuffer; bool mEyeResolutionOverriden; osg::Vec2i mEyeResolutionOverride; - double mNear; - double mFar; + float mNear; + float mFar; std::array mView; std::array mViewOffsetMatrix; diff --git a/components/stereo/types.cpp b/components/stereo/types.cpp index 99b7da5ad1..0c29e04795 100644 --- a/components/stereo/types.cpp +++ b/components/stereo/types.cpp @@ -60,15 +60,18 @@ namespace Stereo // that view matrix will already convert points to a camera space // with opengl conventions. So we need to convert offsets to opengl // conventions. - float y = position.y(); - float z = position.z(); - position.y() = z; - position.z() = -y; - - y = orientation.y(); - z = orientation.z(); - orientation.y() = z; - orientation.z() = -y; + { + float y = position.y(); + float z = position.z(); + position.y() = z; + position.z() = -y; + } + { + double y = orientation.y(); + double z = orientation.z(); + orientation.y() = z; + orientation.z() = -y; + } osg::Matrix viewMatrix; viewMatrix.setTrans(-position); diff --git a/components/terrain/buffercache.cpp b/components/terrain/buffercache.cpp index 6dc4f8dab9..4cbf435353 100644 --- a/components/terrain/buffercache.cpp +++ b/components/terrain/buffercache.cpp @@ -12,6 +12,7 @@ namespace template osg::ref_ptr createIndexBuffer(unsigned int flags, unsigned int verts) { + using IndexType = IndexArrayType::value_type; // LOD level n means every 2^n-th vertex is kept, but we currently handle LOD elsewhere. size_t lodLevel = 0; //(flags >> (4*4)); @@ -45,23 +46,23 @@ namespace // diamond pattern if ((row + col % 2) % 2 == 1) { - indices->push_back(verts * (col + increment) + row); - indices->push_back(verts * (col + increment) + row + increment); - indices->push_back(verts * col + row + increment); + indices->push_back(static_cast(verts * (col + increment) + row)); + indices->push_back(static_cast(verts * (col + increment) + row + increment)); + indices->push_back(static_cast(verts * col + row + increment)); - indices->push_back(verts * col + row); - indices->push_back(verts * (col + increment) + row); - indices->push_back(verts * (col) + row + increment); + indices->push_back(static_cast(verts * col + row)); + indices->push_back(static_cast(verts * (col + increment) + row)); + indices->push_back(static_cast(verts * (col) + row + increment)); } else { - indices->push_back(verts * col + row); - indices->push_back(verts * (col + increment) + row + increment); - indices->push_back(verts * col + row + increment); + indices->push_back(static_cast(verts * col + row)); + indices->push_back(static_cast(verts * (col + increment) + row + increment)); + indices->push_back(static_cast(verts * col + row + increment)); - indices->push_back(verts * col + row); - indices->push_back(verts * (col + increment) + row); - indices->push_back(verts * (col + increment) + row + increment); + indices->push_back(static_cast(verts * col + row)); + indices->push_back(static_cast(verts * (col + increment) + row)); + indices->push_back(static_cast(verts * (col + increment) + row + increment)); } } } @@ -77,22 +78,22 @@ namespace size_t outerStep = static_cast(1) << (lodDeltas[Terrain::South] + lodLevel); for (size_t col = 0; col < verts - 1; col += outerStep) { - indices->push_back(verts * col + row); - indices->push_back(verts * (col + outerStep) + row); + indices->push_back(static_cast(verts * col + row)); + indices->push_back(static_cast(verts * (col + outerStep) + row)); // Make sure not to touch the right edge if (col + outerStep == verts - 1) - indices->push_back(verts * (col + outerStep - innerStep) + row + innerStep); + indices->push_back(static_cast(verts * (col + outerStep - innerStep) + row + innerStep)); else - indices->push_back(verts * (col + outerStep) + row + innerStep); + indices->push_back(static_cast(verts * (col + outerStep) + row + innerStep)); for (size_t i = 0; i < outerStep; i += innerStep) { // Make sure not to touch the left or right edges if (col + i == 0 || col + i == verts - 1 - innerStep) continue; - indices->push_back(verts * (col) + row); - indices->push_back(verts * (col + i + innerStep) + row + innerStep); - indices->push_back(verts * (col + i) + row + innerStep); + indices->push_back(static_cast(verts * (col) + row)); + indices->push_back(static_cast(verts * (col + i + innerStep) + row + innerStep)); + indices->push_back(static_cast(verts * (col + i) + row + innerStep)); } } @@ -101,22 +102,22 @@ namespace outerStep = size_t(1) << (lodDeltas[Terrain::North] + lodLevel); for (size_t col = 0; col < verts - 1; col += outerStep) { - indices->push_back(verts * (col + outerStep) + row); - indices->push_back(verts * col + row); + indices->push_back(static_cast(verts * (col + outerStep) + row)); + indices->push_back(static_cast(verts * col + row)); // Make sure not to touch the left edge if (col == 0) - indices->push_back(verts * (col + innerStep) + row - innerStep); + indices->push_back(static_cast(verts * (col + innerStep) + row - innerStep)); else - indices->push_back(verts * col + row - innerStep); + indices->push_back(static_cast(verts * col + row - innerStep)); for (size_t i = 0; i < outerStep; i += innerStep) { // Make sure not to touch the left or right edges if (col + i == 0 || col + i == verts - 1 - innerStep) continue; - indices->push_back(verts * (col + i) + row - innerStep); - indices->push_back(verts * (col + i + innerStep) + row - innerStep); - indices->push_back(verts * (col + outerStep) + row); + indices->push_back(static_cast(verts * (col + i) + row - innerStep)); + indices->push_back(static_cast(verts * (col + i + innerStep) + row - innerStep)); + indices->push_back(static_cast(verts * (col + outerStep) + row)); } } @@ -125,22 +126,22 @@ namespace outerStep = size_t(1) << (lodDeltas[Terrain::West] + lodLevel); for (row = 0; row < verts - 1; row += outerStep) { - indices->push_back(verts * col + row + outerStep); - indices->push_back(verts * col + row); + indices->push_back(static_cast(verts * col + row + outerStep)); + indices->push_back(static_cast(verts * col + row)); // Make sure not to touch the top edge if (row + outerStep == verts - 1) - indices->push_back(verts * (col + innerStep) + row + outerStep - innerStep); + indices->push_back(static_cast(verts * (col + innerStep) + row + outerStep - innerStep)); else - indices->push_back(verts * (col + innerStep) + row + outerStep); + indices->push_back(static_cast(verts * (col + innerStep) + row + outerStep)); for (size_t i = 0; i < outerStep; i += innerStep) { // Make sure not to touch the top or bottom edges if (row + i == 0 || row + i == verts - 1 - innerStep) continue; - indices->push_back(verts * col + row); - indices->push_back(verts * (col + innerStep) + row + i); - indices->push_back(verts * (col + innerStep) + row + i + innerStep); + indices->push_back(static_cast(verts * col + row)); + indices->push_back(static_cast(verts * (col + innerStep) + row + i)); + indices->push_back(static_cast(verts * (col + innerStep) + row + i + innerStep)); } } @@ -149,22 +150,22 @@ namespace outerStep = size_t(1) << (lodDeltas[Terrain::East] + lodLevel); for (row = 0; row < verts - 1; row += outerStep) { - indices->push_back(verts * col + row); - indices->push_back(verts * col + row + outerStep); + indices->push_back(static_cast(verts * col + row)); + indices->push_back(static_cast(verts * col + row + outerStep)); // Make sure not to touch the bottom edge if (row == 0) - indices->push_back(verts * (col - innerStep) + row + innerStep); + indices->push_back(static_cast(verts * (col - innerStep) + row + innerStep)); else - indices->push_back(verts * (col - innerStep) + row); + indices->push_back(static_cast(verts * (col - innerStep) + row)); for (size_t i = 0; i < outerStep; i += innerStep) { // Make sure not to touch the top or bottom edges if (row + i == 0 || row + i == verts - 1 - innerStep) continue; - indices->push_back(verts * col + row + outerStep); - indices->push_back(verts * (col - innerStep) + row + i + innerStep); - indices->push_back(verts * (col - innerStep) + row + i); + indices->push_back(static_cast(verts * col + row + outerStep)); + indices->push_back(static_cast(verts * (col - innerStep) + row + i + innerStep)); + indices->push_back(static_cast(verts * (col - innerStep) + row + i)); } } } diff --git a/components/terrain/cellborder.cpp b/components/terrain/cellborder.cpp index b78691cd8d..bc257ab407 100644 --- a/components/terrain/cellborder.cpp +++ b/components/terrain/cellborder.cpp @@ -62,7 +62,7 @@ namespace Terrain border->setColorArray(colors.get()); border->setColorBinding(osg::Geometry::BIND_PER_VERTEX); - border->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, vertices->size())); + border->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, static_cast(vertices->size()))); osg::ref_ptr borderGroup = new osg::Group; borderGroup->addChild(border.get()); @@ -84,8 +84,8 @@ namespace Terrain void CellBorder::createCellBorderGeometry(int x, int y) { - auto borderGroup = createBorderGeometry( - x, y, 1.f, mWorld->getStorage(), mSceneManager, mBorderMask, mWorld->getWorldspace()); + auto borderGroup = createBorderGeometry(static_cast(x), static_cast(y), 1.f, mWorld->getStorage(), + mSceneManager, mBorderMask, mWorld->getWorldspace()); mRoot->addChild(borderGroup); mCellBorderNodes[std::make_pair(x, y)] = borderGroup; diff --git a/components/terrain/chunkmanager.cpp b/components/terrain/chunkmanager.cpp index 242f3e5700..dcb872ec55 100644 --- a/components/terrain/chunkmanager.cpp +++ b/components/terrain/chunkmanager.cpp @@ -206,10 +206,10 @@ namespace Terrain blendmapTextures.push_back(texture); } - float tileCount = mStorage->getTextureTileCount(chunkSize, mWorldspace); + int tileCount = mStorage->getTextureTileCount(chunkSize, mWorldspace); - return ::Terrain::createPasses( - useShaders, mSceneManager, layers, blendmapTextures, tileCount, tileCount, ESM::isEsm4Ext(mWorldspace)); + return ::Terrain::createPasses(useShaders, mSceneManager, layers, blendmapTextures, tileCount, + static_cast(tileCount), ESM::isEsm4Ext(mWorldspace)); } osg::ref_ptr ChunkManager::createChunk(float chunkSize, const osg::Vec2f& chunkCenter, unsigned char lod, @@ -261,7 +261,8 @@ namespace Terrain if (chunkSize <= 1.f) geometry->setLightListCallback(new SceneUtil::LightListCallback); - unsigned int numVerts = (mStorage->getCellVertices(mWorldspace) - 1) * chunkSize / (1 << lod) + 1; + unsigned int numVerts + = static_cast((mStorage->getCellVertices(mWorldspace) - 1) * chunkSize / (1 << lod) + 1); geometry->addPrimitiveSet(mBufferCache.getIndexBuffer(numVerts, lodFlags)); @@ -303,7 +304,7 @@ namespace Terrain layer.mSpecular = false; geometry->setPasses(::Terrain::createPasses( mSceneManager->getForceShaders() || !mSceneManager->getClampLighting(), mSceneManager, - std::vector(1, layer), std::vector>(), 1.f, 1.f)); + std::vector(1, layer), std::vector>(), 1, 1.f)); } else { diff --git a/components/terrain/compositemaprenderer.cpp b/components/terrain/compositemaprenderer.cpp index adf58162e8..7a03015344 100644 --- a/components/terrain/compositemaprenderer.cpp +++ b/components/terrain/compositemaprenderer.cpp @@ -21,7 +21,7 @@ namespace Terrain getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); } - CompositeMapRenderer::~CompositeMapRenderer() {} + CompositeMapRenderer::~CompositeMapRenderer() = default; void CompositeMapRenderer::drawImplementation(osg::RenderInfo& renderInfo) const { @@ -104,7 +104,7 @@ namespace Terrain // should OSG be doing this on its own? state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), osg::StateAttribute::TEXTURE); - for (unsigned int i = compositeMap.mCompiled; i < compositeMap.mDrawables.size(); ++i) + for (size_t i = compositeMap.mCompiled; i < compositeMap.mDrawables.size(); ++i) { osg::Drawable* drw = compositeMap.mDrawables[i]; osg::StateSet* stateset = drw->getStateSet(); @@ -165,7 +165,7 @@ namespace Terrain } } - unsigned int CompositeMapRenderer::getCompileSetSize() const + size_t CompositeMapRenderer::getCompileSetSize() const { std::lock_guard lock(mMutex); return mCompileSet.size(); diff --git a/components/terrain/compositemaprenderer.hpp b/components/terrain/compositemaprenderer.hpp index 1e33c717ec..24849e0e86 100644 --- a/components/terrain/compositemaprenderer.hpp +++ b/components/terrain/compositemaprenderer.hpp @@ -23,7 +23,7 @@ namespace Terrain ~CompositeMap(); std::vector> mDrawables; osg::ref_ptr mTexture; - unsigned int mCompiled; + size_t mCompiled; }; /** @@ -52,7 +52,7 @@ namespace Terrain /// Mark this composite map to be required for the current frame void setImmediate(CompositeMap* map); - unsigned int getCompileSetSize() const; + size_t getCompileSetSize() const; private: float mTargetFrameRate; diff --git a/components/terrain/material.cpp b/components/terrain/material.cpp index 350b174d69..c04d8d8da6 100644 --- a/components/terrain/material.cpp +++ b/components/terrain/material.cpp @@ -24,17 +24,17 @@ namespace static const osg::ref_ptr& value(const int blendmapScale) { static BlendmapTexMat instance; - return instance.get(blendmapScale); + return instance.get(static_cast(blendmapScale)); } - const osg::ref_ptr& get(const int blendmapScale) + const osg::ref_ptr& get(const float blendmapScale) { const std::lock_guard lock(mMutex); auto texMat = mTexMatMap.find(blendmapScale); if (texMat == mTexMatMap.end()) { osg::Matrixf matrix; - float scale = (blendmapScale / (static_cast(blendmapScale) + 1.f)); + float scale = (blendmapScale / (blendmapScale + 1.f)); matrix.preMultTranslate(osg::Vec3f(0.5f, 0.5f, 0.f)); matrix.preMultScale(osg::Vec3f(scale, scale, 1.f)); matrix.preMultTranslate(osg::Vec3f(-0.5f, -0.5f, 0.f)); @@ -43,8 +43,7 @@ namespace // blendmap, apparently. matrix.preMultTranslate(osg::Vec3f(1.0f / blendmapScale / 4.0f, 1.0f / blendmapScale / 4.0f, 0.f)); - texMat = mTexMatMap.insert(std::make_pair(static_cast(blendmapScale), new osg::TexMat(matrix))) - .first; + texMat = mTexMatMap.emplace(blendmapScale, new osg::TexMat(matrix)).first; } return texMat->second; } diff --git a/components/terrain/quadtreenode.hpp b/components/terrain/quadtreenode.hpp index abe92b1ba9..0f5c689682 100644 --- a/components/terrain/quadtreenode.hpp +++ b/components/terrain/quadtreenode.hpp @@ -44,7 +44,7 @@ namespace Terrain inline QuadTreeNode* getParent() { return mParent; } inline QuadTreeNode* getChild(unsigned int i) { return static_cast(Group::getChild(i)); } - inline unsigned int getNumChildren() const override { return _children.size(); } + inline unsigned int getNumChildren() const override { return static_cast(_children.size()); } // osg::Group::addChild() does a lot of unrelated stuff, but we just really want to add a child node. void addChildNode(QuadTreeNode* child) diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 0d7f1b7762..fceb469d38 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -145,7 +145,7 @@ namespace Terrain float centerX = (mMinX + mMaxX) / 2.f + (size - origSizeX) / 2.f; float centerY = (mMinY + mMaxY) / 2.f + (size - origSizeY) / 2.f; - mRootNode = new RootNode(size, osg::Vec2f(centerX, centerY)); + mRootNode = new RootNode(static_cast(size), osg::Vec2f(centerX, centerY)); addChildren(mRootNode); mRootNode->initNeighbours(); @@ -212,7 +212,8 @@ namespace Terrain // Do not add child nodes for default cells without data. // size = 1 means that the single shape covers the whole cell. if (node->getSize() == 1 - && !mStorage->hasData(ESM::ExteriorCellLocation(center.x() - 0.5, center.y() - 0.5, mWorldspace))) + && !mStorage->hasData(ESM::ExteriorCellLocation( + static_cast(center.x() - 0.5f), static_cast(center.y() - 0.5f), mWorldspace))) return node; if (node->getSize() <= mMinSize) @@ -259,14 +260,14 @@ namespace Terrain , mNodeMask(nodeMask) { } - osg::ref_ptr getChunk(float size, const osg::Vec2f& chunkCenter, unsigned char lod, + osg::ref_ptr getChunk(float size, const osg::Vec2f& chunkCenter, unsigned char /*lod*/, unsigned int lodFlags, bool activeGrid, const osg::Vec3f& viewPoint, bool compile) { osg::Vec3f center = { chunkCenter.x(), chunkCenter.y(), 0 }; auto chunkBorder = CellBorder::createBorderGeometry(center.x() - size / 2.f, center.y() - size / 2.f, size, mStorage, mSceneManager, mNodeMask, mWorldspace, 5.f, { 1, 0, 0, 0 }); osg::ref_ptr pat = new SceneUtil::PositionAttitudeTransform; - pat->setPosition(-center * ESM::getCellSize(mWorldspace)); + pat->setPosition(-center * static_cast(ESM::getCellSize(mWorldspace))); pat->addChild(chunkBorder); return pat; } @@ -282,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) @@ -396,8 +397,8 @@ namespace Terrain for (QuadTreeWorld::ChunkManager* m : mChunkManagers) { osg::ref_ptr n = m->getChunk(entry.mNode->getSize(), entry.mNode->getCenter(), - DefaultLodCallback::getNativeLodLevel(entry.mNode, mMinSize), entry.mLodFlags, activeGrid, - vd->getViewPoint(), compile); + static_cast(DefaultLodCallback::getNativeLodLevel(entry.mNode, mMinSize)), + entry.mLodFlags, activeGrid, vd->getViewPoint(), compile); if (n) pat->addChild(n); } @@ -487,7 +488,7 @@ namespace Terrain mRootNode->traverseNodes(vd, viewPoint, &lodCallback); } - const float cellWorldSize = ESM::getCellSize(mWorldspace); + const float cellWorldSize = static_cast(ESM::getCellSize(mWorldspace)); for (unsigned int i = 0; i < vd->getNumEntries(); ++i) { @@ -552,7 +553,7 @@ namespace Terrain vd->setViewPoint(viewPoint); vd->setActiveGrid(grid); - DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, grid, cellWorldSize); + DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, grid, static_cast(cellWorldSize)); mRootNode->traverseNodes(vd, viewPoint, &lodCallback); reporter.addTotal(vd->getNumEntries()); @@ -568,14 +569,15 @@ namespace Terrain void QuadTreeWorld::reportStats(unsigned int frameNumber, osg::Stats* stats) { if (mCompositeMapRenderer) - stats->setAttribute(frameNumber, "Composite", mCompositeMapRenderer->getCompileSetSize()); + stats->setAttribute( + frameNumber, "Composite", static_cast(mCompositeMapRenderer->getCompileSetSize())); } void QuadTreeWorld::loadCell(int x, int y) { // fallback behavior only for undefined cells (every other is already handled in quadtree) float dummy; - if (mChunkManager && !mStorage->getMinMaxHeights(1, osg::Vec2f(x + 0.5, y + 0.5), mWorldspace, dummy, dummy)) + if (mChunkManager && !mStorage->getMinMaxHeights(1, osg::Vec2f(x + 0.5f, y + 0.5f), mWorldspace, dummy, dummy)) TerrainGrid::loadCell(x, y); else World::loadCell(x, y); @@ -585,7 +587,7 @@ namespace Terrain { // fallback behavior only for undefined cells (every other is already handled in quadtree) float dummy; - if (mChunkManager && !mStorage->getMinMaxHeights(1, osg::Vec2f(x + 0.5, y + 0.5), mWorldspace, dummy, dummy)) + if (mChunkManager && !mStorage->getMinMaxHeights(1, osg::Vec2f(x + 0.5f, y + 0.5f), mWorldspace, dummy, dummy)) TerrainGrid::unloadCell(x, y); else World::unloadCell(x, y); diff --git a/components/terrain/quadtreeworld.hpp b/components/terrain/quadtreeworld.hpp index fa800d2655..56962a5529 100644 --- a/components/terrain/quadtreeworld.hpp +++ b/components/terrain/quadtreeworld.hpp @@ -59,7 +59,7 @@ namespace Terrain class ChunkManager { public: - virtual ~ChunkManager() {} + virtual ~ChunkManager() = default; ChunkManager() = default; ChunkManager(ESM::RefId worldspace) : ChunkManager() diff --git a/components/terrain/storage.hpp b/components/terrain/storage.hpp index 38aee20b8b..436efd8e31 100644 --- a/components/terrain/storage.hpp +++ b/components/terrain/storage.hpp @@ -25,7 +25,7 @@ namespace Terrain class Storage { public: - virtual ~Storage() {} + virtual ~Storage() = default; public: /// Get bounds of the whole terrain in cell units @@ -36,8 +36,8 @@ namespace Terrain virtual bool hasData(ESM::ExteriorCellLocation cellLocation) { float dummy; - return getMinMaxHeights( - 1, osg::Vec2f(cellLocation.mX + 0.5, cellLocation.mY + 0.5), cellLocation.mWorldspace, dummy, dummy); + return getMinMaxHeights(1.f, osg::Vec2f(cellLocation.mX + 0.5f, cellLocation.mY + 0.5f), + cellLocation.mWorldspace, dummy, dummy); } /// Get the minimum and maximum heights of a terrain region. diff --git a/components/terrain/terraindrawable.cpp b/components/terrain/terraindrawable.cpp index 65f7aaf98b..20df85b6ba 100644 --- a/components/terrain/terraindrawable.cpp +++ b/components/terrain/terraindrawable.cpp @@ -12,7 +12,7 @@ namespace Terrain TerrainDrawable::TerrainDrawable() {} - TerrainDrawable::~TerrainDrawable() {} + TerrainDrawable::~TerrainDrawable() = default; TerrainDrawable::TerrainDrawable(const TerrainDrawable& copy, const osg::CopyOp& copyop) : osg::Geometry(copy, copyop) @@ -37,8 +37,8 @@ namespace Terrain inline float distance(const osg::Vec3& coord, const osg::Matrix& matrix) { - return -((float)coord[0] * (float)matrix(0, 2) + (float)coord[1] * (float)matrix(1, 2) - + (float)coord[2] * (float)matrix(2, 2) + matrix(3, 2)); + return -(coord[0] * static_cast(matrix(0, 2)) + coord[1] * static_cast(matrix(1, 2)) + + coord[2] * static_cast(matrix(2, 2)) + static_cast(matrix(3, 2))); } // canot use ClusterCullingCallback::cull: viewpoint != eyepoint