diff --git a/apps/opencs/model/world/resources.cpp b/apps/opencs/model/world/resources.cpp index fc5b127dc..c5f5d6c76 100644 --- a/apps/opencs/model/world/resources.cpp +++ b/apps/opencs/model/world/resources.cpp @@ -4,30 +4,18 @@ #include #include -#include - #include CSMWorld::Resources::Resources (const std::string& baseDirectory, UniversalId::Type type, - const char * const *extensions) + std::vector resources, const char * const *extensions) : mBaseDirectory (baseDirectory), mType (type) { int baseSize = mBaseDirectory.size(); - Ogre::StringVector resourcesGroups = - Ogre::ResourceGroupManager::getSingleton().getResourceGroups(); - - for (Ogre::StringVector::iterator iter (resourcesGroups.begin()); - iter!=resourcesGroups.end(); ++iter) + for (std::vector::iterator iter(resources.begin()); iter != resources.end(); ++iter) { - if (*iter=="General" || *iter=="Internal" || *iter=="Autodetect") - continue; - - Ogre::StringVectorPtr resources = - Ogre::ResourceGroupManager::getSingleton().listResourceNames (*iter); - - for (Ogre::StringVector::const_iterator iter2 (resources->begin()); - iter2!=resources->end(); ++iter2) + // populate mFiles and mIndex + for (Ogre::StringVector::const_iterator iter2 ((*iter)->begin()); iter2 != (*iter)->end(); ++iter2) { if (static_cast (iter2->size())substr (0, baseSize)!=mBaseDirectory || diff --git a/apps/opencs/model/world/resources.hpp b/apps/opencs/model/world/resources.hpp index 9c1c76b6f..6e318e092 100644 --- a/apps/opencs/model/world/resources.hpp +++ b/apps/opencs/model/world/resources.hpp @@ -5,6 +5,8 @@ #include #include +#include + #include "universalid.hpp" namespace CSMWorld @@ -20,6 +22,7 @@ namespace CSMWorld /// \param type Type of resources in this table. Resources (const std::string& baseDirectory, UniversalId::Type type, + std::vector resources, const char * const *extensions = 0); int getSize() const; diff --git a/apps/opencs/model/world/resourcesmanager.cpp b/apps/opencs/model/world/resourcesmanager.cpp index 1b4770197..ba1d9629c 100644 --- a/apps/opencs/model/world/resourcesmanager.cpp +++ b/apps/opencs/model/world/resourcesmanager.cpp @@ -2,6 +2,8 @@ #include +#include + void CSMWorld::ResourcesManager::addResources (const Resources& resources) { mResources.insert (std::make_pair (resources.getType(), resources)); @@ -11,14 +13,45 @@ void CSMWorld::ResourcesManager::addResources (const Resources& resources) void CSMWorld::ResourcesManager::listResources() { + // Following code was taken out of Resources ctor, since it was being executed each time + // and slow enough to showe up in the profiler. + // + // See Editor ctor which calls Bsa::registerResources() + // + // resourceGroups include those from config files, e.g.: + // + // C:/Program Files\OpenMW\data + // C:/Program Files (x86)\Bethesda Softworks\Morrowind\Data Files + // + // and from archives: + // + // C:/Program Files (x86)\Bethesda Softworks\Morrowind\Data Files\Morrowind.bsa + // C:/Program Files (x86)\Bethesda Softworks\Morrowind\Data Files\Tribunal.bsa + // C:/Program Files (x86)\Bethesda Softworks\Morrowind\Data Files\Bloodmoon.bsa + // + std::vector resources; + + Ogre::StringVector resourcesGroups = + Ogre::ResourceGroupManager::getSingleton().getResourceGroups(); + + for (Ogre::StringVector::iterator iter (resourcesGroups.begin()); + iter!=resourcesGroups.end(); ++iter) + { + if (*iter=="General" || *iter=="Internal" || *iter=="Autodetect") + continue; + + resources.push_back( + Ogre::ResourceGroupManager::getSingleton().listResourceNames (*iter)); + } + static const char * const sMeshTypes[] = { "nif", 0 }; - addResources (Resources ("meshes", UniversalId::Type_Mesh, sMeshTypes)); - addResources (Resources ("icons", UniversalId::Type_Icon)); - addResources (Resources ("music", UniversalId::Type_Music)); - addResources (Resources ("sound", UniversalId::Type_SoundRes)); - addResources (Resources ("textures", UniversalId::Type_Texture)); - addResources (Resources ("videos", UniversalId::Type_Video)); + addResources (Resources ("meshes", UniversalId::Type_Mesh, resources, sMeshTypes)); + addResources (Resources ("icons", UniversalId::Type_Icon, resources)); + addResources (Resources ("music", UniversalId::Type_Music, resources)); + addResources (Resources ("sound", UniversalId::Type_SoundRes, resources)); + addResources (Resources ("textures", UniversalId::Type_Texture, resources)); + addResources (Resources ("videos", UniversalId::Type_Video, resources)); } const CSMWorld::Resources& CSMWorld::ResourcesManager::get (UniversalId::Type type) const diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 35fbf62a8..12836ea70 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -49,6 +49,8 @@ using namespace Ogre; static bool fsstrict = false; +static const std::ctype& facet = std::use_facet >(std::locale::classic()); + static char strict_normalize_char(char ch) { return ch == '\\' ? '/' : ch; @@ -56,7 +58,7 @@ static char strict_normalize_char(char ch) static char nonstrict_normalize_char(char ch) { - return ch == '\\' ? '/' : std::tolower(ch,std::locale::classic()); + return ch == '\\' ? '/' : facet.tolower(ch); } template @@ -245,7 +247,7 @@ public: time_t getModifiedTime(const String&) { return 0; } - // This is never called as far as I can see. + // This is never called as far as I can see. (actually called from CSMWorld::Resources ctor) StringVectorPtr list(bool recursive = true, bool dirs = false) { return find ("*", recursive, dirs);