From 218139351830d00b3b564b13ab7d16276b99c6d3 Mon Sep 17 00:00:00 2001 From: Nathan Jeffords Date: Fri, 4 Jan 2013 11:36:22 -0800 Subject: [PATCH] change texture renaming logic to increase performance ResourceGroupManager::resourceExistsInAnyGroup is slow (at least on windows) if the tested path does not exist, but is fast if it does (due to finding it in the index). This change tries the '.dds' version of the name first, and reverts to the original if the '.dds' version was not found. --- components/nifogre/ogre_nif_loader.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index ad51d50b95..dca459119b 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -536,11 +536,23 @@ static Ogre::String getMaterial(const NiTriShape *shape, const Ogre::String &nam * textures from tga to dds for increased load speed, but all * texture file name references were kept as .tga. */ - texName = "textures\\" + st->filename; - if(!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(texName)) + + static const char * path = "textures\\"; + + texName = path + st->filename; + + Ogre::String::size_type pos = texName.rfind('.'); + + if (texName.compare (pos, texName.size () - pos, ".dds") != 0) { - Ogre::String::size_type pos = texName.rfind('.'); + // since we know all (GOTY edition or less) textures end + // in .dds, we change the extension texName.replace(pos, texName.length(), ".dds"); + + // if it turns out that the above wasn't true in all cases (not for vanilla, but maybe mods) + // verify, and revert if false (this call succeeds quickly, but fails slowly) + if(!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(texName)) + texName = path + st->filename; } } else warn("Found internal texture, ignoring.");