mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 15:15:31 +00:00
Optimized dialogue merging with a lookup map
This commit is contained in:
parent
1677fcf324
commit
0aa1042fd7
2 changed files with 36 additions and 21 deletions
|
@ -47,37 +47,46 @@ void Dialogue::save(ESMWriter &esm) const
|
|||
|
||||
void Dialogue::addInfo(const ESM::DialInfo& info, bool merge)
|
||||
{
|
||||
// TODO: use std::move
|
||||
if (!merge || mInfo.empty() || info.mNext.empty())
|
||||
{
|
||||
mInfo.push_back(info);
|
||||
mLookup[info.mId] = mInfo.insert(mInfo.end(), info);
|
||||
return;
|
||||
}
|
||||
if (info.mPrev.empty())
|
||||
{
|
||||
mInfo.push_front(info);
|
||||
mLookup[info.mId] = mInfo.insert(mInfo.begin(), info);
|
||||
return;
|
||||
}
|
||||
int i=0;
|
||||
for (ESM::Dialogue::InfoContainer::iterator it = mInfo.begin(); it != mInfo.end(); ++it)
|
||||
|
||||
ESM::Dialogue::InfoContainer::iterator it = mInfo.end();
|
||||
|
||||
std::map<std::string, ESM::Dialogue::InfoContainer::iterator>::iterator lookup;
|
||||
lookup = mLookup.find(info.mPrev);
|
||||
if (lookup != mLookup.end())
|
||||
{
|
||||
if (info.mPrev == it->mId)
|
||||
{
|
||||
mInfo.insert(++it, info);
|
||||
return;
|
||||
}
|
||||
if (info.mNext == it->mId)
|
||||
{
|
||||
mInfo.insert(it, info);
|
||||
return;
|
||||
}
|
||||
if (info.mId == it->mId)
|
||||
{
|
||||
*it = info;
|
||||
return;
|
||||
}
|
||||
++i;
|
||||
it = lookup->second;
|
||||
|
||||
mLookup[info.mId] = mInfo.insert(++it, info);
|
||||
return;
|
||||
}
|
||||
|
||||
lookup = mLookup.find(info.mNext);
|
||||
if (lookup != mLookup.end())
|
||||
{
|
||||
it = lookup->second;
|
||||
|
||||
mLookup[info.mId] = mInfo.insert(it, info);
|
||||
return;
|
||||
}
|
||||
|
||||
lookup = mLookup.find(info.mId);
|
||||
if (lookup != mLookup.end())
|
||||
{
|
||||
it = lookup->second;
|
||||
*it = info;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cerr << "Failed to insert info " << info.mId << std::endl;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#include "loadinfo.hpp"
|
||||
|
||||
|
@ -36,8 +37,13 @@ struct Dialogue
|
|||
|
||||
typedef std::list<DialInfo> InfoContainer;
|
||||
|
||||
typedef std::map<std::string, InfoContainer::iterator> LookupMap;
|
||||
|
||||
InfoContainer mInfo;
|
||||
|
||||
// This is only used during the loading phase to speed up DialInfo merging.
|
||||
LookupMap mLookup;
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm) const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue