From f32105a2ae41dce4c637772a60db3ef5771982d5 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 15 Jun 2010 19:04:52 +0200 Subject: [PATCH] added --master option; reimplemented file handling with boost::filesystem --- game/main.cpp | 104 +++++++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 40 deletions(-) diff --git a/game/main.cpp b/game/main.cpp index 5ebd093a4..58d894a66 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -3,7 +3,8 @@ #include #include -#include "boost/program_options.hpp" +#include +#include #include "esm_store/cell_store.hpp" #include "bsa/bsa_archive.hpp" @@ -16,65 +17,85 @@ using namespace std; -void maintest (std::string dataDir, const std::string& cellName) +void maintest (boost::filesystem::path dataDir, const std::string& cellName, + std::string master) { - assert (!dataDir.empty()); + assert (!dataDir.empty()); - if (dataDir[dataDir.size()-1]!='/' && dataDir[dataDir.size()-1]!='\\') - dataDir += "/"; + dataDir = boost::filesystem::system_complete (dataDir); - const char* esmFile = "Morrowind.esm"; - const char* bsaFile = "Morrowind.bsa"; + std::string masterName; // name without extension + + std::string::size_type sep = master.find_last_of ("."); + + if (sep==std::string::npos) + { + masterName = master; + master += ".esm"; + } + else + { + masterName = master.substr (0, sep); + } + + boost::filesystem::path masterPath (dataDir); + masterPath /= master; + + boost::filesystem::path bsa (dataDir); + bsa /= masterName + ".bsa"; - const char* plugCfg = "plugins.cfg"; + const char* plugCfg = "plugins.cfg"; - cout << "Hello, fellow traveler!\n"; + cout << "Hello, fellow traveler!\n"; - cout << "Your data directory for today is: " << dataDir << "\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 << "Initializing OGRE\n"; + Render::OgreRenderer ogre; + ogre.configure(!isFile("ogre.cfg"), plugCfg, false); - cout << "Adding " << bsaFile << endl; - addBSA(dataDir + bsaFile); + if (boost::filesystem::exists (bsa)) + { + cout << "Adding " << bsa.string() << endl; + addBSA(bsa.file_string()); + } - cout << "Loading ESM " << esmFile << "\n"; - ESM::ESMReader esm; - ESMS::ESMStore store; - ESMS::CellStore cell; + cout << "Loading ESM " << masterPath.string() << "\n"; + ESM::ESMReader esm; + ESMS::ESMStore store; + ESMS::CellStore cell; - // This parses the ESM file and loads a sample cell - esm.open(dataDir + esmFile); - store.load(esm); + // This parses the ESM file and loads a sample cell + esm.open(masterPath.file_string()); + store.load(esm); - cell.loadInt(cellName, store, esm); + cell.loadInt(cellName, store, esm); - // Create the window - ogre.createWindow("OpenMW"); + // Create the window + ogre.createWindow("OpenMW"); - cout << "\nSetting up cell rendering\n"; + cout << "\nSetting up cell rendering\n"; - // Sets up camera, scene manager etc - MWRender::MWScene scene(ogre); + // Sets up camera, scene manager etc + MWRender::MWScene scene(ogre); - // This connects the cell data with the rendering scene. - MWRender::InteriorCellRender rend(cell, scene); + // This connects the cell data with the rendering scene. + MWRender::InteriorCellRender rend(cell, scene); - // Load the cell and insert it into the renderer - rend.show(); + // Load the cell and insert it into the renderer + rend.show(); - cout << "Setting up input system\n"; + cout << "Setting up input system\n"; - // Sets up the input system - MWInput::MWInputManager input(ogre); + // Sets up the input system + MWInput::MWInputManager input(ogre); - cout << "\nStart! Press Q/ESC or close window to exit.\n"; + cout << "\nStart! Press Q/ESC or close window to exit.\n"; - // Start the main rendering loop - ogre.start(); + // Start the main rendering loop + ogre.start(); - cout << "\nThat's all for now!\n"; + cout << "\nThat's all for now!\n"; } int main(int argc, char**argv) @@ -90,6 +111,8 @@ int main(int argc, char**argv) "set data directory") ("start", boost::program_options::value()->default_value ("Beshara"), "set initial cell (only interior cells supported at the moment") + ("master", boost::program_options::value()->default_value ("Morrowind"), + "master file") ; boost::program_options::variables_map variables; @@ -110,7 +133,8 @@ int main(int argc, char**argv) } else { - maintest (variables["data"].as(), variables["start"].as()); + maintest (variables["data"].as(), variables["start"].as(), + variables["master"].as()); } } catch(exception &e)