From 419046e121612ea90e0808bc1fc6cd6f6e1bba15 Mon Sep 17 00:00:00 2001 From: Jordan Ayers Date: Sat, 11 Oct 2014 12:30:24 -0500 Subject: [PATCH] Dialogue: Use std::set for known topics in the manager. There were three different data structures being used for topic lists in this code. (map< string, true >, list< string >, and vector< string >) Switch the local topic lists to set< string >. This supports everything the list and map were doing, reduces the variety of data structures, and makes count (a more efficient search) available. The vector has not changed, since it's tied to the ESM modules, and must meet other requirements. --- apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 20 ++++++++++--------- apps/openmw/mwdialogue/dialoguemanagerimp.hpp | 6 +++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index d2534cd82..1d1f655aa 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -78,7 +79,7 @@ namespace MWDialogue void DialogueManager::addTopic (const std::string& topic) { - mKnownTopics[Misc::StringUtils::lowerCase(topic)] = true; + mKnownTopics.insert( Misc::StringUtils::lowerCase(topic) ); } void DialogueManager::parseText (const std::string& text) @@ -102,8 +103,8 @@ namespace MWDialogue if (tok->isImplicitKeyword() && mTranslationDataStorage.hasTranslation()) continue; - if (std::find(mActorKnownTopics.begin(), mActorKnownTopics.end(), topicId) != mActorKnownTopics.end()) - mKnownTopics[topicId] = true; + if (mActorKnownTopics.count( topicId )) + mKnownTopics.insert( topicId ); } updateTopics(); @@ -341,10 +342,10 @@ namespace MWDialogue if (filter.responseAvailable (*iter)) { std::string lower = Misc::StringUtils::lowerCase(iter->mId); - mActorKnownTopics.push_back (lower); + mActorKnownTopics.insert (lower); //does the player know the topic? - if (mKnownTopics.find (lower) != mKnownTopics.end()) + if (mKnownTopics.count(lower)) { keywordList.push_back (iter->mId); } @@ -635,10 +636,11 @@ namespace MWDialogue { ESM::DialogueState state; - for (std::map::const_iterator iter (mKnownTopics.begin()); + for (std::set::const_iterator iter (mKnownTopics.begin()); iter!=mKnownTopics.end(); ++iter) - if (iter->second) - state.mKnownTopics.push_back (iter->first); + { + state.mKnownTopics.push_back (*iter); + } state.mChangedFactionReaction = mChangedFactionReaction; @@ -659,7 +661,7 @@ namespace MWDialogue for (std::vector::const_iterator iter (state.mKnownTopics.begin()); iter!=state.mKnownTopics.end(); ++iter) if (store.get().search (*iter)) - mKnownTopics.insert (std::make_pair (*iter, true)); + mKnownTopics.insert (*iter); mChangedFactionReaction = state.mChangedFactionReaction; } diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp index 77035bc60..aec503e87 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp @@ -4,7 +4,7 @@ #include "../mwbase/dialoguemanager.hpp" #include -#include +#include #include #include @@ -23,13 +23,13 @@ namespace MWDialogue class DialogueManager : public MWBase::DialogueManager { std::map mDialogueMap; - std::map mKnownTopics;// Those are the topics the player knows. + std::set mKnownTopics;// Those are the topics the player knows. // Modified faction reactions. > typedef std::map > ModFactionReactionMap; ModFactionReactionMap mChangedFactionReaction; - std::list mActorKnownTopics; + std::set mActorKnownTopics; Translation::Storage& mTranslationDataStorage; MWScript::CompilerContext mCompilerContext;