mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-23 22:11:38 +00:00
Port ResourceHelpers to new VFS
This commit is contained in:
parent
e6880de032
commit
79c2138e53
4 changed files with 38 additions and 45 deletions
|
@ -282,7 +282,8 @@ namespace ESMTerrain
|
||||||
const ESM::LandTexture* ltex = getLandTexture(id.first-1, id.second);
|
const ESM::LandTexture* ltex = getLandTexture(id.first-1, id.second);
|
||||||
|
|
||||||
//TODO this is needed due to MWs messed up texture handling
|
//TODO this is needed due to MWs messed up texture handling
|
||||||
std::string texture = Misc::ResourceHelpers::correctTexturePath(ltex->mTexture);
|
assert(0 && "no vfs here yet");
|
||||||
|
std::string texture = ltex->mTexture; //Misc::ResourceHelpers::correctTexturePath(ltex->mTexture);
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#include "resourcehelpers.hpp"
|
#include "resourcehelpers.hpp"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <components/misc/stringops.hpp>
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
#include <OgreResourceGroupManager.h>
|
#include <components/vfs/manager.hpp>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -29,8 +31,8 @@ namespace
|
||||||
|
|
||||||
bool Misc::ResourceHelpers::changeExtensionToDds(std::string &path)
|
bool Misc::ResourceHelpers::changeExtensionToDds(std::string &path)
|
||||||
{
|
{
|
||||||
Ogre::String::size_type pos = path.rfind('.');
|
std::string::size_type pos = path.rfind('.');
|
||||||
if(pos != Ogre::String::npos && path.compare(pos, path.length() - pos, ".dds") != 0)
|
if(pos != std::string::npos && path.compare(pos, path.length() - pos, ".dds") != 0)
|
||||||
{
|
{
|
||||||
path.replace(pos, path.length(), ".dds");
|
path.replace(pos, path.length(), ".dds");
|
||||||
return true;
|
return true;
|
||||||
|
@ -38,7 +40,7 @@ bool Misc::ResourceHelpers::changeExtensionToDds(std::string &path)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLevelDirectory, const std::string &resPath)
|
std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLevelDirectory, const std::string &resPath, const VFS::Manager* vfs)
|
||||||
{
|
{
|
||||||
/* Bethesda at some point converted all their BSA
|
/* Bethesda at some point converted all their BSA
|
||||||
* textures from tga to dds for increased load speed, but all
|
* textures from tga to dds for increased load speed, but all
|
||||||
|
@ -64,65 +66,65 @@ std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLev
|
||||||
// since we know all (GOTY edition or less) textures end
|
// since we know all (GOTY edition or less) textures end
|
||||||
// in .dds, we change the extension
|
// in .dds, we change the extension
|
||||||
bool changedToDds = changeExtensionToDds(correctedPath);
|
bool changedToDds = changeExtensionToDds(correctedPath);
|
||||||
if (Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(correctedPath))
|
if (vfs->exists(correctedPath))
|
||||||
return correctedPath;
|
return correctedPath;
|
||||||
// if it turns out that the above wasn't true in all cases (not for vanilla, but maybe mods)
|
// 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)
|
// verify, and revert if false (this call succeeds quickly, but fails slowly)
|
||||||
if (changedToDds && Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(origExt))
|
if (changedToDds && vfs->exists(origExt))
|
||||||
return origExt;
|
return origExt;
|
||||||
|
|
||||||
// fall back to a resource in the top level directory if it exists
|
// fall back to a resource in the top level directory if it exists
|
||||||
std::string fallback = topLevelDirectory + "\\" + getBasename(correctedPath);
|
std::string fallback = topLevelDirectory + "\\" + getBasename(correctedPath);
|
||||||
if (Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(fallback))
|
if (vfs->exists(fallback))
|
||||||
return fallback;
|
return fallback;
|
||||||
|
|
||||||
if (changedToDds)
|
if (changedToDds)
|
||||||
{
|
{
|
||||||
fallback = topLevelDirectory + "\\" + getBasename(origExt);
|
fallback = topLevelDirectory + "\\" + getBasename(origExt);
|
||||||
if (Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(fallback))
|
if (vfs->exists(fallback))
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
return correctedPath;
|
return correctedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Misc::ResourceHelpers::correctTexturePath(const std::string &resPath)
|
std::string Misc::ResourceHelpers::correctTexturePath(const std::string &resPath, const VFS::Manager* vfs)
|
||||||
{
|
{
|
||||||
static const std::string dir = "textures";
|
static const std::string dir = "textures";
|
||||||
return correctResourcePath(dir, resPath);
|
return correctResourcePath(dir, resPath, vfs);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Misc::ResourceHelpers::correctIconPath(const std::string &resPath)
|
std::string Misc::ResourceHelpers::correctIconPath(const std::string &resPath, const VFS::Manager* vfs)
|
||||||
{
|
{
|
||||||
static const std::string dir = "icons";
|
static const std::string dir = "icons";
|
||||||
return correctResourcePath(dir, resPath);
|
return correctResourcePath(dir, resPath, vfs);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Misc::ResourceHelpers::correctBookartPath(const std::string &resPath)
|
std::string Misc::ResourceHelpers::correctBookartPath(const std::string &resPath, const VFS::Manager* vfs)
|
||||||
{
|
{
|
||||||
static const std::string dir = "bookart";
|
static const std::string dir = "bookart";
|
||||||
std::string image = correctResourcePath(dir, resPath);
|
std::string image = correctResourcePath(dir, resPath, vfs);
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Misc::ResourceHelpers::correctBookartPath(const std::string &resPath, int width, int height)
|
std::string Misc::ResourceHelpers::correctBookartPath(const std::string &resPath, int width, int height, const VFS::Manager* vfs)
|
||||||
{
|
{
|
||||||
std::string image = correctBookartPath(resPath);
|
std::string image = correctBookartPath(resPath, vfs);
|
||||||
|
|
||||||
// Apparently a bug with some morrowind versions, they reference the image without the size suffix.
|
// Apparently a bug with some morrowind versions, they reference the image without the size suffix.
|
||||||
// So if the image isn't found, try appending the size.
|
// So if the image isn't found, try appending the size.
|
||||||
if (!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(image))
|
if (!vfs->exists(image))
|
||||||
{
|
{
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
str << image.substr(0, image.rfind('.')) << "_" << width << "_" << height << image.substr(image.rfind('.'));
|
str << image.substr(0, image.rfind('.')) << "_" << width << "_" << height << image.substr(image.rfind('.'));
|
||||||
image = Misc::ResourceHelpers::correctBookartPath(str.str());
|
image = Misc::ResourceHelpers::correctBookartPath(str.str(), vfs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Misc::ResourceHelpers::correctActorModelPath(const std::string &resPath)
|
std::string Misc::ResourceHelpers::correctActorModelPath(const std::string &resPath, const VFS::Manager* vfs)
|
||||||
{
|
{
|
||||||
std::string mdlname = resPath;
|
std::string mdlname = resPath;
|
||||||
std::string::size_type p = mdlname.rfind('\\');
|
std::string::size_type p = mdlname.rfind('\\');
|
||||||
|
@ -132,7 +134,7 @@ std::string Misc::ResourceHelpers::correctActorModelPath(const std::string &resP
|
||||||
mdlname.insert(mdlname.begin()+p+1, 'x');
|
mdlname.insert(mdlname.begin()+p+1, 'x');
|
||||||
else
|
else
|
||||||
mdlname.insert(mdlname.begin(), 'x');
|
mdlname.insert(mdlname.begin(), 'x');
|
||||||
if(!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(mdlname))
|
if(!vfs->exists(mdlname))
|
||||||
{
|
{
|
||||||
return resPath;
|
return resPath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,23 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace VFS
|
||||||
|
{
|
||||||
|
class Manager;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Misc
|
namespace Misc
|
||||||
{
|
{
|
||||||
namespace ResourceHelpers
|
namespace ResourceHelpers
|
||||||
{
|
{
|
||||||
bool changeExtensionToDds(std::string &path);
|
bool changeExtensionToDds(std::string &path);
|
||||||
std::string correctResourcePath(const std::string &topLevelDirectory, const std::string &resPath);
|
std::string correctResourcePath(const std::string &topLevelDirectory, const std::string &resPath, const VFS::Manager* vfs);
|
||||||
std::string correctTexturePath(const std::string &resPath);
|
std::string correctTexturePath(const std::string &resPath, const VFS::Manager* vfs);
|
||||||
std::string correctIconPath(const std::string &resPath);
|
std::string correctIconPath(const std::string &resPath, const VFS::Manager* vfs);
|
||||||
std::string correctBookartPath(const std::string &resPath);
|
std::string correctBookartPath(const std::string &resPath, const VFS::Manager* vfs);
|
||||||
std::string correctBookartPath(const std::string &resPath, int width, int height);
|
std::string correctBookartPath(const std::string &resPath, int width, int height, const VFS::Manager* vfs);
|
||||||
/// Uses "xfoo.nif" instead of "foo.nif" if available
|
/// Uses "xfoo.nif" instead of "foo.nif" if available
|
||||||
std::string correctActorModelPath(const std::string &resPath);
|
std::string correctActorModelPath(const std::string &resPath, const VFS::Manager* vfs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <osgDB/Registry>
|
#include <osgDB/Registry>
|
||||||
#include <osg/io_utils>
|
#include <osg/io_utils>
|
||||||
#include <components/misc/stringops.hpp>
|
#include <components/misc/stringops.hpp>
|
||||||
|
#include <components/misc/resourcehelpers.hpp>
|
||||||
|
|
||||||
// skel
|
// skel
|
||||||
#include <osgAnimation/Skeleton>
|
#include <osgAnimation/Skeleton>
|
||||||
|
@ -477,15 +478,7 @@ namespace NifOsg
|
||||||
if (st.empty())
|
if (st.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// FIXME: replace by ResourceHelpers
|
std::string filename = Misc::ResourceHelpers::correctTexturePath(st->filename, resourceManager);
|
||||||
std::string filename (st->filename);
|
|
||||||
Misc::StringUtils::toLower(filename);
|
|
||||||
filename = "textures\\" + filename;
|
|
||||||
size_t found = filename.find(".tga");
|
|
||||||
if (found == std::string::npos)
|
|
||||||
found = filename.find(".bmp");
|
|
||||||
if (found != std::string::npos)
|
|
||||||
filename.replace(found, 4, ".dds");
|
|
||||||
|
|
||||||
// tx_creature_werewolf.dds isn't loading in the correct format without this option
|
// tx_creature_werewolf.dds isn't loading in the correct format without this option
|
||||||
osgDB::Options* opts = new osgDB::Options;
|
osgDB::Options* opts = new osgDB::Options;
|
||||||
|
@ -868,15 +861,7 @@ namespace NifOsg
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: replace by ResourceHelpers
|
std::string filename = Misc::ResourceHelpers::correctTexturePath(st->filename, resourceManager);
|
||||||
std::string filename (st->filename);
|
|
||||||
Misc::StringUtils::toLower(filename);
|
|
||||||
filename = "textures\\" + filename;
|
|
||||||
size_t found = filename.find(".tga");
|
|
||||||
if (found == std::string::npos)
|
|
||||||
found = filename.find(".bmp");
|
|
||||||
if (found != std::string::npos)
|
|
||||||
filename.replace(found, 4, ".dds");
|
|
||||||
|
|
||||||
// tx_creature_werewolf.dds isn't loading in the correct format without this option
|
// tx_creature_werewolf.dds isn't loading in the correct format without this option
|
||||||
osgDB::Options* opts = new osgDB::Options;
|
osgDB::Options* opts = new osgDB::Options;
|
||||||
|
|
Loading…
Reference in a new issue