From 9a041d7c01a4f89cdb9d94dea9a2a15641d2c251 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 11 Jun 2010 19:53:00 +0200 Subject: [PATCH] added data option and openmw.cfg file --- CMakeLists.txt | 3 +++ bsa/bsa_archive.cpp | 2 +- bsa/bsa_archive.hpp | 4 +++- files/openmw.cfg | 2 ++ game/main.cpp | 34 +++++++++++++++++++++++++++------- 5 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 files/openmw.cfg diff --git a/CMakeLists.txt b/CMakeLists.txt index de2061298..220ae7ca8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,9 @@ configure_file(${OpenMW_SOURCE_DIR}/files/plugins.cfg.linux "${OpenMW_BINARY_DIR}/plugins.cfg" COPYONLY) endif (WIN32) +configure_file(${OpenMW_SOURCE_DIR}/files/openmw.cfg + "${OpenMW_BINARY_DIR}/openmw.cfg" COPYONLY) + # Main executable add_executable(openmw ${BSA} ${BSA_HEADER} diff --git a/bsa/bsa_archive.cpp b/bsa/bsa_archive.cpp index d1a8c150f..a025c2507 100644 --- a/bsa/bsa_archive.cpp +++ b/bsa/bsa_archive.cpp @@ -157,7 +157,7 @@ static void insertBSAFactory() // The function below is the only publicly exposed part of this file -void addBSA(const char* name, const char* group) +void addBSA(const std::string& name, const std::string& group) { insertBSAFactory(); ResourceGroupManager::getSingleton(). diff --git a/bsa/bsa_archive.hpp b/bsa/bsa_archive.hpp index 007fd5b36..bde6d9c3b 100644 --- a/bsa/bsa_archive.hpp +++ b/bsa/bsa_archive.hpp @@ -21,11 +21,13 @@ */ +#include + #ifndef _BSA_ARCHIVE_H_ #define _BSA_ARCHIVE_H_ /// Add the given BSA file as an input archive in the Ogre resource /// system. -void addBSA(const char* file, const char* group="General"); +void addBSA(const std::string& file, const std::string& group="General"); #endif diff --git a/files/openmw.cfg b/files/openmw.cfg new file mode 100644 index 000000000..cd24a9443 --- /dev/null +++ b/files/openmw.cfg @@ -0,0 +1,2 @@ +data=data + diff --git a/game/main.cpp b/game/main.cpp index 164c258e0..f66fed2df 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -1,5 +1,8 @@ #include +#include +#include + #include "boost/program_options.hpp" #include "esm_store/cell_store.hpp" @@ -13,21 +16,28 @@ using namespace std; -void maintest() +void maintest (std::string dataDir) { - const char* esmFile = "data/Morrowind.esm"; - const char* bsaFile = "data/Morrowind.bsa"; + assert (!dataDir.empty()); + + if (dataDir[dataDir.size()-1]!='/' && dataDir[dataDir.size()-1]!='\\') + dataDir += "/"; + + const char* esmFile = "Morrowind.esm"; + const char* bsaFile = "Morrowind.bsa"; const char* plugCfg = "plugins.cfg"; cout << "Hello, fellow traveler!\n"; + + cout << "Your data directory for today is: " << dataDir << "\n"; cout << "Initializing OGRE\n"; Render::OgreRenderer ogre; ogre.configure(!isFile("ogre.cfg"), plugCfg, false); cout << "Adding " << bsaFile << endl; - addBSA(bsaFile); + addBSA(dataDir + bsaFile); cout << "Loading ESM " << esmFile << "\n"; ESM::ESMReader esm; @@ -35,7 +45,7 @@ void maintest() ESMS::CellStore cell; // This parses the ESM file and loads a sample cell - esm.open(esmFile); + esm.open(dataDir + esmFile); store.load(esm); cell.loadInt("Beshara", store, esm); @@ -75,20 +85,30 @@ int main(int argc, char**argv) "Syntax: openmw \nAllowed options"); desc.add_options() - ("help", "print help message"); + ("help", "print help message") + ("data", boost::program_options::value()->default_value ("data"), + "set data directory" + ); boost::program_options::variables_map variables; + + std::ifstream configFile ("openmw.cfg"); + boost::program_options::store ( boost::program_options::parse_command_line (argc, argv, desc), variables); boost::program_options::notify (variables); + if (configFile.is_open()) + boost::program_options::store ( + boost::program_options::parse_config_file (configFile, desc), variables); + if (variables.count ("help")) { std::cout << desc << std::endl; } else { - maintest(); + maintest (variables["data"].as()); } } catch(exception &e)