Merge pull request #227 from lioncash/pair

CAnimSourceReader: Minor cleanup
This commit is contained in:
Luke Street 2020-03-15 19:46:21 -04:00 committed by GitHub
commit 76f12c5c38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 41 additions and 21 deletions

View File

@ -1,5 +1,7 @@
#include "Runtime/Character/CAnimSourceReader.hpp" #include "Runtime/Character/CAnimSourceReader.hpp"
#include <algorithm>
#include "Runtime/Character/CBoolPOINode.hpp" #include "Runtime/Character/CBoolPOINode.hpp"
#include "Runtime/Character/CFBStreamedAnimReader.hpp" #include "Runtime/Character/CFBStreamedAnimReader.hpp"
#include "Runtime/Character/CInt32POINode.hpp" #include "Runtime/Character/CInt32POINode.hpp"
@ -27,27 +29,33 @@ CCharAnimTime CAnimSourceInfo::GetAnimationDuration() const { return x4_token->G
std::set<std::pair<std::string, s32>> CAnimSourceReaderBase::GetUniqueParticlePOIs() const { std::set<std::pair<std::string, s32>> CAnimSourceReaderBase::GetUniqueParticlePOIs() const {
const std::vector<CParticlePOINode>& particleNodes = x4_sourceInfo->GetParticlePOIStream(); const std::vector<CParticlePOINode>& particleNodes = x4_sourceInfo->GetParticlePOIStream();
std::set<std::pair<std::string, s32>> ret; std::set<std::pair<std::string, s32>> ret;
for (const CParticlePOINode& node : particleNodes) for (const CParticlePOINode& node : particleNodes) {
if (node.GetUnique()) if (node.GetUnique()) {
ret.insert(std::make_pair(std::string(node.GetString()), node.GetIndex())); ret.emplace(node.GetString(), node.GetIndex());
}
}
return ret; return ret;
} }
std::set<std::pair<std::string, s32>> CAnimSourceReaderBase::GetUniqueInt32POIs() const { std::set<std::pair<std::string, s32>> CAnimSourceReaderBase::GetUniqueInt32POIs() const {
const std::vector<CInt32POINode>& int32Nodes = x4_sourceInfo->GetInt32POIStream(); const std::vector<CInt32POINode>& int32Nodes = x4_sourceInfo->GetInt32POIStream();
std::set<std::pair<std::string, s32>> ret; std::set<std::pair<std::string, s32>> ret;
for (const CInt32POINode& node : int32Nodes) for (const CInt32POINode& node : int32Nodes) {
if (node.GetUnique()) if (node.GetUnique()) {
ret.insert(std::make_pair(std::string(node.GetString()), node.GetIndex())); ret.emplace(node.GetString(), node.GetIndex());
}
}
return ret; return ret;
} }
std::set<std::pair<std::string, s32>> CAnimSourceReaderBase::GetUniqueBoolPOIs() const { std::set<std::pair<std::string, s32>> CAnimSourceReaderBase::GetUniqueBoolPOIs() const {
const std::vector<CBoolPOINode>& boolNodes = x4_sourceInfo->GetBoolPOIStream(); const std::vector<CBoolPOINode>& boolNodes = x4_sourceInfo->GetBoolPOIStream();
std::set<std::pair<std::string, s32>> ret; std::set<std::pair<std::string, s32>> ret;
for (const CBoolPOINode& node : boolNodes) for (const CBoolPOINode& node : boolNodes) {
if (node.GetUnique()) if (node.GetUnique()) {
ret.insert(std::make_pair(std::string(node.GetString()), node.GetIndex())); ret.emplace(node.GetString(), node.GetIndex());
}
}
return ret; return ret;
} }
@ -165,26 +173,38 @@ u32 CAnimSourceReaderBase::VGetSoundPOIList(const CCharAnimTime& time, CSoundPOI
} }
bool CAnimSourceReaderBase::VGetBoolPOIState(const char* name) const { bool CAnimSourceReaderBase::VGetBoolPOIState(const char* name) const {
for (const auto& node : x24_boolStates) const auto iter = std::find_if(x24_boolStates.cbegin(), x24_boolStates.cend(),
if (node.first == name) [name](const auto& entry) { return entry.first == name; });
return node.second;
if (iter == x24_boolStates.cend()) {
return false; return false;
} }
return iter->second;
}
s32 CAnimSourceReaderBase::VGetInt32POIState(const char* name) const { s32 CAnimSourceReaderBase::VGetInt32POIState(const char* name) const {
for (const auto& node : x34_int32States) const auto iter = std::find_if(x34_int32States.cbegin(), x34_int32States.cend(),
if (node.first == name) [name](const auto& entry) { return entry.first == name; });
return node.second;
if (iter == x34_int32States.cend()) {
return 0; return 0;
} }
return iter->second;
}
CParticleData::EParentedMode CAnimSourceReaderBase::VGetParticlePOIState(const char* name) const { CParticleData::EParentedMode CAnimSourceReaderBase::VGetParticlePOIState(const char* name) const {
for (const auto& node : x44_particleStates) const auto iter = std::find_if(x44_particleStates.cbegin(), x44_particleStates.cend(),
if (node.first == name) [name](const auto& entry) { return entry.first == name; });
return node.second;
if (iter == x44_particleStates.cend()) {
return CParticleData::EParentedMode::Initial; return CParticleData::EParentedMode::Initial;
} }
return iter->second;
}
CAnimSourceReaderBase::CAnimSourceReaderBase(std::unique_ptr<IAnimSourceInfo>&& sourceInfo, const CCharAnimTime& time) CAnimSourceReaderBase::CAnimSourceReaderBase(std::unique_ptr<IAnimSourceInfo>&& sourceInfo, const CCharAnimTime& time)
: x4_sourceInfo(std::move(sourceInfo)), xc_curTime(time) {} : x4_sourceInfo(std::move(sourceInfo)), xc_curTime(time) {}