示例#1
0
文件: engine.cpp 项目: jhooks1/openmw
void OMW::Engine::prepareEngine (Settings::Manager & settings)
{
    Nif::NIFFile::CacheLock cachelock;

    std::string renderSystem = settings.getString("render system", "Video");
    if (renderSystem == "")
    {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        renderSystem = "Direct3D9 Rendering Subsystem";
#else
        renderSystem = "OpenGL Rendering Subsystem";
#endif
    }

    mOgre = new OEngine::Render::OgreRenderer;

    mOgre->configure(
        mCfgMgr.getLogPath().string(),
        renderSystem,
        Settings::Manager::getString("opengl rtt mode", "Video"),
        false);

    // This has to be added BEFORE MyGUI is initialized, as it needs
    // to find core.xml here.

    //addResourcesDirectory(mResDir);

    addResourcesDirectory(mCfgMgr.getCachePath ().string());

    addResourcesDirectory(mResDir / "mygui");
    addResourcesDirectory(mResDir / "water");
    addResourcesDirectory(mResDir / "shadows");
    addZipResource(mResDir / "mygui" / "Obliviontt.zip");

    OEngine::Render::WindowSettings windowSettings;
    windowSettings.fullscreen = settings.getBool("fullscreen", "Video");
    windowSettings.window_x = settings.getInt("resolution x", "Video");
    windowSettings.window_y = settings.getInt("resolution y", "Video");
    windowSettings.screen = settings.getInt("screen", "Video");
    windowSettings.vsync = settings.getBool("vsync", "Video");
    windowSettings.icon = "openmw.png";
    std::string aa = settings.getString("antialiasing", "Video");
    windowSettings.fsaa = (aa.substr(0, 4) == "MSAA") ? aa.substr(5, aa.size()-5) : "0";

    mOgre->createWindow("OpenMW", windowSettings);

    loadBSA();

    // Create the world
    mEnvironment.setWorld( new MWWorld::World (*mOgre, mFileCollections, mMaster, mPlugins,
        mResDir, mCfgMgr.getCachePath(), mEncoder, mFallbackMap,
        mActivationDistanceOverride));
    MWBase::Environment::get().getWorld()->setupPlayer();

    //Load translation data
    mTranslationDataStorage.setEncoder(mEncoder);
    for (size_t i = 0; i < mMaster.size(); i++)
      mTranslationDataStorage.loadTranslationData(mFileCollections, mMaster[i]);

    // Create window manager - this manages all the MW-specific GUI windows
    MWScript::registerExtensions (mExtensions);

    mEnvironment.setWindowManager (new MWGui::WindowManager(
        mExtensions, mFpsLevel, mOgre, mCfgMgr.getLogPath().string() + std::string("/"),
        mCfgMgr.getCachePath ().string(), mScriptConsoleMode, mTranslationDataStorage, mEncoding));
    if (mNewGame)
        mEnvironment.getWindowManager()->setNewGame(true);

    // Create sound system
    mEnvironment.setSoundManager (new MWSound::SoundManager(mUseSound));

    // Create script system
    mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full);
    mScriptContext->setExtensions (&mExtensions);

    mEnvironment.setScriptManager (new MWScript::ScriptManager (MWBase::Environment::get().getWorld()->getStore(),
        mVerboseScripts, *mScriptContext));

    // Create game mechanics system
    mEnvironment.setMechanicsManager (new MWMechanics::MechanicsManager);

    // Create dialog system
    mEnvironment.setJournal (new MWDialogue::Journal);
    mEnvironment.setDialogueManager (new MWDialogue::DialogueManager (mExtensions, mVerboseScripts, mTranslationDataStorage));

    // Sets up the input system

    // Get the path for the keybinder xml file
    std::string keybinderUser = (mCfgMgr.getUserPath() / "input.xml").string();
    bool keybinderUserExists = boost::filesystem::exists(keybinderUser);

    mEnvironment.setInputManager (new MWInput::InputManager (*mOgre,
        MWBase::Environment::get().getWorld()->getPlayer(),
         *MWBase::Environment::get().getWindowManager(), *this, keybinderUser, keybinderUserExists));

    mEnvironment.getWorld()->renderPlayer();

    if (!mNewGame)
    {
        // load cell
        ESM::Position pos;
        MWBase::World *world = MWBase::Environment::get().getWorld();

        if (world->findExteriorPosition(mCellName, pos)) {
            world->changeToExteriorCell (pos);
        }
        else {
            world->findInteriorPosition(mCellName, pos);
            world->changeToInteriorCell (mCellName, pos);
        }
    }
    else
        mEnvironment.getWorld()->startNewGame();

    Ogre::FrameEvent event;
    event.timeSinceLastEvent = 0;
    event.timeSinceLastFrame = 0;
    frameRenderingQueued(event);
    mOgre->getRoot()->addFrameListener (this);

    // scripts
    if (mCompileAll)
    {
        std::pair<int, int> result = MWBase::Environment::get().getScriptManager()->compileAll();

        if (result.first)
            std::cout
                << "compiled " << result.second << " of " << result.first << " scripts ("
                << 100*static_cast<double> (result.second)/result.first
                << "%)"
                << std::endl;
    }
}
示例#2
0
void OMW::Engine::prepareEngine (Settings::Manager & settings)
{
    mEnvironment.setStateManager (
        new MWState::StateManager (mCfgMgr.getUserDataPath() / "saves", mContentFiles.at (0)));

    Nif::NIFFile::CacheLock cachelock;

    std::string renderSystem = settings.getString("render system", "Video");
    if (renderSystem == "")
    {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        renderSystem = "Direct3D9 Rendering Subsystem";
#else
        renderSystem = "OpenGL Rendering Subsystem";
#endif
    }

    mOgre = new OEngine::Render::OgreRenderer;

    mOgre->configure(
        mCfgMgr.getLogPath().string(),
        renderSystem,
        Settings::Manager::getString("opengl rtt mode", "Video"));

    // This has to be added BEFORE MyGUI is initialized, as it needs
    // to find core.xml here.

    //addResourcesDirectory(mResDir);

    addResourcesDirectory(mCfgMgr.getCachePath ().string());

    addResourcesDirectory(mResDir / "mygui");
    addResourcesDirectory(mResDir / "water");
    addResourcesDirectory(mResDir / "shadows");

    OEngine::Render::WindowSettings windowSettings;
    windowSettings.fullscreen = settings.getBool("fullscreen", "Video");
    windowSettings.window_x = settings.getInt("resolution x", "Video");
    windowSettings.window_y = settings.getInt("resolution y", "Video");
    windowSettings.screen = settings.getInt("screen", "Video");
    windowSettings.vsync = settings.getBool("vsync", "Video");
    windowSettings.icon = "openmw.png";
    std::string aa = settings.getString("antialiasing", "Video");
    windowSettings.fsaa = (aa.substr(0, 4) == "MSAA") ? aa.substr(5, aa.size()-5) : "0";

    mOgre->createWindow("OpenMW", windowSettings);

    loadBSA();


    // Create input and UI first to set up a bootstrapping environment for
    // showing a loading screen and keeping the window responsive while doing so

    std::string keybinderUser = (mCfgMgr.getUserConfigPath() / "input.xml").string();
    bool keybinderUserExists = boost::filesystem::exists(keybinderUser);
    MWInput::InputManager* input = new MWInput::InputManager (*mOgre, *this, keybinderUser, keybinderUserExists, mGrab);
    mEnvironment.setInputManager (input);

    MWGui::WindowManager* window = new MWGui::WindowManager(
                mExtensions, mFpsLevel, mOgre, mCfgMgr.getLogPath().string() + std::string("/"),
                mCfgMgr.getCachePath ().string(), mScriptConsoleMode, mTranslationDataStorage, mEncoding);
    mEnvironment.setWindowManager (window);

    // Create the world
    mEnvironment.setWorld( new MWWorld::World (*mOgre, mFileCollections, mContentFiles,
        mResDir, mCfgMgr.getCachePath(), mEncoder, mFallbackMap,
        mActivationDistanceOverride));
    MWBase::Environment::get().getWorld()->setupPlayer();
    input->setPlayer(&mEnvironment.getWorld()->getPlayer());

    window->initUI();
    window->renderWorldMap();

    //Load translation data
    mTranslationDataStorage.setEncoder(mEncoder);
    for (size_t i = 0; i < mContentFiles.size(); i++)
      mTranslationDataStorage.loadTranslationData(mFileCollections, mContentFiles[i]);

    Compiler::registerExtensions (mExtensions);

    // Create sound system
    mEnvironment.setSoundManager (new MWSound::SoundManager(mUseSound));

    // Create script system
    mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full);
    mScriptContext->setExtensions (&mExtensions);

    mEnvironment.setScriptManager (new MWScript::ScriptManager (MWBase::Environment::get().getWorld()->getStore(),
        mVerboseScripts, *mScriptContext));

    // Create game mechanics system
    MWMechanics::MechanicsManager* mechanics = new MWMechanics::MechanicsManager;
    mEnvironment.setMechanicsManager (mechanics);

    // Create dialog system
    mEnvironment.setJournal (new MWDialogue::Journal);
    mEnvironment.setDialogueManager (new MWDialogue::DialogueManager (mExtensions, mVerboseScripts, mTranslationDataStorage));

    mEnvironment.getWorld()->renderPlayer();
    mechanics->buildPlayer();
    window->updatePlayer();

    // load cell
    ESM::Position pos;
    MWBase::World *world = MWBase::Environment::get().getWorld();

    if (!mCellName.empty())
    {
        if (world->findExteriorPosition(mCellName, pos)) {
            world->changeToExteriorCell (pos);
        }
        else {
            world->findInteriorPosition(mCellName, pos);
            world->changeToInteriorCell (mCellName, pos);
        }
    }
    else
    {
        pos.pos[0] = pos.pos[1] = pos.pos[2] = 0;
        pos.rot[0] = pos.rot[1] = pos.pos[2] = 0;
        world->changeToExteriorCell (pos);
    }

    Ogre::FrameEvent event;
    event.timeSinceLastEvent = 0;
    event.timeSinceLastFrame = 0;
    frameRenderingQueued(event);
    mOgre->getRoot()->addFrameListener (this);

    // scripts
    if (mCompileAll)
    {
        std::pair<int, int> result = MWBase::Environment::get().getScriptManager()->compileAll();

        if (result.first)
            std::cout
                << "compiled " << result.second << " of " << result.first << " scripts ("
                << 100*static_cast<double> (result.second)/result.first
                << "%)"
                << std::endl;
    }
}
//-------------------------------------------------------------------------------------
bool App::update(float a_DeltaT)
{
	//process networking
	m_NetworkManager.ProcessNetworkIO(a_DeltaT);
	
	//get window messages
	MSG  msg;
	while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	//check to see if we've connected to a new server
	if(m_NetworkManager.IsConnectedToServer() && !m_SceneSetup)
		createScene();

	//check to see if we've been disconnected from a server
	if(!m_NetworkManager.IsConnectedToServer() && m_SceneSetup)
		destroyScene();

	//check to see if any new players have joined
	while(m_NetworkManager.HaveNewPlayersConnected())
	{
		NodeInfo newConnectee = m_NetworkManager.GetNewConnectee();
		m_Entities.push_back(new PlayerEntity(newConnectee.nodeName, newConnectee.node_uid, *mSceneMgr, NULL));
		m_ConnectedNodes.push_back(newConnectee);
	}

	//update player
	if(m_pPlayerEntity)
		m_pPlayerEntity->Update(a_DeltaT);
	else
		std::cout << "";
	
	//check to see if we have any updated info from other entities
	if(m_NetworkManager.HaveEntitiesUpdatedPos())
	{
		std::map<int, Ogre::Vector3> newPositions = m_NetworkManager.GetNewEntityPos();
		while(newPositions.size())
		{
			for(unsigned short n=0;n<m_Entities.size();n++)
			{
				if(m_Entities[n]->GetNodeUID() == newPositions.begin()->first)
				{
					m_Entities[n]->SetPosition( newPositions.begin()->second );
					break;
				}
			}
			newPositions.erase(newPositions.begin());
		}
	}

	//update all other entities
	for(unsigned short n=0;n<m_Entities.size();n++)
	{
		if(m_Entities[n])
			m_Entities[n]->Update(a_DeltaT);
	}

	//handle input injection and misc other
	Ogre::FrameEvent frameEvent;
	frameRenderingQueued(frameEvent);

	//render a single frame
	return mRoot->renderOneFrame();
}