2010-06-16 10:13:21 +00:00
|
|
|
#include "engine.hpp"
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2010-06-28 19:44:55 +00:00
|
|
|
#include "components/misc/fileops.hpp"
|
2010-07-02 07:00:06 +00:00
|
|
|
#include "components/bsa/bsa_archive.hpp"
|
2010-06-16 10:13:21 +00:00
|
|
|
|
|
|
|
#include "mwinput/inputmanager.hpp"
|
2010-07-02 07:00:06 +00:00
|
|
|
|
|
|
|
#include "world.hpp"
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2010-06-27 23:44:15 +00:00
|
|
|
OMW::Engine::Engine()
|
|
|
|
{
|
|
|
|
}
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2010-06-16 18:15:48 +00:00
|
|
|
// Load all BSA files in data directory.
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2010-06-16 18:15:48 +00:00
|
|
|
void OMW::Engine::loadBSA()
|
|
|
|
{
|
|
|
|
boost::filesystem::directory_iterator end;
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-06-16 18:15:48 +00:00
|
|
|
for (boost::filesystem::directory_iterator iter (mDataDir); iter!=end; ++iter)
|
2010-06-16 10:13:21 +00:00
|
|
|
{
|
2010-06-16 18:15:48 +00:00
|
|
|
if (boost::filesystem::extension (iter->path())==".bsa")
|
|
|
|
{
|
|
|
|
std::cout << "Adding " << iter->path().string() << std::endl;
|
2010-06-25 20:28:59 +00:00
|
|
|
addBSA(iter->path().file_string());
|
2010-06-16 18:15:48 +00:00
|
|
|
}
|
2010-06-16 10:13:21 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-06-16 10:58:53 +00:00
|
|
|
// add resources directory
|
|
|
|
// \note This function works recursively.
|
|
|
|
|
|
|
|
void OMW::Engine::addResourcesDirectory (const boost::filesystem::path& path)
|
|
|
|
{
|
|
|
|
mOgre.getRoot()->addResourceLocation (path.file_string(), "FileSystem",
|
|
|
|
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
|
2010-06-25 20:28:59 +00:00
|
|
|
}
|
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
// Set data dir
|
|
|
|
|
|
|
|
void OMW::Engine::setDataDir (const boost::filesystem::path& dataDir)
|
|
|
|
{
|
|
|
|
mDataDir = boost::filesystem::system_complete (dataDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set start cell name (only interiors for now)
|
|
|
|
|
|
|
|
void OMW::Engine::setCell (const std::string& cellName)
|
|
|
|
{
|
|
|
|
mCellName = cellName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set master file (esm)
|
|
|
|
// - If the given name does not have an extension, ".esm" is added automatically
|
|
|
|
// - Currently OpenMW only supports one master at the same time.
|
|
|
|
|
|
|
|
void OMW::Engine::addMaster (const std::string& master)
|
|
|
|
{
|
|
|
|
assert (mMaster.empty());
|
|
|
|
mMaster = master;
|
2010-06-30 18:32:40 +00:00
|
|
|
|
|
|
|
// Append .esm if not already there
|
|
|
|
std::string::size_type sep = mMaster.find_last_of (".");
|
|
|
|
if (sep == std::string::npos)
|
|
|
|
{
|
|
|
|
mMaster += ".esm";
|
|
|
|
}
|
2010-06-16 10:13:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialise and enter main loop.
|
|
|
|
|
|
|
|
void OMW::Engine::go()
|
|
|
|
{
|
2010-07-02 07:00:06 +00:00
|
|
|
assert (!mWorld);
|
2010-06-16 10:13:21 +00:00
|
|
|
assert (!mDataDir.empty());
|
|
|
|
assert (!mCellName.empty());
|
|
|
|
assert (!mMaster.empty());
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
std::cout << "Hello, fellow traveler!\n";
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
std::cout << "Your data directory for today is: " << mDataDir << "\n";
|
|
|
|
|
|
|
|
std::cout << "Initializing OGRE\n";
|
|
|
|
|
|
|
|
const char* plugCfg = "plugins.cfg";
|
|
|
|
|
2010-06-28 19:44:55 +00:00
|
|
|
mOgre.configure(!isFile("ogre.cfg"), plugCfg, false);
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-06-16 10:58:53 +00:00
|
|
|
addResourcesDirectory (mDataDir / "Meshes");
|
|
|
|
addResourcesDirectory (mDataDir / "Textures");
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
// Create the window
|
|
|
|
mOgre.createWindow("OpenMW");
|
|
|
|
|
2010-07-02 07:00:06 +00:00
|
|
|
loadBSA();
|
2010-06-28 00:28:49 +00:00
|
|
|
|
2010-07-02 07:00:06 +00:00
|
|
|
// Create the world
|
|
|
|
mWorld = new World (mOgre, mDataDir, mMaster, mCellName);
|
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
std::cout << "Setting up input system\n";
|
|
|
|
|
|
|
|
// Sets up the input system
|
2010-07-02 07:00:06 +00:00
|
|
|
MWInput::MWInputManager input(mOgre, mWorld->getPlayerPos());
|
2010-06-16 10:13:21 +00:00
|
|
|
|
|
|
|
std::cout << "\nStart! Press Q/ESC or close window to exit.\n";
|
|
|
|
|
|
|
|
// Start the main rendering loop
|
|
|
|
mOgre.start();
|
|
|
|
|
2010-06-25 20:28:59 +00:00
|
|
|
std::cout << "\nThat's all for now!\n";
|
2010-06-16 10:13:21 +00:00
|
|
|
}
|
|
|
|
|
2010-07-02 07:00:06 +00:00
|
|
|
OMW::Engine::~Engine()
|
|
|
|
{
|
|
|
|
delete mWorld;
|
|
|
|
}
|
|
|
|
|