From fc2076db1a3bc57f031f6680a0aad31295530669 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 29 Sep 2021 11:36:05 +0400 Subject: [PATCH] Fix MSVC warnings about local variables redeclaration (#3130) --- apps/openmw/mwmechanics/actors.cpp | 2 +- apps/openmw/mwphysics/physicssystem.cpp | 50 +++++++++---------- apps/openmw/mwrender/renderingmanager.cpp | 1 - apps/openmw/mwworld/scene.cpp | 6 +-- components/detournavigator/navigatorimpl.cpp | 4 +- .../detournavigator/recastmeshbuilder.cpp | 24 ++++----- components/sceneutil/recastmesh.cpp | 6 +-- 7 files changed, 46 insertions(+), 47 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index f4cb40c2f5..542f185854 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1171,7 +1171,7 @@ namespace MWMechanics creatureStats.setAiSetting(CreatureStats::AI_Flee, stat); if (creature && ptr.get()->mBase->mData.mType == ESM::Creature::Undead) { - Stat stat = creatureStats.getAiSetting(CreatureStats::AI_Flee); + stat = creatureStats.getAiSetting(CreatureStats::AI_Flee); stat.setModifier(static_cast(effects.get(ESM::MagicEffect::TurnUndead).getMagnitude())); creatureStats.setAiSetting(CreatureStats::AI_Flee, stat); } diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 8499dc74c1..903e383370 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -514,18 +514,18 @@ namespace MWPhysics void PhysicsSystem::remove(const MWWorld::Ptr &ptr) { - if (auto found = mObjects.find(ptr.mRef); found != mObjects.end()) + if (auto foundObject = mObjects.find(ptr.mRef); foundObject != mObjects.end()) { if (mUnrefQueue.get()) - mUnrefQueue->push(found->second->getShapeInstance()); + mUnrefQueue->push(foundObject->second->getShapeInstance()); - mAnimatedObjects.erase(found->second.get()); + mAnimatedObjects.erase(foundObject->second.get()); - mObjects.erase(found); + mObjects.erase(foundObject); } - else if (auto found = mActors.find(ptr.mRef); found != mActors.end()) + else if (auto foundActor = mActors.find(ptr.mRef); foundActor != mActors.end()) { - mActors.erase(found); + mActors.erase(foundActor); } } @@ -591,16 +591,16 @@ namespace MWPhysics void PhysicsSystem::updateScale(const MWWorld::Ptr &ptr) { - if (auto found = mObjects.find(ptr.mRef); found != mObjects.end()) + if (auto foundObject = mObjects.find(ptr.mRef); foundObject != mObjects.end()) { float scale = ptr.getCellRef().getScale(); - found->second->setScale(scale); - mTaskScheduler->updateSingleAabb(found->second); + foundObject->second->setScale(scale); + mTaskScheduler->updateSingleAabb(foundObject->second); } - else if (auto found = mActors.find(ptr.mRef); found != mActors.end()) + else if (auto foundActor = mActors.find(ptr.mRef); foundActor != mActors.end()) { - found->second->updateScale(); - mTaskScheduler->updateSingleAabb(found->second); + foundActor->second->updateScale(); + mTaskScheduler->updateSingleAabb(foundActor->second); } } @@ -633,32 +633,32 @@ namespace MWPhysics void PhysicsSystem::updateRotation(const MWWorld::Ptr &ptr, osg::Quat rotate) { - if (auto found = mObjects.find(ptr.mRef); found != mObjects.end()) + if (auto foundObject = mObjects.find(ptr.mRef); foundObject != mObjects.end()) { - found->second->setRotation(rotate); - mTaskScheduler->updateSingleAabb(found->second); + foundObject->second->setRotation(rotate); + mTaskScheduler->updateSingleAabb(foundObject->second); } - else if (auto found = mActors.find(ptr.mRef); found != mActors.end()) + else if (auto foundActor = mActors.find(ptr.mRef); foundActor != mActors.end()) { - if (!found->second->isRotationallyInvariant()) + if (!foundActor->second->isRotationallyInvariant()) { - found->second->setRotation(rotate); - mTaskScheduler->updateSingleAabb(found->second); + foundActor->second->setRotation(rotate); + mTaskScheduler->updateSingleAabb(foundActor->second); } } } void PhysicsSystem::updatePosition(const MWWorld::Ptr &ptr) { - if (auto found = mObjects.find(ptr.mRef); found != mObjects.end()) + if (auto foundObject = mObjects.find(ptr.mRef); foundObject != mObjects.end()) { - found->second->updatePosition(); - mTaskScheduler->updateSingleAabb(found->second); + foundObject->second->updatePosition(); + mTaskScheduler->updateSingleAabb(foundObject->second); } - else if (auto found = mActors.find(ptr.mRef); found != mActors.end()) + else if (auto foundActor = mActors.find(ptr.mRef); foundActor != mActors.end()) { - found->second->updatePosition(); - mTaskScheduler->updateSingleAabb(found->second, true); + foundActor->second->updatePosition(); + mTaskScheduler->updateSingleAabb(foundActor->second, true); } } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 74e183693c..5661ecfbe7 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -440,7 +440,6 @@ namespace MWRender static_cast(mTerrain.get())->addChunkManager(mGroundcover.get()); mResourceSystem->addResourceManager(mGroundcover.get()); - float groundcoverDistance = std::max(0.f, Settings::Manager::getFloat("rendering distance", "Groundcover")); mGroundcover->setViewDistance(groundcoverDistance); } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index e52f5532b4..559ab4aef4 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -917,9 +917,9 @@ namespace MWWorld // unload for (auto iter = mInactiveCells.begin(); iter!=mInactiveCells.end(); ) { - auto* cell = *iter++; - deactivateCell(cell); - unloadInactiveCell(cell); + auto* cellToUnload = *iter++; + deactivateCell(cellToUnload); + unloadInactiveCell(cellToUnload); } assert(mActiveCells.empty()); assert(mInactiveCells.empty()); diff --git a/components/detournavigator/navigatorimpl.cpp b/components/detournavigator/navigatorimpl.cpp index 5a8488c8d0..750901c73e 100644 --- a/components/detournavigator/navigatorimpl.cpp +++ b/components/detournavigator/navigatorimpl.cpp @@ -39,8 +39,8 @@ namespace DetourNavigator if (const btCollisionShape* const avoidShape = shapes.mShapeInstance->getAvoidCollisionShape()) { const ObjectId avoidId(avoidShape); - CollisionShape collisionShape {shapes.mShapeInstance, *avoidShape}; - if (mNavMeshManager.addObject(avoidId, collisionShape, transform, AreaType_null)) + CollisionShape avoidCollisionShape {shapes.mShapeInstance, *avoidShape}; + if (mNavMeshManager.addObject(avoidId, avoidCollisionShape, transform, AreaType_null)) { updateAvoidShapeId(id, avoidId); result = true; diff --git a/components/detournavigator/recastmeshbuilder.cpp b/components/detournavigator/recastmeshbuilder.cpp index 19125e0a9b..73b731c247 100644 --- a/components/detournavigator/recastmeshbuilder.cpp +++ b/components/detournavigator/recastmeshbuilder.cpp @@ -49,9 +49,9 @@ namespace DetourNavigator std::vector uniqueVertices; uniqueVertices.reserve(3 * triangles.size()); - for (const RecastMeshTriangle& v : triangles) - for (const osg::Vec3f& v : v.mVertices) - uniqueVertices.push_back(v); + for (const RecastMeshTriangle& triangle : triangles) + for (const osg::Vec3f& vertex : triangle.mVertices) + uniqueVertices.push_back(vertex); std::sort(uniqueVertices.begin(), uniqueVertices.end()); uniqueVertices.erase(std::unique(uniqueVertices.begin(), uniqueVertices.end()), uniqueVertices.end()); @@ -61,15 +61,15 @@ namespace DetourNavigator std::vector areaTypes; areaTypes.reserve(triangles.size()); - for (const RecastMeshTriangle& v : triangles) + for (const RecastMeshTriangle& triangle : triangles) { - areaTypes.push_back(v.mAreaType); + areaTypes.push_back(triangle.mAreaType); - for (const osg::Vec3f& v : v.mVertices) + for (const osg::Vec3f& vertex : triangle.mVertices) { - const auto it = std::lower_bound(uniqueVertices.begin(), uniqueVertices.end(), v); + const auto it = std::lower_bound(uniqueVertices.begin(), uniqueVertices.end(), vertex); assert(it != uniqueVertices.end()); - assert(*it == v); + assert(*it == vertex); indices.push_back(static_cast(it - uniqueVertices.begin())); } } @@ -79,11 +79,11 @@ namespace DetourNavigator std::vector vertices; vertices.reserve(3 * uniqueVertices.size()); - for (const osg::Vec3f& v : uniqueVertices) + for (const osg::Vec3f& vertex : uniqueVertices) { - vertices.push_back(v.x() + shift.x()); - vertices.push_back(v.y() + shift.y()); - vertices.push_back(v.z() + shift.z()); + vertices.push_back(vertex.x() + shift.x()); + vertices.push_back(vertex.y() + shift.y()); + vertices.push_back(vertex.z() + shift.z()); } return Mesh(std::move(indices), std::move(vertices), std::move(areaTypes)); diff --git a/components/sceneutil/recastmesh.cpp b/components/sceneutil/recastmesh.cpp index 8d6d47c2b6..97efe010df 100644 --- a/components/sceneutil/recastmesh.cpp +++ b/components/sceneutil/recastmesh.cpp @@ -52,10 +52,10 @@ namespace SceneUtil for (const Heightfield& heightfield : recastMesh.getHeightfields()) { - const Mesh mesh = makeMesh(heightfield); + const Mesh heightfieldMesh = makeMesh(heightfield); const int indexShift = static_cast(vertices.size() / 3); - std::copy(mesh.getVertices().begin(), mesh.getVertices().end(), std::back_inserter(vertices)); - std::transform(mesh.getIndices().begin(), mesh.getIndices().end(), std::back_inserter(indices), + std::copy(heightfieldMesh.getVertices().begin(), heightfieldMesh.getVertices().end(), std::back_inserter(vertices)); + std::transform(heightfieldMesh.getIndices().begin(), heightfieldMesh.getIndices().end(), std::back_inserter(indices), [&] (int index) { return index + indexShift; }); }