From d6ad152a9749ad29db3c97c0444bf1adcd495f58 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 7 May 2020 07:51:48 -0400 Subject: [PATCH] CScriptCameraHint: Brace statements where applicable Makes code consistent. --- Runtime/World/CScriptCameraHint.cpp | 45 +++++++++++++++++++---------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/Runtime/World/CScriptCameraHint.cpp b/Runtime/World/CScriptCameraHint.cpp index 973174ff9..2ff3b5788 100644 --- a/Runtime/World/CScriptCameraHint.cpp +++ b/Runtime/World/CScriptCameraHint.cpp @@ -29,20 +29,26 @@ void CScriptCameraHint::InitializeInArea(CStateManager& mgr) { x164_delegatedCamera = kInvalidUniqueId; for (CEntity* ent : mgr.GetAllObjectList()) { for (const SConnection& conn : ent->GetConnectionList()) { - if (mgr.GetIdForScript(conn.x8_objId) != GetUniqueId()) + if (mgr.GetIdForScript(conn.x8_objId) != GetUniqueId()) { continue; - if (conn.x4_msg != EScriptObjectMessage::Increment && conn.x4_msg != EScriptObjectMessage::Decrement) + } + if (conn.x4_msg != EScriptObjectMessage::Increment && conn.x4_msg != EScriptObjectMessage::Decrement) { continue; + } for (auto it = ent->GetConnectionList().begin(); it != ent->GetConnectionList().end(); ++it) { const SConnection& conn2 = *it; - if (conn2.x4_msg != EScriptObjectMessage::Increment && conn2.x4_msg != EScriptObjectMessage::Decrement) + if (conn2.x4_msg != EScriptObjectMessage::Increment && conn2.x4_msg != EScriptObjectMessage::Decrement) { continue; - TUniqueId id = mgr.GetIdForScript(conn2.x8_objId); - if (TCastToPtr(mgr.ObjectById(id)) || TCastToPtr(mgr.ObjectById((id)))) { + } + + const TUniqueId id = mgr.GetIdForScript(conn2.x8_objId); + const auto* const obj = mgr.ObjectById(id); + if (TCastToConstPtr(obj) || TCastToConstPtr(obj)) { it = ent->GetConnectionList().erase(it); - if (x164_delegatedCamera != id) + if (x164_delegatedCamera != id) { x164_delegatedCamera = id; + } break; } } @@ -52,17 +58,25 @@ void CScriptCameraHint::InitializeInArea(CStateManager& mgr) { } void CScriptCameraHint::AddHelper(TUniqueId id) { - auto search = std::find_if(x150_helpers.begin(), x150_helpers.end(), [id](TUniqueId tid) { return tid == id; }); - if (search == x150_helpers.end()) - x150_helpers.push_back(id); + const auto search = + std::find_if(x150_helpers.cbegin(), x150_helpers.cend(), [id](TUniqueId tid) { return tid == id; }); + + if (search != x150_helpers.end()) { + return; + } + + x150_helpers.push_back(id); } void CScriptCameraHint::RemoveHelper(TUniqueId id) { - auto search = std::find_if(x150_helpers.begin(), x150_helpers.end(), [id](TUniqueId tid) { return tid == id; }); - if (search != x150_helpers.end()) + const auto search = + std::find_if(x150_helpers.cbegin(), x150_helpers.cend(), [id](TUniqueId tid) { return tid == id; }); + + if (search != x150_helpers.cend()) { x150_helpers.erase(search); - else + } else { x150_helpers.pop_front(); + } } void CScriptCameraHint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) { @@ -96,13 +110,14 @@ void CScriptCameraHint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId send if (msg == EScriptObjectMessage::Follow) { if (!GetActive()) { - if (TCastToConstPtr act = mgr.GetObjectById(sender)) { + if (const TCastToConstPtr act = mgr.GetObjectById(sender)) { zeus::CVector3f followerToThisFlat = x168_origXf.origin - act->GetTranslation(); followerToThisFlat.z() = 0.f; - if (followerToThisFlat.canBeNormalized()) + if (followerToThisFlat.canBeNormalized()) { followerToThisFlat.normalize(); - else + } else { followerToThisFlat = act->GetTransform().basis[1]; + } zeus::CVector3f target = act->GetTranslation() + followerToThisFlat; target.z() = x168_origXf.origin.z() + followerToThisFlat.z(); SetTransform(zeus::lookAt(act->GetTranslation(), target));