From cd8515396adfa654574c30d80f89075efb76b7f5 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 28 Sep 2012 21:57:26 -0700 Subject: [PATCH] Use a multimap to store the text keys --- apps/openmw/mwrender/animation.cpp | 53 +++++++++----------------- components/nifogre/ogre_nif_loader.cpp | 25 +++++++++++- components/nifogre/ogre_nif_loader.hpp | 2 +- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 3d7629e5b..f7a175332 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -49,44 +49,27 @@ bool Animation::findGroupTimes(const std::string &groupname, Animation::GroupTim std::string::const_iterator strpos = iter->second.begin(); std::string::const_iterator strend = iter->second.end(); + size_t strlen = strend-strpos; - while(strpos != strend) + if(start.size() <= strlen && std::mismatch(strpos, strend, start.begin(), checklow()).first == strend) { - size_t strlen = strend-strpos; - std::string::const_iterator striter; - - if(start.size() <= strlen && - ((striter=std::mismatch(strpos, strend, start.begin(), checklow()).first) == strend || - *striter == '\r' || *striter == '\n')) - { - times->mStart = iter->first; - times->mLoopStart = iter->first; - } - else if(startloop.size() <= strlen && - ((striter=std::mismatch(strpos, strend, startloop.begin(), checklow()).first) == strend || - *striter == '\r' || *striter == '\n')) - { - times->mLoopStart = iter->first; - } - else if(stoploop.size() <= strlen && - ((striter=std::mismatch(strpos, strend, stoploop.begin(), checklow()).first) == strend || - *striter == '\r' || *striter == '\n')) - { + times->mStart = iter->first; + times->mLoopStart = iter->first; + } + else if(startloop.size() <= strlen && std::mismatch(strpos, strend, startloop.begin(), checklow()).first == strend) + { + times->mLoopStart = iter->first; + } + else if(stoploop.size() <= strlen && std::mismatch(strpos, strend, stoploop.begin(), checklow()).first == strend) + { + times->mLoopStop = iter->first; + } + else if(stop.size() <= strlen && std::mismatch(strpos, strend, stop.begin(), checklow()).first == strend) + { + times->mStop = iter->first; + if(times->mLoopStop < 0.0f) times->mLoopStop = iter->first; - } - else if(stop.size() <= strlen && - ((striter=std::mismatch(strpos, strend, stop.begin(), checklow()).first) == strend || - *striter == '\r' || *striter == '\n')) - { - times->mStop = iter->first; - if(times->mLoopStop < 0.0f) - times->mLoopStop = iter->first; - break; - } - - strpos = std::find(strpos+1, strend, '\n'); - while(strpos != strend && *strpos == '\n') - strpos++; + break; } } diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 91432ed6a..ad51d50b9 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -152,6 +152,28 @@ static void fail(const std::string &msg) } +static void insertTextKeys(const Nif::NiTextKeyExtraData *tk, TextKeyMap *textkeys) +{ + for(size_t i = 0;i < tk->list.size();i++) + { + const std::string &str = tk->list[i].text; + std::string::size_type pos = 0; + while(pos < str.length()) + { + while(pos < str.length() && ::isspace(str[pos])) + pos++; + if(pos >= str.length()) + break; + + std::string::size_type nextpos = std::min(str.find('\r', pos), str.find('\n', pos)); + textkeys->insert(std::make_pair(tk->list[i].time, str.substr(pos, nextpos-pos))); + + pos = nextpos; + } + } +} + + void buildBones(Ogre::Skeleton *skel, const Nif::Node *node, std::vector &ctrls, Ogre::Bone *parent=NULL) { Ogre::Bone *bone; @@ -359,8 +381,7 @@ bool createSkeleton(const std::string &name, const std::string &group, TextKeyMa if(e->recType == Nif::RC_NiTextKeyExtraData) { const Nif::NiTextKeyExtraData *tk = static_cast(e.getPtr()); - for(size_t i = 0;i < tk->list.size();i++) - (*textkeys)[tk->list[i].time] = tk->list[i].text; + insertTextKeys(tk, textkeys); } e = e->extra; } diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index b6610d8a7..a203112b5 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -59,7 +59,7 @@ namespace NifOgre { // FIXME: These should not be in NifOgre, it works agnostic of what model format is used -typedef std::map TextKeyMap; +typedef std::multimap TextKeyMap; struct EntityList { std::vector mEntities; Ogre::Entity *mSkelBase;