From 935d9241d8ee0b74f9e414cbfde93b13369148b1 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 9 Nov 2013 11:42:19 +0100 Subject: [PATCH] first attempt at proper info record loading: partially incorrect and way too slow --- apps/opencs/model/world/infocollection.cpp | 37 ++++++++++++++++++++-- apps/opencs/model/world/infocollection.hpp | 5 +++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/world/infocollection.cpp b/apps/opencs/model/world/infocollection.cpp index a63d3bce41..d326543fbf 100644 --- a/apps/opencs/model/world/infocollection.cpp +++ b/apps/opencs/model/world/infocollection.cpp @@ -2,6 +2,7 @@ #include "infocollection.hpp" #include +#include #include #include @@ -19,7 +20,27 @@ void CSMWorld::InfoCollection::load (const Info& record, bool base) record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly; (base ? record2.mBase : record2.mModified) = record; - insertRecord (record2, getIdMap().size()); + int index = -1; + + std::string topic = Misc::StringUtils::lowerCase (record2.get().mTopicId); + + if (!record2.get().mPrev.empty()) + { + index = getIndex (record2.get().mPrev, topic); + + if (index!=-1) + ++index; + } + + if (index==-1 && !record2.get().mNext.empty()) + { + index = getIndex (record2.get().mNext, topic); + } + + if (index==-1) + index = getIdMap().size(); + + insertRecord (record2, index); } else { @@ -35,6 +56,19 @@ void CSMWorld::InfoCollection::load (const Info& record, bool base) } } +int CSMWorld::InfoCollection::getIndex (const std::string& id, const std::string& topic) const +{ + std::string fullId = Misc::StringUtils::lowerCase (topic) + "#" + id; + + std::pair range = getTopicRange (topic); + + for (; range.first!=range.second; ++range.first) + if (range.first->first==fullId) + return std::distance (getIdMap().begin(), range.first); + + return -1; +} + int CSMWorld::InfoCollection::getAppendIndex (const std::string& id, UniversalId::Type type) const { std::string::size_type separator = id.find_last_of ('#'); @@ -58,7 +92,6 @@ int CSMWorld::InfoCollection::getAppendIndex (const std::string& id, UniversalId void CSMWorld::InfoCollection::load (ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue) { - /// \todo put records into proper order std::string id = Misc::StringUtils::lowerCase (dialogue.mId) + "#" + reader.getHNOString ("INAM"); diff --git a/apps/opencs/model/world/infocollection.hpp b/apps/opencs/model/world/infocollection.hpp index 8ca5f3b45e..398f9becca 100644 --- a/apps/opencs/model/world/infocollection.hpp +++ b/apps/opencs/model/world/infocollection.hpp @@ -21,6 +21,11 @@ namespace CSMWorld void load (const Info& record, bool base); + int getIndex (const std::string& id, const std::string& topic) const; + ///< Return index for record \a id or -1 (if not present; deleted records are considered) + /// + /// \param id info ID without topic prefix + public: virtual int getAppendIndex (const std::string& id,