forked from teamnwah/openmw-tes3coop
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.
This commit is contained in:
parent
05be353fec
commit
419046e121
2 changed files with 14 additions and 12 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#include <components/esm/loaddial.hpp>
|
#include <components/esm/loaddial.hpp>
|
||||||
#include <components/esm/loadinfo.hpp>
|
#include <components/esm/loadinfo.hpp>
|
||||||
|
@ -78,7 +79,7 @@ namespace MWDialogue
|
||||||
|
|
||||||
void DialogueManager::addTopic (const std::string& topic)
|
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)
|
void DialogueManager::parseText (const std::string& text)
|
||||||
|
@ -102,8 +103,8 @@ namespace MWDialogue
|
||||||
if (tok->isImplicitKeyword() && mTranslationDataStorage.hasTranslation())
|
if (tok->isImplicitKeyword() && mTranslationDataStorage.hasTranslation())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (std::find(mActorKnownTopics.begin(), mActorKnownTopics.end(), topicId) != mActorKnownTopics.end())
|
if (mActorKnownTopics.count( topicId ))
|
||||||
mKnownTopics[topicId] = true;
|
mKnownTopics.insert( topicId );
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTopics();
|
updateTopics();
|
||||||
|
@ -341,10 +342,10 @@ namespace MWDialogue
|
||||||
if (filter.responseAvailable (*iter))
|
if (filter.responseAvailable (*iter))
|
||||||
{
|
{
|
||||||
std::string lower = Misc::StringUtils::lowerCase(iter->mId);
|
std::string lower = Misc::StringUtils::lowerCase(iter->mId);
|
||||||
mActorKnownTopics.push_back (lower);
|
mActorKnownTopics.insert (lower);
|
||||||
|
|
||||||
//does the player know the topic?
|
//does the player know the topic?
|
||||||
if (mKnownTopics.find (lower) != mKnownTopics.end())
|
if (mKnownTopics.count(lower))
|
||||||
{
|
{
|
||||||
keywordList.push_back (iter->mId);
|
keywordList.push_back (iter->mId);
|
||||||
}
|
}
|
||||||
|
@ -635,10 +636,11 @@ namespace MWDialogue
|
||||||
{
|
{
|
||||||
ESM::DialogueState state;
|
ESM::DialogueState state;
|
||||||
|
|
||||||
for (std::map<std::string, bool>::const_iterator iter (mKnownTopics.begin());
|
for (std::set<std::string>::const_iterator iter (mKnownTopics.begin());
|
||||||
iter!=mKnownTopics.end(); ++iter)
|
iter!=mKnownTopics.end(); ++iter)
|
||||||
if (iter->second)
|
{
|
||||||
state.mKnownTopics.push_back (iter->first);
|
state.mKnownTopics.push_back (*iter);
|
||||||
|
}
|
||||||
|
|
||||||
state.mChangedFactionReaction = mChangedFactionReaction;
|
state.mChangedFactionReaction = mChangedFactionReaction;
|
||||||
|
|
||||||
|
@ -659,7 +661,7 @@ namespace MWDialogue
|
||||||
for (std::vector<std::string>::const_iterator iter (state.mKnownTopics.begin());
|
for (std::vector<std::string>::const_iterator iter (state.mKnownTopics.begin());
|
||||||
iter!=state.mKnownTopics.end(); ++iter)
|
iter!=state.mKnownTopics.end(); ++iter)
|
||||||
if (store.get<ESM::Dialogue>().search (*iter))
|
if (store.get<ESM::Dialogue>().search (*iter))
|
||||||
mKnownTopics.insert (std::make_pair (*iter, true));
|
mKnownTopics.insert (*iter);
|
||||||
|
|
||||||
mChangedFactionReaction = state.mChangedFactionReaction;
|
mChangedFactionReaction = state.mChangedFactionReaction;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "../mwbase/dialoguemanager.hpp"
|
#include "../mwbase/dialoguemanager.hpp"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <list>
|
#include <set>
|
||||||
|
|
||||||
#include <components/compiler/streamerrorhandler.hpp>
|
#include <components/compiler/streamerrorhandler.hpp>
|
||||||
#include <components/translation/translation.hpp>
|
#include <components/translation/translation.hpp>
|
||||||
|
@ -23,13 +23,13 @@ namespace MWDialogue
|
||||||
class DialogueManager : public MWBase::DialogueManager
|
class DialogueManager : public MWBase::DialogueManager
|
||||||
{
|
{
|
||||||
std::map<std::string, ESM::Dialogue> mDialogueMap;
|
std::map<std::string, ESM::Dialogue> mDialogueMap;
|
||||||
std::map<std::string, bool> mKnownTopics;// Those are the topics the player knows.
|
std::set<std::string> mKnownTopics;// Those are the topics the player knows.
|
||||||
|
|
||||||
// Modified faction reactions. <Faction1, <Faction2, Difference> >
|
// Modified faction reactions. <Faction1, <Faction2, Difference> >
|
||||||
typedef std::map<std::string, std::map<std::string, int> > ModFactionReactionMap;
|
typedef std::map<std::string, std::map<std::string, int> > ModFactionReactionMap;
|
||||||
ModFactionReactionMap mChangedFactionReaction;
|
ModFactionReactionMap mChangedFactionReaction;
|
||||||
|
|
||||||
std::list<std::string> mActorKnownTopics;
|
std::set<std::string> mActorKnownTopics;
|
||||||
|
|
||||||
Translation::Storage& mTranslationDataStorage;
|
Translation::Storage& mTranslationDataStorage;
|
||||||
MWScript::CompilerContext mCompilerContext;
|
MWScript::CompilerContext mCompilerContext;
|
||||||
|
|
Loading…
Reference in a new issue