Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/ObjectBase.cpp
Show First 20 Lines • Show All 774 Lines • ▼ Show 20 Lines | std::vector<u8> CActorDef::QualityLevels() const | ||||
splits.reserve(m_ObjectBases.size()); | splits.reserve(m_ObjectBases.size()); | ||||
for (const std::shared_ptr<CObjectBase>& base : m_ObjectBases) | for (const std::shared_ptr<CObjectBase>& base : m_ObjectBases) | ||||
splits.emplace_back(base->m_QualityLevel); | splits.emplace_back(base->m_QualityLevel); | ||||
return splits; | return splits; | ||||
} | } | ||||
const std::shared_ptr<CObjectBase>& CActorDef::GetBase(u8 QualityLevel) const | const std::shared_ptr<CObjectBase>& CActorDef::GetBase(u8 QualityLevel) const | ||||
{ | { | ||||
for (const std::shared_ptr<CObjectBase>& base : m_ObjectBases) | // Must return something once the actor is initialised, so dereferencing is safe. | ||||
if (base->m_QualityLevel >= QualityLevel) | return *GetBaseIterator(QualityLevel); | ||||
return base; | } | ||||
std::vector<std::shared_ptr<CObjectBase>>::const_iterator CActorDef::GetBaseIterator(u8 QualityLevel) const | |||||
{ | |||||
for (std::vector<std::shared_ptr<CObjectBase>>::const_iterator it = m_ObjectBases.begin(); it != m_ObjectBases.end(); ++it) | |||||
if ((*it)->m_QualityLevel >= QualityLevel) | |||||
return it; | |||||
// This code path ought to be impossible to take, | // This code path ought to be impossible to take, | ||||
// because by construction we must have at least one valid CObjectBase of quality MAX_QUALITY | // because by construction we must have at least one valid CObjectBase of quality MAX_QUALITY | ||||
// (which necessarily fits the u8 comparison above). | // (which necessarily fits the u8 comparison above). | ||||
// However compilers will warn that we return a reference to a local temporary if I return nullptr, | // However compilers will warn that we return a reference to a local temporary if I return nullptr, | ||||
// so just return something sane instead. | // so just return something sane instead. | ||||
ENSURE(false); | ENSURE(false); | ||||
return m_ObjectBases.back(); | return m_ObjectBases.end(); | ||||
Stan: Can't we use std::find in that function? | |||||
} | } | ||||
bool CActorDef::Load(const VfsPath& pathname) | bool CActorDef::Load(const VfsPath& pathname) | ||||
{ | { | ||||
m_UsedFiles.clear(); | m_UsedFiles.clear(); | ||||
m_UsedFiles.insert(pathname); | m_UsedFiles.insert(pathname); | ||||
m_ObjectBases.clear(); | m_ObjectBases.clear(); | ||||
▲ Show 20 Lines • Show All 197 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Can't we use std::find in that function?