CScriptPlayerHint: Make use of std::any_of/std::find_if where applicable

Same behavior, can be simplified even further with ranges in the future.
This commit is contained in:
Lioncash 2020-04-12 14:00:31 -04:00
parent ff123f7820
commit 1d112134cf
1 changed files with 20 additions and 10 deletions

View File

@ -1,5 +1,7 @@
#include "Runtime/World/CScriptPlayerHint.hpp" #include "Runtime/World/CScriptPlayerHint.hpp"
#include <algorithm>
#include "Runtime/CStateManager.hpp" #include "Runtime/CStateManager.hpp"
#include "Runtime/MP1/World/CMetroidPrimeRelay.hpp" #include "Runtime/MP1/World/CMetroidPrimeRelay.hpp"
#include "Runtime/World/CActorParameters.hpp" #include "Runtime/World/CActorParameters.hpp"
@ -19,20 +21,28 @@ CScriptPlayerHint::CScriptPlayerHint(TUniqueId uid, std::string_view name, const
void CScriptPlayerHint::Accept(IVisitor& visit) { visit.Visit(this); } void CScriptPlayerHint::Accept(IVisitor& visit) { visit.Visit(this); }
void CScriptPlayerHint::AddToObjectList(TUniqueId uid) { void CScriptPlayerHint::AddToObjectList(TUniqueId uid) {
for (TUniqueId existId : xe8_objectList) const bool inList =
if (uid == existId) std::any_of(xe8_objectList.cbegin(), xe8_objectList.cend(), [uid](const auto id) { return id == uid; });
return; if (inList) {
if (xe8_objectList.size() != 8) return;
xe8_objectList.push_back(uid); }
if (xe8_objectList.size() == xe8_objectList.capacity()) {
return;
}
xe8_objectList.push_back(uid);
} }
void CScriptPlayerHint::RemoveFromObjectList(TUniqueId uid) { void CScriptPlayerHint::RemoveFromObjectList(TUniqueId uid) {
for (auto it = xe8_objectList.begin(); it != xe8_objectList.end(); ++it) { const auto iter =
if (*it == uid) { std::find_if(xe8_objectList.cbegin(), xe8_objectList.cend(), [uid](const auto id) { return id == uid; });
xe8_objectList.erase(it);
return; if (iter == xe8_objectList.cend()) {
} return;
} }
xe8_objectList.erase(iter);
} }
void CScriptPlayerHint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) { void CScriptPlayerHint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) {