diff --git a/CMakeLists.txt b/CMakeLists.txt index 76dd9c82f..2d91f8b29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,10 +10,12 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/) set(GAME apps/openmw/main.cpp - apps/openmw/engine.cpp) + apps/openmw/engine.cpp + apps/openmw/world.cpp) set(GAME_HEADER apps/openmw/mwinput/inputmanager.hpp - apps/openmw/engine.hpp) + apps/openmw/engine.hpp + apps/openmw/world.hpp) source_group(game FILES ${GAME} ${GAME_HEADER}) set(GAMEREND diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index f431e51bd..82e1ff58f 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -4,19 +4,14 @@ #include -#include "components/esm_store/cell_store.hpp" -#include "components/bsa/bsa_archive.hpp" -#include "components/engine/ogre/renderer.hpp" #include "components/misc/fileops.hpp" +#include "components/bsa/bsa_archive.hpp" -#include "apps/openmw/mwrender/interior.hpp" #include "mwinput/inputmanager.hpp" -#include "apps/openmw/mwrender/playerpos.hpp" -#include "apps/openmw/mwrender/sky.hpp" + +#include "world.hpp" OMW::Engine::Engine() - : mEnableSky (false) - , mpSkyManager (NULL) { } @@ -76,17 +71,11 @@ void OMW::Engine::addMaster (const std::string& master) } } -// Enables sky rendering -// -void OMW::Engine::enableSky (bool bEnable) -{ - mEnableSky = bEnable; -} - // Initialise and enter main loop. void OMW::Engine::go() { + assert (!mWorld); assert (!mDataDir.empty()); assert (!mCellName.empty()); assert (!mMaster.empty()); @@ -104,55 +93,29 @@ void OMW::Engine::go() addResourcesDirectory (mDataDir / "Meshes"); addResourcesDirectory (mDataDir / "Textures"); - loadBSA(); - - 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, and viewport. - MWRender::MWScene scene(mOgre); - - // Used to control the player camera and position - MWRender::PlayerPos player(scene.getCamera()); - - // 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(); - - // Optionally enable the sky - if (mEnableSky) - mpSkyManager = MWRender::SkyManager::create(mOgre.getWindow(), scene.getCamera()); + loadBSA(); + // Create the world + mWorld = new World (mOgre, mDataDir, mMaster, mCellName); + std::cout << "Setting up input system\n"; // Sets up the input system - MWInput::MWInputManager input(mOgre, player); + MWInput::MWInputManager input(mOgre, mWorld->getPlayerPos()); std::cout << "\nStart! Press Q/ESC or close window to exit.\n"; // Start the main rendering loop mOgre.start(); - delete mpSkyManager; - std::cout << "\nThat's all for now!\n"; } +OMW::Engine::~Engine() +{ + delete mWorld; +} + diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index ae69f52b4..ec9fb82d2 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -5,15 +5,12 @@ #include -#include "apps/openmw/mwrender/mwscene.hpp" - -namespace MWRender -{ - class SkyManager; -} +#include "components/engine/ogre/renderer.hpp" namespace OMW { + class World; + /// \brief Main engine class, that brings together all the components of OpenMW class Engine @@ -22,10 +19,8 @@ namespace OMW Render::OgreRenderer mOgre; std::string mCellName; std::string mMaster; + World *mWorld; - bool mEnableSky; - MWRender::SkyManager* mpSkyManager; - // not implemented Engine (const Engine&); Engine& operator= (const Engine&); @@ -41,6 +36,8 @@ namespace OMW Engine(); + ~Engine(); + /// Set data dir void setDataDir (const boost::filesystem::path& dataDir); @@ -52,9 +49,6 @@ namespace OMW /// - Currently OpenMW only supports one master at the same time. void addMaster (const std::string& master); - /// Enables rendering of the sky (off by default). - void enableSky (bool bEnable); - /// Initialise and enter main loop. void go(); }; diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 635384ad5..cb8b8f58e 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -29,7 +29,6 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) "set initial cell (only interior cells supported at the moment") ("master", bpo::value()->default_value ("Morrowind"), "master file") - ("enablesky", "enable rendering of the sky") ; bpo::variables_map variables; @@ -48,8 +47,6 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) return false; } - engine.enableSky(!!variables.count("enablesky")); - engine.setDataDir (variables["data"].as()); engine.setCell (variables["start"].as()); engine.addMaster (variables["master"].as()); diff --git a/apps/openmw/mwrender/cell.hpp b/apps/openmw/mwrender/cell.hpp index 0ddec0964..4ef4cc64c 100644 --- a/apps/openmw/mwrender/cell.hpp +++ b/apps/openmw/mwrender/cell.hpp @@ -37,6 +37,9 @@ namespace MWRender virtual std::string insertEnd() = 0; void insertCell(const ESMS::CellStore &cell); + + /// placeholder function -> need to do some heavy refactoring on the whole cell stuff + virtual void show() = 0; }; } diff --git a/apps/openmw/mwrender/interior.hpp b/apps/openmw/mwrender/interior.hpp index 7657a6751..af527f324 100644 --- a/apps/openmw/mwrender/interior.hpp +++ b/apps/openmw/mwrender/interior.hpp @@ -23,7 +23,7 @@ namespace MWRender TODO FIXME: Doesn't do full cleanup yet. */ - class InteriorCellRender : private CellRender + class InteriorCellRender : public CellRender { static bool lightConst; @@ -83,7 +83,7 @@ namespace MWRender virtual ~InteriorCellRender() { destroy(); } /// Make the cell visible. Load the cell if necessary. - void show(); + virtual void show(); /// Remove the cell from rendering, but don't remove it from /// memory.