mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-21 20:11:34 +00:00
first round of main refactoring; moving functionality out to a separate class
This commit is contained in:
parent
f32105a2ae
commit
04037fb01a
4 changed files with 190 additions and 80 deletions
|
@ -30,8 +30,8 @@ set(OGRE_HEADER ogre/renderer.hpp)
|
||||||
set(INPUT input/oismanager.cpp)
|
set(INPUT input/oismanager.cpp)
|
||||||
set(INPUT_HEADER input/oismanager.hpp input/listener.hpp input/func_binder.hpp input/dispatch_map.hpp input/dispatcher.hpp)
|
set(INPUT_HEADER input/oismanager.hpp input/listener.hpp input/func_binder.hpp input/dispatch_map.hpp input/dispatcher.hpp)
|
||||||
|
|
||||||
set(GAME game/main.cpp)
|
set(GAME game/main.cpp game/engine.cpp)
|
||||||
set(GAME_HEADER game/mwinput/inputmanager.hpp)
|
set(GAME_HEADER game/mwinput/inputmanager.hpp game/engine.hpp)
|
||||||
|
|
||||||
set(ESM_STORE esm_store/store.cpp esm_store/cell_store.cpp)
|
set(ESM_STORE esm_store/store.cpp esm_store/cell_store.cpp)
|
||||||
set(ESM_STORE_HEADER esm_store/cell_store.hpp esm_store/reclists.hpp esm_store/store.hpp)
|
set(ESM_STORE_HEADER esm_store/cell_store.hpp esm_store/reclists.hpp esm_store/store.hpp)
|
||||||
|
|
133
game/engine.cpp
Normal file
133
game/engine.cpp
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
#include "engine.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "esm_store/cell_store.hpp"
|
||||||
|
#include "bsa/bsa_archive.hpp"
|
||||||
|
#include "ogre/renderer.hpp"
|
||||||
|
#include "tools/fileops.hpp"
|
||||||
|
|
||||||
|
#include "mwrender/interior.hpp"
|
||||||
|
#include "mwinput/inputmanager.hpp"
|
||||||
|
|
||||||
|
OMW::Engine::Engine() {}
|
||||||
|
|
||||||
|
// adjust name and load bsa
|
||||||
|
|
||||||
|
void OMW::Engine::prepareMaster()
|
||||||
|
{
|
||||||
|
assert (!mDataDir.empty());
|
||||||
|
|
||||||
|
std::string masterName; // name without extension
|
||||||
|
|
||||||
|
std::string::size_type sep = mMaster.find_last_of (".");
|
||||||
|
|
||||||
|
if (sep==std::string::npos)
|
||||||
|
{
|
||||||
|
masterName = mMaster;
|
||||||
|
mMaster += ".esm";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
masterName = mMaster.substr (0, sep);
|
||||||
|
}
|
||||||
|
|
||||||
|
// bsa
|
||||||
|
boost::filesystem::path bsa (mDataDir);
|
||||||
|
bsa /= masterName + ".bsa";
|
||||||
|
|
||||||
|
if (boost::filesystem::exists (bsa))
|
||||||
|
{
|
||||||
|
std::cout << "Adding " << bsa.string() << std::endl;
|
||||||
|
addBSA(bsa.file_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// - If there is a bsa file with the same name, OpenMW will load it.
|
||||||
|
// - Currently OpenMW only supports one master at the same time.
|
||||||
|
|
||||||
|
void OMW::Engine::addMaster (const std::string& master)
|
||||||
|
{
|
||||||
|
assert (mMaster.empty());
|
||||||
|
mMaster = master;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialise and enter main loop.
|
||||||
|
|
||||||
|
void OMW::Engine::go()
|
||||||
|
{
|
||||||
|
assert (!mDataDir.empty());
|
||||||
|
assert (!mCellName.empty());
|
||||||
|
assert (!mMaster.empty());
|
||||||
|
|
||||||
|
std::cout << "Hello, fellow traveler!\n";
|
||||||
|
|
||||||
|
std::cout << "Your data directory for today is: " << mDataDir << "\n";
|
||||||
|
|
||||||
|
std::cout << "Initializing OGRE\n";
|
||||||
|
|
||||||
|
const char* plugCfg = "plugins.cfg";
|
||||||
|
|
||||||
|
mOgre.configure(!isFile("ogre.cfg"), plugCfg, false);
|
||||||
|
|
||||||
|
prepareMaster();
|
||||||
|
|
||||||
|
boost::filesystem::path masterPath (mDataDir);
|
||||||
|
masterPath /= mMaster;
|
||||||
|
|
||||||
|
std::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(masterPath.file_string());
|
||||||
|
store.load(esm);
|
||||||
|
|
||||||
|
cell.loadInt(mCellName, store, esm);
|
||||||
|
|
||||||
|
// Create the window
|
||||||
|
mOgre.createWindow("OpenMW");
|
||||||
|
|
||||||
|
std::cout << "\nSetting up cell rendering\n";
|
||||||
|
|
||||||
|
// Sets up camera, scene manager etc
|
||||||
|
MWRender::MWScene scene(mOgre);
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
std::cout << "Setting up input system\n";
|
||||||
|
|
||||||
|
// Sets up the input system
|
||||||
|
MWInput::MWInputManager input(mOgre);
|
||||||
|
|
||||||
|
std::cout << "\nStart! Press Q/ESC or close window to exit.\n";
|
||||||
|
|
||||||
|
// Start the main rendering loop
|
||||||
|
mOgre.start();
|
||||||
|
|
||||||
|
std::cout << "\nThat's all for now!\n";
|
||||||
|
}
|
||||||
|
|
49
game/engine.hpp
Normal file
49
game/engine.hpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#ifndef ENGINE_H
|
||||||
|
#define ENGINE_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
#include "mwrender/mwscene.hpp"
|
||||||
|
|
||||||
|
namespace OMW
|
||||||
|
{
|
||||||
|
/// \brief Main engine class, that brings together all the components of OpenMW
|
||||||
|
|
||||||
|
class Engine
|
||||||
|
{
|
||||||
|
boost::filesystem::path mDataDir;
|
||||||
|
Render::OgreRenderer mOgre;
|
||||||
|
std::string mCellName;
|
||||||
|
std::string mMaster;
|
||||||
|
|
||||||
|
// not implemented
|
||||||
|
Engine (const Engine&);
|
||||||
|
Engine& operator= (const Engine&);
|
||||||
|
|
||||||
|
/// adjust name and load bsa
|
||||||
|
void prepareMaster();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Engine();
|
||||||
|
|
||||||
|
/// Set data dir
|
||||||
|
void setDataDir (const boost::filesystem::path& dataDir);
|
||||||
|
|
||||||
|
/// Set start cell name (only interiors for now)
|
||||||
|
void setCell (const std::string& cellName);
|
||||||
|
|
||||||
|
/// Set master file (esm)
|
||||||
|
/// - If the given name does not have an extension, ".esm" is added automatically
|
||||||
|
/// - If there is a bsa file with the same name, OpenMW will load it.
|
||||||
|
/// - Currently OpenMW only supports one master at the same time.
|
||||||
|
void addMaster (const std::string& master);
|
||||||
|
|
||||||
|
/// Initialise and enter main loop.
|
||||||
|
void go();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -6,14 +6,7 @@
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include "esm_store/cell_store.hpp"
|
#include "engine.hpp"
|
||||||
#include "bsa/bsa_archive.hpp"
|
|
||||||
#include "ogre/renderer.hpp"
|
|
||||||
#include "tools/fileops.hpp"
|
|
||||||
|
|
||||||
#include "mwrender/interior.hpp"
|
|
||||||
#include "mwrender/mwscene.hpp"
|
|
||||||
#include "mwinput/inputmanager.hpp"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -22,80 +15,15 @@ void maintest (boost::filesystem::path dataDir, const std::string& cellName,
|
||||||
{
|
{
|
||||||
assert (!dataDir.empty());
|
assert (!dataDir.empty());
|
||||||
|
|
||||||
dataDir = boost::filesystem::system_complete (dataDir);
|
OMW::Engine engine;
|
||||||
|
|
||||||
std::string masterName; // name without extension
|
engine.setDataDir (dataDir);
|
||||||
|
|
||||||
std::string::size_type sep = master.find_last_of (".");
|
engine.setCell (cellName);
|
||||||
|
|
||||||
if (sep==std::string::npos)
|
engine.addMaster (master);
|
||||||
{
|
|
||||||
masterName = master;
|
|
||||||
master += ".esm";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
masterName = master.substr (0, sep);
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::filesystem::path masterPath (dataDir);
|
engine.go();
|
||||||
masterPath /= master;
|
|
||||||
|
|
||||||
boost::filesystem::path bsa (dataDir);
|
|
||||||
bsa /= masterName + ".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);
|
|
||||||
|
|
||||||
if (boost::filesystem::exists (bsa))
|
|
||||||
{
|
|
||||||
cout << "Adding " << bsa.string() << endl;
|
|
||||||
addBSA(bsa.file_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
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(masterPath.file_string());
|
|
||||||
store.load(esm);
|
|
||||||
|
|
||||||
cell.loadInt(cellName, store, esm);
|
|
||||||
|
|
||||||
// Create the window
|
|
||||||
ogre.createWindow("OpenMW");
|
|
||||||
|
|
||||||
cout << "\nSetting up cell rendering\n";
|
|
||||||
|
|
||||||
// Sets up camera, scene manager etc
|
|
||||||
MWRender::MWScene scene(ogre);
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
cout << "Setting up input system\n";
|
|
||||||
|
|
||||||
// Sets up the input system
|
|
||||||
MWInput::MWInputManager input(ogre);
|
|
||||||
|
|
||||||
cout << "\nStart! Press Q/ESC or close window to exit.\n";
|
|
||||||
|
|
||||||
// Start the main rendering loop
|
|
||||||
ogre.start();
|
|
||||||
|
|
||||||
cout << "\nThat's all for now!\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char**argv)
|
int main(int argc, char**argv)
|
||||||
|
|
Loading…
Reference in a new issue