Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/ObjectManager.cpp
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | if (!actor->Load(pathname)) | ||||
LOGERROR("CObjectManager::FindActorDef(): Cannot find actor '%s'", utf8_from_wstring(actorName)); | LOGERROR("CObjectManager::FindActorDef(): Cannot find actor '%s'", utf8_from_wstring(actorName)); | ||||
actor->LoadErrorPlaceholder(pathname); | actor->LoadErrorPlaceholder(pathname); | ||||
success = false; | success = false; | ||||
} | } | ||||
return { success, *m_ActorDefs.insert_or_assign(actorName, std::move(actor)).first->second.obj }; | return { success, *m_ActorDefs.insert_or_assign(actorName, std::move(actor)).first->second.obj }; | ||||
} | } | ||||
CObjectEntry* CObjectManager::FindObjectVariation(const CActorDef* actor, const std::vector<std::set<CStr>>& selections, uint32_t seed) | std::vector<CObjectEntry*> CObjectManager::FindObjectVariations(const CActorDef& actor, const std::vector<std::set<CStr>>& selections, uint32_t seed) | ||||
{ | { | ||||
if (!actor) | std::vector<CObjectEntry*> ret; | ||||
return nullptr; | |||||
const std::shared_ptr<CObjectBase>& base = actor->GetBase(m_QualityLevel); | |||||
std::vector<const std::set<CStr>*> completeSelections; | std::vector<const std::set<CStr>*> completeSelections; | ||||
for (const std::set<CStr>& selectionSet : selections) | for (const std::set<CStr>& selectionSet : selections) | ||||
completeSelections.emplace_back(&selectionSet); | completeSelections.emplace_back(&selectionSet); | ||||
std::vector<std::shared_ptr<CObjectBase>>::const_iterator it = actor.m_ObjectBases.begin(); | |||||
// Must exist. | |||||
ENSURE(actor.m_ObjectBases.size() > 0); | |||||
std::vector<std::shared_ptr<CObjectBase>>::const_iterator highestQual = --actor.m_ObjectBases.end(); | |||||
// To maintain a consistent look between quality levels, first complete with the highest-quality variants. | // To maintain a consistent look between quality levels, first complete with the highest-quality variants. | ||||
// then complete again at the required quality level (since not all variants may be available). | // then complete again at the required quality level (since not all variants may be available). | ||||
std::set<CStr> highQualitySelections = actor->GetBase(255)->CalculateRandomRemainingSelections(seed, selections); | const std::shared_ptr<CObjectBase>& highQualityBase = *highestQual; | ||||
std::set<CStr> highQualitySelections = highQualityBase->CalculateRandomRemainingSelections(seed, selections); | |||||
completeSelections.emplace_back(&highQualitySelections); | completeSelections.emplace_back(&highQualitySelections); | ||||
// We don't have to pass the high-quality selections here because they have higher priority anyways. | |||||
std::vector<std::shared_ptr<CObjectBase>>::const_iterator maxQuality = actor.GetBaseIterator(m_QualityLevel); | |||||
while (true) | |||||
{ | |||||
const std::shared_ptr<CObjectBase>& base = *it; | |||||
std::set<CStr> remainingSelections = base->CalculateRandomRemainingSelections(seed, selections); | std::set<CStr> remainingSelections = base->CalculateRandomRemainingSelections(seed, selections); | ||||
completeSelections.emplace_back(&remainingSelections); | completeSelections.emplace_back(&remainingSelections); | ||||
return FindObjectVariation(base, completeSelections); | CObjectEntry* entry = FindObjectVariation(base, completeSelections); | ||||
if (entry) | |||||
ret.push_back(entry); | |||||
completeSelections.pop_back(); | |||||
if (it++ == maxQuality) | |||||
Stan: Can't it be the loop condition? | |||||
Done Inline ActionsNo, the loop needs to run once anyways, but I need to check the pre-incremented value. It's plausible that I'm missing an obvious way to do this, but I didn't find an easier one. wraitii: No, the loop needs to run once anyways, but I need to check the pre-incremented value.
It's… | |||||
break; | |||||
} | |||||
return ret; | |||||
} | } | ||||
CObjectEntry* CObjectManager::FindObjectVariation(const std::shared_ptr<CObjectBase>& base, const std::vector<const std::set<CStr>*>& completeSelections) | CObjectEntry* CObjectManager::FindObjectVariation(const std::shared_ptr<CObjectBase>& base, const std::vector<const std::set<CStr>*>& completeSelections) | ||||
{ | { | ||||
PROFILE2("FindObjectVariation"); | PROFILE2("FindObjectVariation"); | ||||
// Look to see whether this particular variation has already been loaded | // Look to see whether this particular variation has already been loaded | ||||
std::vector<u8> choices = base->CalculateVariationKey(completeSelections); | std::vector<u8> choices = base->CalculateVariationKey(completeSelections); | ||||
▲ Show 20 Lines • Show All 75 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Can't it be the loop condition?