From 6e880cffb24ba19dd8622ae3477a42622e78b023 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 5 May 2011 19:32:42 +0200 Subject: [PATCH] changed engine class to support multiple data directories for esm files --- apps/openmw/engine.cpp | 26 ++++++++++++-------------- apps/openmw/engine.hpp | 9 +++++---- apps/openmw/main.cpp | 4 +++- apps/openmw/mwworld/world.cpp | 8 +++++--- apps/openmw/mwworld/world.hpp | 8 +++++++- components/files/collections.cpp | 2 ++ components/files/collections.hpp | 2 ++ 7 files changed, 36 insertions(+), 23 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 1ca5c68b4..fbba304b9 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -240,15 +240,12 @@ OMW::Engine::~Engine() void OMW::Engine::loadBSA() { - boost::filesystem::directory_iterator end; + const Files::MultiDirCollection& bsa = mFileCollections.getCollection (".bsa"); - for (boost::filesystem::directory_iterator iter (mDataDir); iter!=end; ++iter) + for (Files::MultiDirCollection::TIter iter (bsa.begin()); iter!=bsa.end(); ++iter) { - if (boost::filesystem::extension (iter->path())==".bsa") - { - std::cout << "Adding " << iter->path().string() << std::endl; - addBSA(iter->path().string()); - } + std::cout << "Adding " << iter->second.string() << std::endl; + addBSA (iter->second.string()); } } @@ -263,9 +260,13 @@ void OMW::Engine::addResourcesDirectory (const boost::filesystem::path& path) // Set data dir -void OMW::Engine::setDataDir (const boost::filesystem::path& dataDir) +void OMW::Engine::setDataDirs (const std::vector& dataDirs) { - mDataDir = boost::filesystem::system_complete (dataDir); + /// \todo remove mDataDir, once resources system can handle multiple directories + assert (!dataDirs.empty()); + mDataDir = dataDirs[0]; + + mFileCollections = Files::Collections (dataDirs, true); } // Set resource dir @@ -318,15 +319,12 @@ void OMW::Engine::setNewGame() void OMW::Engine::go() { assert (!mEnvironment.mWorld); - assert (!mDataDir.empty()); assert (!mCellName.empty()); assert (!mMaster.empty()); test.name = ""; total = 0; - std::cout << "Data directory: " << mDataDir << "\n"; - std::string cfgDir = Files::getPath (Files::Path_ConfigGlobal, "openmw", ""); std::string cfgUserDir = Files::getPath (Files::Path_ConfigUser, "openmw", ""); std::string plugCfg = "plugins.cfg"; @@ -358,8 +356,8 @@ void OMW::Engine::go() mPhysicEngine = new OEngine::Physic::PhysicEngine(shapeLoader); // Create the world - mEnvironment.mWorld = new MWWorld::World (mOgre, mPhysicEngine, mDataDir, mMaster, mResDir, mNewGame, mEnvironment); - + mEnvironment.mWorld = new MWWorld::World (mOgre, mPhysicEngine, mFileCollections, mMaster, + mResDir, mNewGame, mEnvironment); // Set up the GUI system mGuiManager = new OEngine::GUI::MyGUIManager(mOgre.getWindow(), mOgre.getScene(), false, cfgDir); diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 2f8a5b1d2..4631f60a7 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "mwworld/environment.hpp" #include "mwworld/ptr.hpp" @@ -55,8 +56,6 @@ namespace OMW class Engine : private Ogre::FrameListener { - - //int nFiles; boost::filesystem::path mDataDir; boost::filesystem::path mResDir; OEngine::Render::OgreRenderer mOgre; @@ -84,6 +83,8 @@ namespace OMW MWWorld::Ptr mIgnoreLocalPtr; + Files::Collections mFileCollections; + // not implemented Engine (const Engine&); Engine& operator= (const Engine&); @@ -108,8 +109,8 @@ namespace OMW ~Engine(); - /// Set data dir - void setDataDir (const boost::filesystem::path& dataDir); + /// Set data dirs + void setDataDirs (const std::vector& dataDirs); /// Set resource dir void setResourceDir (const boost::filesystem::path& parResDir); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index c5f53d7b5..7eba8c303 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -105,7 +105,9 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) } // directory settings - engine.setDataDir (variables["data"].as()); + std::vector dataDirs; + dataDirs.push_back (variables["data"].as()); + engine.setDataDirs (dataDirs); engine.setResourceDir (variables["resources"].as()); // master and plugin diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 81151ccdc..68e3a745d 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -5,6 +5,7 @@ #include #include +#include #include "../mwrender/sky.hpp" #include "../mwrender/interior.hpp" @@ -406,15 +407,16 @@ namespace MWWorld mCellChanged = true; } - World::World (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, const boost::filesystem::path& dataDir, + World::World (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, + const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment) : mSkyManager (0), mScene (renderer,physEng), mPlayer (0), mCurrentCell (0), mGlobalVariables (0), mSky (false), mCellChanged (false), mEnvironment (environment) { mPhysEngine = physEng; - boost::filesystem::path masterPath (dataDir); - masterPath /= master; + + boost::filesystem::path masterPath (fileCollections.getCollection (".esm").getPath (master)); std::cout << "Loading ESM " << masterPath.string() << "\n"; diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index d722eb166..160c20314 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -26,6 +26,11 @@ namespace ESM struct Position; } +namespace Files +{ + class Collections; +} + namespace Render { class OgreRenderer; @@ -107,7 +112,8 @@ namespace MWWorld /// interior cell. public: - World (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, const boost::filesystem::path& dataDir, + World (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, + const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment); diff --git a/components/files/collections.cpp b/components/files/collections.cpp index 6d1c00ab1..8cd4865b3 100644 --- a/components/files/collections.cpp +++ b/components/files/collections.cpp @@ -3,6 +3,8 @@ namespace Files { + Collections::Collections() : mFoldCase (false) {} + Collections::Collections (const std::vector& directories, bool foldCase) : mDirectories (directories), mFoldCase (foldCase) {} diff --git a/components/files/collections.hpp b/components/files/collections.hpp index 9e23892af..6eaf0303e 100644 --- a/components/files/collections.hpp +++ b/components/files/collections.hpp @@ -13,6 +13,8 @@ namespace Files public: + Collections(); + Collections (const std::vector& directories, bool foldCase); ///< Directories are listed with increasing priority.