Move expensive questIndicatorPosition() call

need to optimize Object configValue at some point
This commit is contained in:
Kae 2023-07-01 08:01:29 +10:00
parent c48a61bb03
commit ce68aad078

View File

@ -276,12 +276,11 @@ Maybe<QuestPtr> QuestManager::trackedQuest() const {
Maybe<QuestIndicator> QuestManager::getQuestIndicator(EntityPtr const& entity) const { Maybe<QuestIndicator> QuestManager::getQuestIndicator(EntityPtr const& entity) const {
Maybe<String> indicatorType; Maybe<String> indicatorType;
Vec2F indicatorPos = entity->position() + Vec2F(0, 2.75); Vec2F indicatorPos = entity->position() + Vec2F(0, 2.75);
auto questGiver = as<InteractiveEntity>(entity);
if (auto questGiver = as<InteractiveEntity>(entity)) { if (questGiver) {
indicatorPos = questGiver->questIndicatorPosition();
if (!indicatorType) { if (!indicatorType) {
for (auto questId : questGiver->turnInQuests()) { for (auto& questId : questGiver->turnInQuests()) {
if (!isActive(questId)) if (!isActive(questId))
continue; continue;
auto quest = getQuest(questId); auto quest = getQuest(questId);
@ -294,9 +293,9 @@ Maybe<QuestIndicator> QuestManager::getQuestIndicator(EntityPtr const& entity) c
if (!indicatorType) { if (!indicatorType) {
auto questTemplateDatabase = Root::singleton().questTemplateDatabase(); auto questTemplateDatabase = Root::singleton().questTemplateDatabase();
for (auto questArc : questGiver->offeredQuests()) { for (auto& questArc : questGiver->offeredQuests()) {
if (canStart(questArc) && questArc.quests.size() > 0) { if (canStart(questArc) && questArc.quests.size() > 0) {
auto questDesc = questArc.quests[0]; auto& questDesc = questArc.quests[0];
auto questTemplate = questTemplateDatabase->questTemplate(questDesc.templateId); auto questTemplate = questTemplateDatabase->questTemplate(questDesc.templateId);
indicatorType = questTemplate->questGiverIndicator; indicatorType = questTemplate->questGiverIndicator;
break; break;
@ -308,13 +307,18 @@ Maybe<QuestIndicator> QuestManager::getQuestIndicator(EntityPtr const& entity) c
if (indicatorType) { if (indicatorType) {
Json indicators = Root::singleton().assets()->json("/quests/quests.config:indicators"); Json indicators = Root::singleton().assets()->json("/quests/quests.config:indicators");
String indicatorImage = indicators.get(*indicatorType).getString("image"); String indicatorImage = indicators.get(*indicatorType).getString("image");
if (questGiver)
indicatorPos = questGiver->questIndicatorPosition();
return QuestIndicator{indicatorImage, indicatorPos}; return QuestIndicator{indicatorImage, indicatorPos};
} }
for (auto& pair : m_quests) { for (auto& pair : m_quests) {
if (pair.second->state() == QuestState::Active) { if (pair.second->state() == QuestState::Active) {
if (auto indicatorImage = pair.second->customIndicator(entity)) if (auto indicatorImage = pair.second->customIndicator(entity)) {
if (questGiver)
indicatorPos = questGiver->questIndicatorPosition();
return QuestIndicator{ *indicatorImage, indicatorPos }; return QuestIndicator{ *indicatorImage, indicatorPos };
}
} }
} }