mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-03 23:56:43 +00:00 
			
		
		
		
	factored world class out of main engine class
This commit is contained in:
		
							parent
							
								
									60fb817e89
								
							
						
					
					
						commit
						ce37666dbc
					
				
					 6 changed files with 29 additions and 70 deletions
				
			
		| 
						 | 
				
			
			@ -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 
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,19 +4,14 @@
 | 
			
		|||
 | 
			
		||||
#include <iostream>
 | 
			
		||||
 | 
			
		||||
#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";
 | 
			
		||||
    loadBSA();
 | 
			
		||||
 | 
			
		||||
    // 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());
 | 
			
		||||
    // 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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,15 +5,12 @@
 | 
			
		|||
 | 
			
		||||
#include <boost/filesystem.hpp>
 | 
			
		||||
 | 
			
		||||
#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,9 +19,7 @@ namespace OMW
 | 
			
		|||
            Render::OgreRenderer mOgre;
 | 
			
		||||
            std::string mCellName;
 | 
			
		||||
            std::string mMaster;
 | 
			
		||||
            
 | 
			
		||||
            bool                  mEnableSky;
 | 
			
		||||
            MWRender::SkyManager* mpSkyManager;
 | 
			
		||||
            World *mWorld;
 | 
			
		||||
            
 | 
			
		||||
            // not implemented
 | 
			
		||||
            Engine (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();
 | 
			
		||||
    };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<std::string>()->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<std::string>());
 | 
			
		||||
    engine.setCell (variables["start"].as<std::string>());
 | 
			
		||||
    engine.addMaster (variables["master"].as<std::string>());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue