From b3fcbf9a89d5f9fceda064ddd11587851d55aa70 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 20 Jan 2020 12:51:50 -0500 Subject: [PATCH 1/2] CCameraManager: Resolve signed/unsigned mismatch in RemoveCameraShaker An unsigned value is passed into RemoveCameraShaker at its only usage spot. This also resolves unsigned/signed comparisons within the function itself. --- Runtime/Camera/CCameraManager.cpp | 2 +- Runtime/Camera/CCameraManager.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/Camera/CCameraManager.cpp b/Runtime/Camera/CCameraManager.cpp index 6dc75e1b4..0483eed35 100644 --- a/Runtime/Camera/CCameraManager.cpp +++ b/Runtime/Camera/CCameraManager.cpp @@ -37,7 +37,7 @@ zeus::CTransform CCameraManager::GetCurrentCameraTransform(const CStateManager& return camera->GetTransform() * zeus::CTransform::Translate(x30_shakeOffset); } -void CCameraManager::RemoveCameraShaker(int id) { +void CCameraManager::RemoveCameraShaker(u32 id) { for (auto it = x14_shakers.begin(); it != x14_shakers.end(); ++it) if (it->xbc_shakerId == id) { x14_shakers.erase(it); diff --git a/Runtime/Camera/CCameraManager.hpp b/Runtime/Camera/CCameraManager.hpp index fc15fb179..365a0742a 100644 --- a/Runtime/Camera/CCameraManager.hpp +++ b/Runtime/Camera/CCameraManager.hpp @@ -94,7 +94,7 @@ public: bool IsInFirstPersonCamera() const; zeus::CVector3f GetGlobalCameraTranslation(const CStateManager& stateMgr) const; zeus::CTransform GetCurrentCameraTransform(const CStateManager& stateMgr) const; - void RemoveCameraShaker(int id); + void RemoveCameraShaker(u32 id); int AddCameraShaker(const CCameraShakeData& data, bool sfx); void AddCinemaCamera(TUniqueId, CStateManager& stateMgr); void RemoveCinemaCamera(TUniqueId, CStateManager&); From b847930a85af1ad2e504664b5f941d358b8e5c33 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 20 Jan 2020 12:57:21 -0500 Subject: [PATCH 2/2] CCameraManager: Collapse loop into std::find_if in RemoveCameraShaker We can collapse the loop into a find_if call here, since it only does a look up and nothing more. --- Runtime/Camera/CCameraManager.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Runtime/Camera/CCameraManager.cpp b/Runtime/Camera/CCameraManager.cpp index 0483eed35..4ee95c092 100644 --- a/Runtime/Camera/CCameraManager.cpp +++ b/Runtime/Camera/CCameraManager.cpp @@ -1,5 +1,7 @@ #include "Runtime/Camera/CCameraManager.hpp" +#include + #include "Runtime/CStateManager.hpp" #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Camera/CBallCamera.hpp" @@ -38,11 +40,12 @@ zeus::CTransform CCameraManager::GetCurrentCameraTransform(const CStateManager& } void CCameraManager::RemoveCameraShaker(u32 id) { - for (auto it = x14_shakers.begin(); it != x14_shakers.end(); ++it) - if (it->xbc_shakerId == id) { - x14_shakers.erase(it); - break; - } + const auto iter = std::find_if(x14_shakers.cbegin(), x14_shakers.cend(), + [id](const auto& shaker) { return shaker.xbc_shakerId == id; }); + if (iter == x14_shakers.cend()) { + return; + } + x14_shakers.erase(iter); } int CCameraManager::AddCameraShaker(const CCameraShakeData& data, bool sfx) {