Move resource names listing code out of CSMWorld::Resources ctor in order to avoid multiple scan of the same resources.

- The resources are still scanned twice, once when the archive/directory is added and another time when the names are listed.
pull/541/head
cc9cii 9 years ago
parent 06f9922822
commit 003b0d48be

@ -4,30 +4,18 @@
#include <stdexcept>
#include <algorithm>
#include <OgreResourceGroupManager.h>
#include <components/misc/stringops.hpp>
CSMWorld::Resources::Resources (const std::string& baseDirectory, UniversalId::Type type,
const char * const *extensions)
std::vector<Ogre::StringVectorPtr> 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<Ogre::StringVectorPtr>::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<int> (iter2->size())<baseSize+1 ||
iter2->substr (0, baseSize)!=mBaseDirectory ||

@ -5,6 +5,8 @@
#include <map>
#include <vector>
#include <OgreStringVector.h>
#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<Ogre::StringVectorPtr> resources,
const char * const *extensions = 0);
int getSize() const;

@ -2,6 +2,8 @@
#include <stdexcept>
#include <OgreResourceGroupManager.h>
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<Ogre::StringVectorPtr> 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

@ -49,6 +49,8 @@ using namespace Ogre;
static bool fsstrict = false;
static const std::ctype<char>& facet = std::use_facet<std::ctype<char> >(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<typename T1, typename T2>
@ -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);

Loading…
Cancel
Save