From 98291f137788a22f61e4dbb578aa26d6bfd21314 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 18 Sep 2025 00:38:08 +0100 Subject: [PATCH] First batch of warning fixes --- components/detournavigator/recastparams.hpp | 2 +- components/detournavigator/tilebounds.hpp | 4 +-- components/esm/util.hpp | 2 +- components/esm3/loadmgef.cpp | 16 +++++----- components/esm3/loadmgef.hpp | 2 +- components/files/memorystream.hpp | 2 +- components/lua/configuration.cpp | 2 +- components/misc/convert.hpp | 6 ++-- components/nifosg/controller.cpp | 2 +- components/nifosg/matrixtransform.cpp | 2 +- components/nifosg/particle.cpp | 16 +++++----- components/resource/bulletshapemanager.cpp | 8 ++--- components/resource/keyframemanager.cpp | 6 ++-- components/resource/stats.cpp | 8 ++--- components/sceneutil/controller.cpp | 4 +-- components/sceneutil/detourdebugdraw.cpp | 4 +-- components/sceneutil/lightcommon.cpp | 4 +-- components/sceneutil/lightmanager.cpp | 24 +++++++------- components/sceneutil/lightmanager.hpp | 12 +++---- components/sceneutil/lightutil.cpp | 4 +-- components/sceneutil/mwshadowtechnique.cpp | 2 +- components/sceneutil/mwshadowtechnique.hpp | 6 ++-- components/sceneutil/pathgridutil.cpp | 31 +++++++++++-------- .../sceneutil/positionattitudetransform.cpp | 4 +-- components/sceneutil/recastmesh.cpp | 2 +- components/sceneutil/shadow.cpp | 2 +- components/sceneutil/statesetupdater.cpp | 16 +++++----- components/sceneutil/statesetupdater.hpp | 4 +-- components/sceneutil/util.cpp | 4 +-- components/sceneutil/util.hpp | 2 +- components/sceneutil/waterutil.cpp | 2 +- components/sceneutil/workqueue.cpp | 4 +-- components/sceneutil/workqueue.hpp | 4 +-- components/shader/shadervisitor.cpp | 4 +-- 34 files changed, 111 insertions(+), 106 deletions(-) diff --git a/components/detournavigator/recastparams.hpp b/components/detournavigator/recastparams.hpp index 74af132bf6..0a99ad58f2 100644 --- a/components/detournavigator/recastparams.hpp +++ b/components/detournavigator/recastparams.hpp @@ -21,7 +21,7 @@ namespace DetourNavigator switch (agentBounds.mShapeType) { case CollisionShapeType::Aabb: - return std::max(agentBounds.mHalfExtents.x(), agentBounds.mHalfExtents.y()) * std::sqrt(2); + return std::max(agentBounds.mHalfExtents.x(), agentBounds.mHalfExtents.y()) * std::sqrt(2.0f); case CollisionShapeType::RotatingBox: return agentBounds.mHalfExtents.x(); case CollisionShapeType::Cylinder: diff --git a/components/detournavigator/tilebounds.hpp b/components/detournavigator/tilebounds.hpp index ef1181307c..62304c1d21 100644 --- a/components/detournavigator/tilebounds.hpp +++ b/components/detournavigator/tilebounds.hpp @@ -56,8 +56,8 @@ namespace DetourNavigator inline TileBounds maxCellTileBounds(const osg::Vec2i& position, int size) { - return TileBounds{ osg::Vec2f(position.x(), position.y()) * size, - osg::Vec2f(position.x() + 1, position.y() + 1) * 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/esm/util.hpp b/components/esm/util.hpp index ae756baf6a..5015b3059d 100644 --- a/components/esm/util.hpp +++ b/components/esm/util.hpp @@ -29,7 +29,7 @@ namespace ESM inline ESM::ExteriorCellLocation positionToExteriorCellLocation( float x, float y, ESM::RefId worldspaceId = ESM::Cell::sDefaultWorldspaceId) { - const float cellSize = getCellSize(worldspaceId); + const float cellSize = static_cast(getCellSize(worldspaceId)); return { static_cast(std::floor(x / cellSize)), static_cast(std::floor(y / cellSize)), worldspaceId }; } diff --git a/components/esm3/loadmgef.cpp b/components/esm3/loadmgef.cpp index 3ff725fcf7..1d3102e4a1 100644 --- a/components/esm3/loadmgef.cpp +++ b/components/esm3/loadmgef.cpp @@ -141,11 +141,11 @@ namespace ESM effects[MagicEffect::Effects::DisintegrateArmor] = MagicEffect::Effects::Sanctuary; effects[MagicEffect::Effects::DisintegrateWeapon] = MagicEffect::Effects::Sanctuary; - for (int i = MagicEffect::Effects::DrainAttribute; i <= MagicEffect::Effects::DamageSkill; ++i) + for (short i = MagicEffect::Effects::DrainAttribute; i <= MagicEffect::Effects::DamageSkill; ++i) effects[i] = MagicEffect::Effects::ResistMagicka; - for (int i = MagicEffect::Effects::AbsorbAttribute; i <= MagicEffect::Effects::AbsorbSkill; ++i) + for (short i = MagicEffect::Effects::AbsorbAttribute; i <= MagicEffect::Effects::AbsorbSkill; ++i) effects[i] = MagicEffect::Effects::ResistMagicka; - for (int 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; @@ -154,7 +154,7 @@ namespace ESM effects[MagicEffect::Effects::Blind] = MagicEffect::Effects::ResistMagicka; effects[MagicEffect::Effects::Sound] = MagicEffect::Effects::ResistMagicka; - for (int i = 0; i < 2; ++i) + for (short i = 0; i < 2; ++i) { effects[MagicEffect::Effects::CalmHumanoid + i] = MagicEffect::Effects::ResistMagicka; effects[MagicEffect::Effects::FrenzyHumanoid + i] = MagicEffect::Effects::ResistMagicka; @@ -194,11 +194,11 @@ namespace ESM static std::map effects; if (effects.empty()) { - for (int i = DrainAttribute; i <= DamageSkill; ++i) + for (short i = DrainAttribute; i <= DamageSkill; ++i) effects[i] = WeaknessToMagicka; - for (int i = AbsorbAttribute; i <= AbsorbSkill; ++i) + for (short i = AbsorbAttribute; i <= AbsorbSkill; ++i) effects[i] = WeaknessToMagicka; - for (int i = WeaknessToFire; i <= WeaknessToNormalWeapons; ++i) + for (short i = WeaknessToFire; i <= WeaknessToNormalWeapons; ++i) effects[i] = WeaknessToMagicka; effects[Burden] = WeaknessToMagicka; @@ -207,7 +207,7 @@ namespace ESM effects[Blind] = WeaknessToMagicka; effects[Sound] = WeaknessToMagicka; - for (int i = 0; i < 2; ++i) + for (short i = 0; i < 2; ++i) { effects[CalmHumanoid + i] = WeaknessToMagicka; effects[FrenzyHumanoid + i] = WeaknessToMagicka; diff --git a/components/esm3/loadmgef.hpp b/components/esm3/loadmgef.hpp index 25ec7d0655..9f028e4bdc 100644 --- a/components/esm3/loadmgef.hpp +++ b/components/esm3/loadmgef.hpp @@ -117,7 +117,7 @@ namespace ESM osg::Vec4f getColor() const; - enum Effects + enum Effects : short { WaterBreathing = 0, SwiftSwim = 1, diff --git a/components/files/memorystream.hpp b/components/files/memorystream.hpp index bd226beb9a..964e3b6f4b 100644 --- a/components/files/memorystream.hpp +++ b/components/files/memorystream.hpp @@ -19,7 +19,7 @@ namespace Files pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which) override { if (dir == std::ios_base::cur) - gbump(off); + setg(bufferStart, gptr() + off, bufferEnd); else setg(bufferStart, (dir == std::ios_base::beg ? bufferStart : bufferEnd) + off, bufferEnd); diff --git a/components/lua/configuration.cpp b/components/lua/configuration.cpp index cbec2e4abc..5e3cdfe805 100644 --- a/components/lua/configuration.cpp +++ b/components/lua/configuration.cpp @@ -130,7 +130,7 @@ namespace LuaUtil { const ESM::LuaScriptCfg& script = mScripts[id]; if (script.mFlags & flag) - res[id] = script.mInitializationData; + res[static_cast(id)] = script.mInitializationData; } return res; } diff --git a/components/misc/convert.hpp b/components/misc/convert.hpp index 5d936b5d5f..be469c6a62 100644 --- a/components/misc/convert.hpp +++ b/components/misc/convert.hpp @@ -19,7 +19,7 @@ namespace Misc::Convert inline osg::Vec3f makeOsgVec3f(const ESM::Pathgrid::Point& value) { - return osg::Vec3f(value.mX, value.mY, value.mZ); + return osg::Vec3f(static_cast(value.mX), static_cast(value.mY), static_cast(value.mZ)); } inline btVector3 toBullet(const osg::Vec3f& vec) @@ -32,9 +32,9 @@ namespace Misc::Convert return btQuaternion(quat.x(), quat.y(), quat.z(), quat.w()); } - inline osg::Vec3f toOsg(const btVector3& vec) + inline osg::Vec3d toOsg(const btVector3& vec) { - return osg::Vec3f(vec.x(), vec.y(), vec.z()); + return osg::Vec3d(vec.x(), vec.y(), vec.z()); } inline osg::Quat toOsg(const btQuaternion& quat) diff --git a/components/nifosg/controller.cpp b/components/nifosg/controller.cpp index bd11344ed8..3ef288b209 100644 --- a/components/nifosg/controller.cpp +++ b/components/nifosg/controller.cpp @@ -263,7 +263,7 @@ namespace NifOsg if (mKeyFrames.size() <= 1) return; float input = getInputValue(nv); - size_t i = 1; + unsigned int i = 1; for (std::vector::iterator it = mKeyFrames.begin() + 1; it != mKeyFrames.end(); ++it, ++i) { diff --git a/components/nifosg/matrixtransform.cpp b/components/nifosg/matrixtransform.cpp index a59f10360a..8d7717eb49 100644 --- a/components/nifosg/matrixtransform.cpp +++ b/components/nifosg/matrixtransform.cpp @@ -40,7 +40,7 @@ namespace NifOsg for (int j = 0; j < 3; ++j) { // Update the current decomposed rotation and restore the known scale. - mRotationScale.mValues[j][i] = _matrix(i, j); // NB: column/row major difference + mRotationScale.mValues[j][i] = static_cast(_matrix(i, j)); // NB: column/row major difference _matrix(i, j) *= mScale; } } diff --git a/components/nifosg/particle.cpp b/components/nifosg/particle.cpp index 53830388a5..21fd280812 100644 --- a/components/nifosg/particle.cpp +++ b/components/nifosg/particle.cpp @@ -106,7 +106,7 @@ namespace NifOsg { mNormalArray = new osg::Vec3Array(1); mNormalArray->setBinding(osg::Array::BIND_OVERALL); - (*mNormalArray.get())[0] = osg::Vec3(0.3, 0.3, 0.3); + (*mNormalArray.get())[0] = osg::Vec3(0.3f, 0.3f, 0.3f); } ParticleSystem::ParticleSystem(const ParticleSystem& copy, const osg::CopyOp& copyop) @@ -115,7 +115,7 @@ namespace NifOsg { mNormalArray = new osg::Vec3Array(1); mNormalArray->setBinding(osg::Array::BIND_OVERALL); - (*mNormalArray.get())[0] = osg::Vec3(0.3, 0.3, 0.3); + (*mNormalArray.get())[0] = osg::Vec3(0.3f, 0.3f, 0.3f); // For some reason the osgParticle constructor doesn't copy the particles for (int i = 0; i < copy.numParticles() - copy.numDeadParticles(); ++i) @@ -247,9 +247,9 @@ namespace NifOsg { float size = mCachedDefaultSize; if (particle->getAge() < mGrowTime && mGrowTime != 0.f) - size *= particle->getAge() / mGrowTime; + size *= static_cast(particle->getAge() / mGrowTime); if (particle->getLifeTime() - particle->getAge() < mFadeTime && mFadeTime != 0.f) - size *= (particle->getLifeTime() - particle->getAge()) / mFadeTime; + size *= static_cast(particle->getLifeTime() - particle->getAge()) / mFadeTime; particle->setSizeRange(osgParticle::rangef(size, size)); } @@ -326,7 +326,7 @@ namespace NifOsg decayFactor = std::exp(-1.f * mDecay * distance); } - particle->addVelocity(mCachedWorldDirection * mForce * dt * decayFactor * magic); + particle->addVelocity(mCachedWorldDirection * mForce * static_cast(dt) * decayFactor * magic); break; } @@ -340,7 +340,7 @@ namespace NifOsg diff.normalize(); - particle->addVelocity(diff * mForce * dt * decayFactor * magic); + particle->addVelocity(diff * mForce * static_cast(dt) * decayFactor * magic); break; } } @@ -421,7 +421,7 @@ namespace NifOsg break; } - particle->addVelocity(explosionDir * mStrength * decay * dt); + particle->addVelocity(explosionDir * mStrength * decay * static_cast(dt)); } Emitter::Emitter() @@ -487,7 +487,7 @@ namespace NifOsg } else { - int randomIndex = 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 488624d2d2..d8594f9a99 100644 --- a/components/resource/bulletshapemanager.cpp +++ b/components/resource/bulletshapemanager.cpp @@ -83,11 +83,11 @@ namespace Resource auto triangleMeshShape = std::make_unique(mTriangleMesh.release(), true); btVector3 aabbMin = triangleMeshShape->getLocalAabbMin(); btVector3 aabbMax = triangleMeshShape->getLocalAabbMax(); - shape->mCollisionBox.mExtents[0] = (aabbMax[0] - aabbMin[0]) / 2.0f; - shape->mCollisionBox.mExtents[1] = (aabbMax[1] - aabbMin[1]) / 2.0f; - shape->mCollisionBox.mExtents[2] = (aabbMax[2] - aabbMin[2]) / 2.0f; + 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( - (aabbMax[0] + aabbMin[0]) / 2.0f, (aabbMax[1] + aabbMin[1]) / 2.0f, (aabbMax[2] + aabbMin[2]) / 2.0f); + 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/keyframemanager.cpp b/components/resource/keyframemanager.cpp index f962ba03fb..e216271925 100644 --- a/components/resource/keyframemanager.cpp +++ b/components/resource/keyframemanager.cpp @@ -144,8 +144,8 @@ namespace Resource callback->addMergedAnimationTrack(std::move(mergedAnimationTrack)); - float startTime = animation->getStartTime(); - float stopTime = startTime + animation->getDuration(); + float startTime = static_cast(animation->getStartTime()); + float stopTime = static_cast(startTime + animation->getDuration()); SceneUtil::EmulatedAnimation emulatedAnimation; emulatedAnimation.mStartTime = startTime; @@ -168,7 +168,7 @@ namespace Resource { std::string line; while (getline(*textKeysFile, line)) - mTarget.mTextKeys.emplace(parseTimeSignature(line), parseTextKey(line)); + mTarget.mTextKeys.emplace(static_cast(parseTimeSignature(line)), parseTextKey(line)); } catch (const std::exception& e) { diff --git a/components/resource/stats.cpp b/components/resource/stats.cpp index c902265448..d3bb721584 100644 --- a/components/resource/stats.cpp +++ b/components/resource/stats.cpp @@ -520,14 +520,14 @@ namespace Resource void StatsHandler::setUpScene(osgViewer::ViewerBase& viewer) { - const osg::Vec4 backgroundColor(0.0, 0.0, 0.0f, 0.3); - const osg::Vec4 staticTextColor(1.0, 1.0, 0.0f, 1.0); - const osg::Vec4 dynamicTextColor(1.0, 1.0, 1.0f, 1.0); + const osg::Vec4 backgroundColor(0.0f, 0.0f, 0.0f, 0.3f); + const osg::Vec4 staticTextColor(1.0f, 1.0f, 0.0f, 1.0f); + const osg::Vec4 dynamicTextColor(1.0f, 1.0f, 1.0f, 1.0f); const auto longest = std::max_element(mStatNames.begin(), mStatNames.end(), [](const std::string& lhs, const std::string& rhs) { return lhs.size() < rhs.size(); }); const std::size_t longestSize = longest->size(); - const float statNamesWidth = longestSize * characterSize * 0.6 + 2 * backgroundMargin; + const float statNamesWidth = longestSize * characterSize * 0.6f + 2 * backgroundMargin; const float statTextWidth = 7 * characterSize + 2 * backgroundMargin; const float statHeight = pageSize * characterSize + 2 * backgroundMargin; const float width = statNamesWidth + backgroundSpacing + statTextWidth; diff --git a/components/sceneutil/controller.cpp b/components/sceneutil/controller.cpp index e44c02741a..614795a55b 100644 --- a/components/sceneutil/controller.cpp +++ b/components/sceneutil/controller.cpp @@ -51,7 +51,7 @@ namespace SceneUtil float FrameTimeSource::getValue(osg::NodeVisitor* nv) { - return nv->getFrameStamp()->getSimulationTime(); + return static_cast(nv->getFrameStamp()->getSimulationTime()); } ControllerVisitor::ControllerVisitor() @@ -83,7 +83,7 @@ namespace SceneUtil visit(node, *ctrl); if (CompositeStateSetUpdater* composite = dynamic_cast(callback)) { - for (unsigned int i = 0; i < composite->getNumControllers(); ++i) + for (size_t i = 0; i < composite->getNumControllers(); ++i) { StateSetUpdater* statesetcontroller = composite->getController(i); if (Controller* ctrl = dynamic_cast(statesetcontroller)) diff --git a/components/sceneutil/detourdebugdraw.cpp b/components/sceneutil/detourdebugdraw.cpp index 24d29b0b70..1dd6d344e6 100644 --- a/components/sceneutil/detourdebugdraw.cpp +++ b/components/sceneutil/detourdebugdraw.cpp @@ -114,8 +114,8 @@ namespace SceneUtil osg::ref_ptr material = new osg::Material; material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); - const float polygonOffsetFactor = SceneUtil::AutoDepth::isReversed() ? 1.0 : -1.0; - const float polygonOffsetUnits = SceneUtil::AutoDepth::isReversed() ? 1.0 : -1.0; + const float polygonOffsetFactor = SceneUtil::AutoDepth::isReversed() ? 1.0f : -1.0f; + const float polygonOffsetUnits = SceneUtil::AutoDepth::isReversed() ? 1.0f : -1.0f; osg::ref_ptr polygonOffset = new osg::PolygonOffset(polygonOffsetFactor, polygonOffsetUnits); diff --git a/components/sceneutil/lightcommon.cpp b/components/sceneutil/lightcommon.cpp index 03d00811e2..f207de19c6 100644 --- a/components/sceneutil/lightcommon.cpp +++ b/components/sceneutil/lightcommon.cpp @@ -14,7 +14,7 @@ namespace SceneUtil , mPulseSlow(light.mData.mFlags & ESM::Light::PulseSlow) , mOffDefault(light.mData.mFlags & ESM::Light::OffDefault) , mColor(SceneUtil::colourFromRGB(light.mData.mColor)) - , mRadius(light.mData.mRadius) + , mRadius(static_cast(light.mData.mRadius)) { } @@ -26,7 +26,7 @@ namespace SceneUtil , mPulseSlow(light.mData.flags & ESM4::Light::PulseSlow) , mOffDefault(light.mData.flags & ESM4::Light::OffDefault) , mColor(SceneUtil::colourFromRGB(light.mData.colour)) - , mRadius(light.mData.radius) + , mRadius(static_cast(light.mData.radius)) { } diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index 178ea087c0..26532f3f6e 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -168,7 +168,7 @@ namespace SceneUtil void configureLayout(const LightBuffer* other) { mOffsets = other->mOffsets; - int size = other->mData->size(); + int size = static_cast(other->mData->size()); configureLayout(mOffsets, size); } @@ -192,7 +192,7 @@ namespace SceneUtil : mStride((offsetAttenuationRadius + sizeof(GLfloat) * osg::Vec4::num_components + stride) / 4) { constexpr auto sizeofFloat = sizeof(GLfloat); - const auto diffuseOffset = offsetColors / sizeofFloat; + const auto diffuseOffset = static_cast(offsetColors / sizeofFloat); mValues[Diffuse] = diffuseOffset; mValues[Ambient] = diffuseOffset + 1; @@ -310,7 +310,7 @@ namespace SceneUtil META_StateAttribute(SceneUtil, DisableLight, osg::StateAttribute::LIGHT) - unsigned int getMember() const override { return mIndex; } + unsigned int getMember() const override { return static_cast(mIndex); } bool getModeUsage(ModeUsage& usage) const override { @@ -360,12 +360,12 @@ namespace SceneUtil { } - unsigned int getMember() const override { return mIndex; } + unsigned int getMember() const override { return static_cast(mIndex); } bool getModeUsage(ModeUsage& usage) const override { for (size_t i = 0; i < mLights.size(); ++i) - usage.usesMode(GL_LIGHT0 + mIndex + i); + usage.usesMode(GL_LIGHT0 + static_cast(mIndex) + i); return true; } @@ -451,7 +451,7 @@ 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() + 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 @@ -533,7 +533,7 @@ namespace SceneUtil configureAttenuation(lightMat, light->getConstantAttenuation(), light->getLinearAttenuation(), light->getQuadraticAttenuation(), lightList[i]->mLightSource->getRadius()); - data->setElement(i + 1, lightMat); + data->setElement(static_cast(i + 1), lightMat); } stateset->addUniform(data); @@ -774,7 +774,7 @@ namespace SceneUtil int stride = -1; ext->glGetActiveUniformBlockiv(handle, 0, GL_UNIFORM_BLOCK_DATA_SIZE, &totalBlockSize); - ext->glGetActiveUniformsiv(handle, 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", @@ -784,8 +784,8 @@ namespace SceneUtil std::vector indices(names.size()); std::vector offsets(names.size()); - ext->glGetUniformIndices(handle, names.size(), names.data(), indices.data()); - ext->glGetActiveUniformsiv(handle, indices.size(), indices.data(), GL_UNIFORM_OFFSET, offsets.data()); + 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()); mTemplate->configureLayout(offsets[0], offsets[1], offsets[2], totalBlockSize, stride); } @@ -1047,7 +1047,7 @@ namespace SceneUtil LightSourceTransform l; l.mLightSource = lightSource; l.mWorldMatrix = worldMat; - osg::Vec3f pos = osg::Vec3f(worldMat.getTrans().x(), worldMat.getTrans().y(), worldMat.getTrans().z()); + osg::Vec3f pos = worldMat.getTrans(); lightSource->getLight(frameNum)->setPosition(osg::Vec4f(pos, 1.f)); mLights.push_back(l); @@ -1094,7 +1094,7 @@ namespace SceneUtil if (getLightIndexMap(frameNum).find(id) != getLightIndexMap(frameNum).end()) continue; - int index = getLightIndexMap(frameNum).size() + 1; + int index = static_cast(getLightIndexMap(frameNum).size()) + 1; updateGPUPointLight(index, lightList[i]->mLightSource, frameNum, viewMatrix); getLightIndexMap(frameNum).emplace(id, index); } diff --git a/components/sceneutil/lightmanager.hpp b/components/sceneutil/lightmanager.hpp index 0b30a77e5c..d6b3771b39 100644 --- a/components/sceneutil/lightmanager.hpp +++ b/components/sceneutil/lightmanager.hpp @@ -55,7 +55,7 @@ namespace SceneUtil void setLight(size_t frame, const osg::Light* light, float radius) { size_t frameId = frame % 2; - size_t i = mIndex[frameId]; + int i = mIndex[frameId]; if (i >= (sMaxPPLights - 1)) return; @@ -74,11 +74,11 @@ namespace SceneUtil void updateCount(size_t frame) { size_t frameId = frame % 2; - mUniformCount[frameId]->set(static_cast(mIndex[frameId])); + mUniformCount[frameId]->set(mIndex[frameId]); } private: - std::array mIndex; + std::array mIndex; std::array, 2> mUniformBuffers; std::array, 2> mUniformCount; }; @@ -106,7 +106,7 @@ namespace SceneUtil float mActorFade; - unsigned int mLastAppliedFrame; + size_t mLastAppliedFrame; bool mEmpty = false; @@ -148,9 +148,9 @@ namespace SceneUtil /// Get the unique ID for this light source. int getId() const { return mId; } - void setLastAppliedFrame(unsigned int lastAppliedFrame) { mLastAppliedFrame = lastAppliedFrame; } + void setLastAppliedFrame(size_t lastAppliedFrame) { mLastAppliedFrame = lastAppliedFrame; } - unsigned int getLastAppliedFrame() const { return mLastAppliedFrame; } + size_t getLastAppliedFrame() const { return mLastAppliedFrame; } }; class UBOManager : public osg::StateAttribute diff --git a/components/sceneutil/lightutil.cpp b/components/sceneutil/lightutil.cpp index 90dc8237f2..2904acd00a 100644 --- a/components/sceneutil/lightutil.cpp +++ b/components/sceneutil/lightutil.cpp @@ -73,7 +73,7 @@ namespace SceneUtil linearAttenuation = linearMethod == 0 ? linearValue : 0.01f; float r = radius * linearRadiusMult; if (r > 0.f && (linearMethod == 1 || linearMethod == 2)) - linearAttenuation = linearValue / std::pow(r, linearMethod); + linearAttenuation = linearValue / std::pow(r, static_cast(linearMethod)); } if (useQuadratic && (!outQuadInLin || isExterior)) @@ -81,7 +81,7 @@ namespace SceneUtil quadraticAttenuation = quadraticMethod == 0 ? quadraticValue : 0.01f; float r = radius * quadraticRadiusMult; if (r > 0.f && (quadraticMethod == 1 || quadraticMethod == 2)) - quadraticAttenuation = quadraticValue / std::pow(r, quadraticMethod); + quadraticAttenuation = quadraticValue / std::pow(r, static_cast(quadraticMethod)); } // If the values are still nonsense, try to at least prevent UB and disable attenuation diff --git a/components/sceneutil/mwshadowtechnique.cpp b/components/sceneutil/mwshadowtechnique.cpp index 7ee4fb9511..053650a4e3 100644 --- a/components/sceneutil/mwshadowtechnique.cpp +++ b/components/sceneutil/mwshadowtechnique.cpp @@ -3341,7 +3341,7 @@ void SceneUtil::MWShadowTechnique::DebugHUD::setFrustumVertices(osg::ref_ptrsetViewport(200 * shadowMapNumber, 0, 200, 200); diff --git a/components/sceneutil/mwshadowtechnique.hpp b/components/sceneutil/mwshadowtechnique.hpp index 1b7307024a..48b487649d 100644 --- a/components/sceneutil/mwshadowtechnique.hpp +++ b/components/sceneutil/mwshadowtechnique.hpp @@ -300,12 +300,12 @@ namespace SceneUtil { double _splitPointUniformLogRatio = 0.5; double _splitPointDeltaBias = 0.0; - float _polygonOffsetFactor = 1.1; - float _polygonOffsetUnits = 4.0; + float _polygonOffsetFactor = 1.f; + float _polygonOffsetUnits = 4.0f; bool _useFrontFaceCulling = true; - float _shadowFadeStart = 0.0; + float _shadowFadeStart = 0.0f; unsigned int _worldMask = ~0u; diff --git a/components/sceneutil/pathgridutil.cpp b/components/sceneutil/pathgridutil.cpp index 121ef068d8..5891783d3b 100644 --- a/components/sceneutil/pathgridutil.cpp +++ b/components/sceneutil/pathgridutil.cpp @@ -47,16 +47,19 @@ namespace SceneUtil void addPathgridToGeometry(const size_t vertexCount, const size_t pointIndexCount, const size_t edgeIndexCount, osg::ref_ptr& gridGeometry, const ESM::Pathgrid& pathgrid) { - osg::ref_ptr vertices = new osg::Vec3Array(vertexCount); - osg::ref_ptr colors = new osg::Vec4Array(vertexCount); - osg::ref_ptr pointIndices = new PType(osg::PrimitiveSet::TRIANGLES, pointIndexCount); - osg::ref_ptr lineIndices = new LType(osg::PrimitiveSet::LINES, edgeIndexCount); + assert(vertexCount < std::numeric_limits::max()); + assert(pointIndexCount < std::numeric_limits::max()); + 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)); // 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(point.mX, point.mY, 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; @@ -70,7 +73,7 @@ namespace SceneUtil for (unsigned short i = 0; i < DiamondIndexCount; ++i) { - pointIndices->setElement(indexOffset + i, vertexOffset + DiamondIndices[i]); + pointIndices->setElement(static_cast(indexOffset + i), static_cast(vertexOffset + DiamondIndices[i])); } // Connectors @@ -93,8 +96,8 @@ 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(from.mX, from.mY, from.mZ); - osg::Vec3f toPos = osg::Vec3f(to.mX, to.mY, 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(); @@ -138,9 +141,11 @@ namespace SceneUtil osg::ref_ptr& wireframeGeometry, const ESM::Pathgrid& pathgrid, const std::vector& selected) { - osg::ref_ptr vertices = new osg::Vec3Array(vertexCount); - osg::ref_ptr colors = new osg::Vec4Array(vertexCount); - osg::ref_ptr indices = new T(osg::PrimitiveSet::LINES, indexCount); + assert(vertexCount < std::numeric_limits::max()); + assert(indexCount < 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 indices = new T(osg::PrimitiveSet::LINES, static_cast(indexCount)); osg::Vec3f wireOffset = osg::Vec3f(0, 0, (1 - DiamondWireframeScalar) * DiamondHalfHeight); @@ -148,7 +153,7 @@ 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(point.mX, point.mY, 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; @@ -166,7 +171,7 @@ namespace SceneUtil for (unsigned short i = 0; i < DiamondWireframeIndexCount; ++i) { - indices->setElement(indexOffset + i, vertexOffset + DiamondWireframeIndices[i]); + indices->setElement(static_cast(indexOffset + i), static_cast(vertexOffset + DiamondWireframeIndices[i])); } } diff --git a/components/sceneutil/positionattitudetransform.cpp b/components/sceneutil/positionattitudetransform.cpp index 9e79d042f0..872f5c0827 100644 --- a/components/sceneutil/positionattitudetransform.cpp +++ b/components/sceneutil/positionattitudetransform.cpp @@ -34,13 +34,13 @@ namespace SceneUtil { matrix.postMultTranslate(-_position); matrix.postMultRotate(_attitude.inverse()); - matrix.postMultScale(osg::Vec3f(1.0 / _scale.x(), 1.0 / _scale.y(), 1.0 / _scale.z())); + matrix.postMultScale(osg::Vec3f(1.0f / _scale.x(), 1.0f / _scale.y(), 1.0f / _scale.z())); } else // absolute { matrix.makeRotate(_attitude.inverse()); matrix.preMultTranslate(-_position); - matrix.postMultScale(osg::Vec3f(1.0 / _scale.x(), 1.0 / _scale.y(), 1.0 / _scale.z())); + matrix.postMultScale(osg::Vec3f(1.0f / _scale.x(), 1.0f / _scale.y(), 1.0f / _scale.z())); } return true; } diff --git a/components/sceneutil/recastmesh.cpp b/components/sceneutil/recastmesh.cpp index 89712495f7..78bb26c162 100644 --- a/components/sceneutil/recastmesh.cpp +++ b/components/sceneutil/recastmesh.cpp @@ -32,7 +32,7 @@ namespace const osg::Vec3f e1 = v2 - v0; osg::Vec3f normal = e0 ^ e1; normal.normalize(); - for (std::size_t j = 0; j < 3; ++j) + for (int j = 0; j < 3; ++j) result[i + j] = normal[j]; } return result; diff --git a/components/sceneutil/shadow.cpp b/components/sceneutil/shadow.cpp index a03700578d..0e6abe3258 100644 --- a/components/sceneutil/shadow.cpp +++ b/components/sceneutil/shadow.cpp @@ -61,7 +61,7 @@ namespace SceneUtil else if (Misc::StringUtils::ciEqual(computeSceneBounds, "bounds")) mShadowSettings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES); - const int mapres = settings.mShadowMapResolution; + const short mapres = static_cast(settings.mShadowMapResolution); mShadowSettings->setTextureSize(osg::Vec2s(mapres, mapres)); mShadowTechnique->setSplitPointUniformLogarithmicRatio(settings.mSplitPointUniformLogarithmicRatio); diff --git a/components/sceneutil/statesetupdater.cpp b/components/sceneutil/statesetupdater.cpp index 42dab1cc98..03ab82d98c 100644 --- a/components/sceneutil/statesetupdater.cpp +++ b/components/sceneutil/statesetupdater.cpp @@ -88,14 +88,14 @@ namespace SceneUtil void CompositeStateSetUpdater::apply(osg::StateSet* stateset, osg::NodeVisitor* nv) { - for (unsigned int i = 0; i < mCtrls.size(); ++i) - mCtrls[i]->apply(stateset, nv); + for (const auto& ctrl : mCtrls) + ctrl->apply(stateset, nv); } void CompositeStateSetUpdater::setDefaults(osg::StateSet* stateset) { - for (unsigned int i = 0; i < mCtrls.size(); ++i) - mCtrls[i]->setDefaults(stateset); + for (const auto& ctrl : mCtrls) + ctrl->setDefaults(stateset); } CompositeStateSetUpdater::CompositeStateSetUpdater() {} @@ -103,16 +103,16 @@ namespace SceneUtil CompositeStateSetUpdater::CompositeStateSetUpdater(const CompositeStateSetUpdater& copy, const osg::CopyOp& copyop) : StateSetUpdater(copy, copyop) { - for (unsigned int i = 0; i < copy.mCtrls.size(); ++i) - mCtrls.emplace_back(osg::clone(copy.mCtrls[i].get(), copyop)); + for (const auto& ctrl : copy.mCtrls) + mCtrls.emplace_back(osg::clone(ctrl.get(), copyop)); } - unsigned int CompositeStateSetUpdater::getNumControllers() + size_t CompositeStateSetUpdater::getNumControllers() { return mCtrls.size(); } - StateSetUpdater* CompositeStateSetUpdater::getController(int i) + StateSetUpdater* CompositeStateSetUpdater::getController(size_t i) { return mCtrls[i]; } diff --git a/components/sceneutil/statesetupdater.hpp b/components/sceneutil/statesetupdater.hpp index 261721e3d6..5fa6f8a7c5 100644 --- a/components/sceneutil/statesetupdater.hpp +++ b/components/sceneutil/statesetupdater.hpp @@ -79,8 +79,8 @@ namespace SceneUtil META_Object(SceneUtil, CompositeStateSetUpdater) - unsigned int getNumControllers(); - StateSetUpdater* getController(int i); + size_t getNumControllers(); + StateSetUpdater* getController(size_t i); void addController(StateSetUpdater* ctrl); diff --git a/components/sceneutil/util.cpp b/components/sceneutil/util.cpp index e7a9cab730..185f90010e 100644 --- a/components/sceneutil/util.cpp +++ b/components/sceneutil/util.cpp @@ -131,8 +131,8 @@ namespace SceneUtil if ((mDuration >= 0) && mStartingTime == 0) mStartingTime = nv->getFrameStamp()->getSimulationTime(); - float time = nv->getFrameStamp()->getSimulationTime(); - int index = (int)(time * 16) % mTextures.size(); + double time = nv->getFrameStamp()->getSimulationTime(); + int index = static_cast(std::floor(time * 16)) % mTextures.size(); stateset->setTextureAttribute( mTexUnit, mTextures[index], osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); diff --git a/components/sceneutil/util.hpp b/components/sceneutil/util.hpp index 5a0280c661..dd29d46cb8 100644 --- a/components/sceneutil/util.hpp +++ b/components/sceneutil/util.hpp @@ -41,7 +41,7 @@ namespace SceneUtil float mDuration; float mOriginalDuration; // for recording that this is originally a permanent glow if it is changed to a // temporary one - float mStartingTime; + double mStartingTime; Resource::ResourceSystem* mResourceSystem; bool mColorChanged; bool mDone; diff --git a/components/sceneutil/waterutil.cpp b/components/sceneutil/waterutil.cpp index 7e739945aa..b5fe3019d3 100644 --- a/components/sceneutil/waterutil.cpp +++ b/components/sceneutil/waterutil.cpp @@ -58,7 +58,7 @@ 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, 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/sceneutil/workqueue.cpp b/components/sceneutil/workqueue.cpp index c398324aa9..7c24d6d384 100644 --- a/components/sceneutil/workqueue.cpp +++ b/components/sceneutil/workqueue.cpp @@ -99,13 +99,13 @@ namespace SceneUtil return nullptr; } - unsigned int WorkQueue::getNumItems() const + size_t WorkQueue::getNumItems() const { std::unique_lock lock(mMutex); return mQueue.size(); } - unsigned int WorkQueue::getNumActiveThreads() const + size_t WorkQueue::getNumActiveThreads() const { return std::accumulate( mThreads.begin(), mThreads.end(), 0u, [](auto r, const auto& t) { return r + t->isActive(); }); diff --git a/components/sceneutil/workqueue.hpp b/components/sceneutil/workqueue.hpp index d167c4d7e4..8d7f5a9ec9 100644 --- a/components/sceneutil/workqueue.hpp +++ b/components/sceneutil/workqueue.hpp @@ -62,9 +62,9 @@ namespace SceneUtil /// @par Used internally by the WorkThread. osg::ref_ptr removeWorkItem(); - unsigned int getNumItems() const; + size_t getNumItems() const; - unsigned int getNumActiveThreads() const; + size_t getNumActiveThreads() const; private: bool mIsReleased; diff --git a/components/shader/shadervisitor.cpp b/components/shader/shadervisitor.cpp index 0e6b5e79c6..40bba966d1 100644 --- a/components/shader/shadervisitor.cpp +++ b/components/shader/shadervisitor.cpp @@ -441,7 +441,7 @@ namespace Shader normalMapTex->setMaxAnisotropy(diffuseMap->getMaxAnisotropy()); normalMap = normalMapTex; - int unit = texAttributes.size(); + int unit = static_cast(texAttributes.size()); if (!writableStateSet) writableStateSet = getWritableStateSet(node); writableStateSet->setTextureAttributeAndModes(unit, normalMapTex, osg::StateAttribute::ON); @@ -487,7 +487,7 @@ namespace Shader osg::Texture::MAG_FILTER, diffuseMap->getFilter(osg::Texture::MAG_FILTER)); specularMapTex->setMaxAnisotropy(diffuseMap->getMaxAnisotropy()); - int unit = texAttributes.size(); + int unit = static_cast(texAttributes.size()); if (!writableStateSet) writableStateSet = getWritableStateSet(node); writableStateSet->setTextureAttributeAndModes(unit, specularMapTex, osg::StateAttribute::ON);