2010-06-16 10:13:21 +00:00
|
|
|
#include "engine.hpp"
|
2013-01-12 21:52:26 +00:00
|
|
|
|
2013-12-05 13:23:39 +00:00
|
|
|
#include <stdexcept>
|
2014-02-19 17:40:29 +00:00
|
|
|
#include <iomanip>
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2011-10-09 11:12:44 +00:00
|
|
|
#include <OgreRoot.h>
|
2012-01-16 15:33:21 +00:00
|
|
|
#include <OgreRenderWindow.h>
|
2011-10-09 11:12:44 +00:00
|
|
|
|
|
|
|
#include <MyGUI_WidgetManager.h>
|
|
|
|
|
2013-11-16 09:31:46 +00:00
|
|
|
#include <SDL.h>
|
|
|
|
|
2013-08-07 17:16:20 +00:00
|
|
|
#include <components/compiler/extensions0.hpp>
|
2013-08-07 00:38:41 +00:00
|
|
|
|
2014-03-09 10:42:39 +00:00
|
|
|
#include <components/bsa/resources.hpp>
|
2012-01-21 00:14:35 +00:00
|
|
|
#include <components/files/configurationmanager.hpp>
|
2012-12-25 19:20:39 +00:00
|
|
|
#include <components/translation/translation.hpp>
|
2012-04-11 18:13:15 +00:00
|
|
|
#include <components/nifoverrides/nifoverrides.hpp>
|
2012-01-21 00:14:35 +00:00
|
|
|
|
2013-02-24 21:52:23 +00:00
|
|
|
#include <components/nifbullet/bulletnifloader.hpp>
|
|
|
|
#include <components/nifogre/ogrenifloader.hpp>
|
2010-07-16 20:27:50 +00:00
|
|
|
|
2013-12-05 13:23:39 +00:00
|
|
|
#include <components/esm/loadcell.hpp>
|
|
|
|
|
2012-08-11 15:53:39 +00:00
|
|
|
#include "mwinput/inputmanagerimp.hpp"
|
2010-07-03 13:41:20 +00:00
|
|
|
|
2012-08-12 16:11:09 +00:00
|
|
|
#include "mwgui/windowmanagerimp.hpp"
|
2011-10-09 11:12:44 +00:00
|
|
|
|
2012-08-08 13:18:55 +00:00
|
|
|
#include "mwscript/scriptmanagerimp.hpp"
|
2010-07-03 10:12:13 +00:00
|
|
|
#include "mwscript/extensions.hpp"
|
2012-11-10 13:31:58 +00:00
|
|
|
#include "mwscript/interpretercontext.hpp"
|
2010-07-02 07:00:06 +00:00
|
|
|
|
2012-08-09 12:33:21 +00:00
|
|
|
#include "mwsound/soundmanagerimp.hpp"
|
2010-07-03 13:17:02 +00:00
|
|
|
|
2010-08-03 20:06:48 +00:00
|
|
|
#include "mwworld/class.hpp"
|
2011-01-04 14:58:22 +00:00
|
|
|
#include "mwworld/player.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "mwworld/worldimp.hpp"
|
2010-08-03 11:17:31 +00:00
|
|
|
|
|
|
|
#include "mwclass/classes.hpp"
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2012-08-09 08:35:53 +00:00
|
|
|
#include "mwdialogue/dialoguemanagerimp.hpp"
|
2012-08-09 10:56:03 +00:00
|
|
|
#include "mwdialogue/journalimp.hpp"
|
2010-08-06 16:01:34 +00:00
|
|
|
|
2012-08-11 15:30:55 +00:00
|
|
|
#include "mwmechanics/mechanicsmanagerimp.hpp"
|
2010-07-26 09:15:38 +00:00
|
|
|
|
2013-11-16 09:31:46 +00:00
|
|
|
#include "mwstate/statemanagerimp.hpp"
|
2012-01-10 05:34:29 +00:00
|
|
|
|
2010-07-02 14:18:25 +00:00
|
|
|
void OMW::Engine::executeLocalScripts()
|
|
|
|
{
|
2012-04-23 13:27:03 +00:00
|
|
|
MWWorld::LocalScripts& localScripts = MWBase::Environment::get().getWorld()->getLocalScripts();
|
2011-10-06 10:29:59 +00:00
|
|
|
|
|
|
|
localScripts.startIteration();
|
|
|
|
|
|
|
|
while (!localScripts.isFinished())
|
2010-07-02 14:18:25 +00:00
|
|
|
{
|
2011-10-06 10:29:59 +00:00
|
|
|
std::pair<std::string, MWWorld::Ptr> script = localScripts.getNext();
|
2010-08-01 08:25:50 +00:00
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
MWScript::InterpreterContext interpreterContext (
|
2011-10-06 10:29:59 +00:00
|
|
|
&script.second.getRefData().getLocals(), script.second);
|
2012-04-23 13:27:03 +00:00
|
|
|
MWBase::Environment::get().getScriptManager()->run (script.first, interpreterContext);
|
2010-07-02 14:18:25 +00:00
|
|
|
}
|
2010-08-05 13:46:50 +00:00
|
|
|
|
2011-10-07 07:52:42 +00:00
|
|
|
localScripts.setIgnore (MWWorld::Ptr());
|
2010-07-02 14:18:25 +00:00
|
|
|
}
|
2010-07-01 18:49:00 +00:00
|
|
|
|
2013-03-05 13:24:29 +00:00
|
|
|
bool OMW::Engine::frameStarted (const Ogre::FrameEvent& evt)
|
|
|
|
{
|
2014-05-15 22:58:12 +00:00
|
|
|
if (MWBase::Environment::get().getStateManager()->getState()!=
|
|
|
|
MWBase::StateManager::State_NoGame)
|
|
|
|
{
|
|
|
|
bool paused = MWBase::Environment::get().getWindowManager()->isGuiMode();
|
|
|
|
MWBase::Environment::get().getWorld()->frameStarted(evt.timeSinceLastFrame, paused);
|
|
|
|
MWBase::Environment::get().getWindowManager ()->frameStarted(evt.timeSinceLastFrame);
|
|
|
|
}
|
2013-03-05 13:24:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-18 14:37:09 +00:00
|
|
|
bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
|
2010-07-02 15:30:26 +00:00
|
|
|
{
|
2011-10-06 10:34:13 +00:00
|
|
|
try
|
2011-02-18 14:46:24 +00:00
|
|
|
{
|
2013-02-23 21:15:37 +00:00
|
|
|
float frametime = std::min(evt.timeSinceLastFrame, 0.2f);
|
2013-01-14 01:32:45 +00:00
|
|
|
|
2013-06-12 10:34:33 +00:00
|
|
|
mEnvironment.setFrameDuration (frametime);
|
2011-10-08 08:15:03 +00:00
|
|
|
|
2012-04-05 19:16:51 +00:00
|
|
|
// update input
|
2013-02-23 21:15:37 +00:00
|
|
|
MWBase::Environment::get().getInputManager()->update(frametime, false);
|
2012-04-05 19:16:51 +00:00
|
|
|
|
2014-09-03 02:54:07 +00:00
|
|
|
// When the window is minimized, pause everything. Currently this *has* to be here to work around a MyGUI bug.
|
|
|
|
// If we are not currently rendering, then RenderItems will not be reused resulting in a memory leak upon changing widget textures.
|
|
|
|
if (!mOgre->getWindow()->isActive() || !mOgre->getWindow()->isVisible())
|
|
|
|
return true;
|
|
|
|
|
2011-10-09 07:28:36 +00:00
|
|
|
// sound
|
|
|
|
if (mUseSound)
|
2013-02-23 21:15:37 +00:00
|
|
|
MWBase::Environment::get().getSoundManager()->update(frametime);
|
2010-10-31 16:23:03 +00:00
|
|
|
|
2014-06-14 22:09:12 +00:00
|
|
|
// GUI active? Most game processing will be paused, but scripts still run.
|
|
|
|
bool guiActive = MWBase::Environment::get().getWindowManager()->isGuiMode();
|
|
|
|
|
|
|
|
// Main menu opened? Then scripts are also paused.
|
|
|
|
bool paused = MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_MainMenu);
|
2014-01-25 14:54:24 +00:00
|
|
|
|
2014-01-25 21:20:46 +00:00
|
|
|
// update game state
|
|
|
|
MWBase::Environment::get().getStateManager()->update (frametime);
|
|
|
|
|
2013-12-16 19:02:21 +00:00
|
|
|
if (MWBase::Environment::get().getStateManager()->getState()==
|
|
|
|
MWBase::StateManager::State_Running)
|
|
|
|
{
|
2014-06-14 22:09:12 +00:00
|
|
|
if (!paused)
|
|
|
|
{
|
|
|
|
// global scripts
|
|
|
|
MWBase::Environment::get().getScriptManager()->getGlobalScripts().run();
|
2010-07-22 10:46:24 +00:00
|
|
|
|
2014-06-14 22:09:12 +00:00
|
|
|
// local scripts
|
|
|
|
executeLocalScripts();
|
2010-07-22 10:46:24 +00:00
|
|
|
|
2014-06-14 22:09:12 +00:00
|
|
|
MWBase::Environment::get().getWorld()->markCellAsUnchanged();
|
|
|
|
}
|
2010-08-01 08:25:50 +00:00
|
|
|
|
2014-06-14 22:09:12 +00:00
|
|
|
if (!guiActive)
|
2013-12-16 19:02:21 +00:00
|
|
|
MWBase::Environment::get().getWorld()->advanceTime(
|
|
|
|
frametime*MWBase::Environment::get().getWorld()->getTimeScaleFactor()/3600);
|
|
|
|
}
|
2012-01-23 13:33:06 +00:00
|
|
|
|
2010-08-01 08:25:50 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
// update actors
|
2014-05-15 22:58:12 +00:00
|
|
|
if (MWBase::Environment::get().getStateManager()->getState()!=
|
|
|
|
MWBase::StateManager::State_NoGame)
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->update(frametime,
|
2014-06-14 22:09:12 +00:00
|
|
|
guiActive);
|
2014-05-15 22:58:12 +00:00
|
|
|
}
|
2013-11-28 08:33:50 +00:00
|
|
|
|
2013-12-16 13:40:47 +00:00
|
|
|
if (MWBase::Environment::get().getStateManager()->getState()==
|
|
|
|
MWBase::StateManager::State_Running)
|
|
|
|
{
|
2014-01-25 14:54:24 +00:00
|
|
|
MWWorld::Ptr player = mEnvironment.getWorld()->getPlayerPtr();
|
2014-06-14 22:09:12 +00:00
|
|
|
if(!guiActive && player.getClass().getCreatureStats(player).isDead())
|
2013-12-16 13:40:47 +00:00
|
|
|
MWBase::Environment::get().getStateManager()->endGame();
|
2013-11-16 16:46:48 +00:00
|
|
|
}
|
2010-07-22 10:29:23 +00:00
|
|
|
|
2012-01-23 13:33:06 +00:00
|
|
|
// update world
|
2014-05-15 22:58:12 +00:00
|
|
|
if (MWBase::Environment::get().getStateManager()->getState()!=
|
|
|
|
MWBase::StateManager::State_NoGame)
|
|
|
|
{
|
2014-06-14 22:09:12 +00:00
|
|
|
MWBase::Environment::get().getWorld()->update(frametime, guiActive);
|
2014-05-15 22:58:12 +00:00
|
|
|
}
|
2012-01-23 13:33:06 +00:00
|
|
|
|
2012-04-14 15:47:44 +00:00
|
|
|
// update GUI
|
2014-05-29 15:21:35 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->onFrame(frametime);
|
2014-05-15 22:58:12 +00:00
|
|
|
if (MWBase::Environment::get().getStateManager()->getState()!=
|
|
|
|
MWBase::StateManager::State_NoGame)
|
|
|
|
{
|
|
|
|
Ogre::RenderWindow* window = mOgre->getWindow();
|
|
|
|
unsigned int tri, batch;
|
|
|
|
MWBase::Environment::get().getWorld()->getTriangleBatchCount(tri, batch);
|
|
|
|
MWBase::Environment::get().getWindowManager()->wmUpdateFps(window->getLastFPS(), tri, batch);
|
2012-04-14 15:47:44 +00:00
|
|
|
|
2014-05-15 22:58:12 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->update();
|
|
|
|
}
|
2010-09-18 06:39:21 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
std::cerr << "Error in framelistener: " << e.what() << std::endl;
|
2010-08-03 18:40:45 +00:00
|
|
|
}
|
|
|
|
|
2010-07-02 15:30:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-21 00:14:35 +00:00
|
|
|
OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
|
2011-10-09 11:05:38 +00:00
|
|
|
: mOgre (0)
|
2012-01-16 15:33:21 +00:00
|
|
|
, mFpsLevel(0)
|
2010-07-07 07:55:44 +00:00
|
|
|
, mVerboseScripts (false)
|
2013-11-16 10:33:20 +00:00
|
|
|
, mSkipMenu (false)
|
2010-08-18 09:16:15 +00:00
|
|
|
, mUseSound (true)
|
2010-10-06 12:52:53 +00:00
|
|
|
, mCompileAll (false)
|
2014-02-02 13:09:59 +00:00
|
|
|
, mWarningsMode (1)
|
2010-07-07 07:55:44 +00:00
|
|
|
, mScriptContext (0)
|
2011-05-05 17:56:16 +00:00
|
|
|
, mFSStrict (false)
|
2012-07-30 09:43:28 +00:00
|
|
|
, mScriptConsoleMode (false)
|
2011-08-19 19:06:09 +00:00
|
|
|
, mCfgMgr(configurationManager)
|
2013-07-31 16:46:32 +00:00
|
|
|
, mEncoding(ToUTF8::WINDOWS_1252)
|
|
|
|
, mEncoder(NULL)
|
|
|
|
, mActivationDistanceOverride(-1)
|
2013-11-29 19:06:54 +00:00
|
|
|
, mGrab(true)
|
2014-07-21 07:34:10 +00:00
|
|
|
, mScriptBlacklistUse (true)
|
2014-08-11 18:37:29 +00:00
|
|
|
, mExportFonts(false)
|
2014-09-01 09:55:12 +00:00
|
|
|
, mNewGame (false)
|
2010-08-01 08:25:50 +00:00
|
|
|
{
|
2011-10-06 10:36:16 +00:00
|
|
|
std::srand ( std::time(NULL) );
|
2010-08-03 11:17:31 +00:00
|
|
|
MWClass::registerClasses();
|
2013-01-14 01:32:45 +00:00
|
|
|
|
|
|
|
Uint32 flags = SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE;
|
|
|
|
if(SDL_WasInit(flags) == 0)
|
|
|
|
{
|
|
|
|
//kindly ask SDL not to trash our OGL context
|
|
|
|
//might this be related to http://bugzilla.libsdl.org/show_bug.cgi?id=748 ?
|
|
|
|
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
|
2014-01-11 10:00:34 +00:00
|
|
|
SDL_SetMainReady();
|
2013-01-14 01:32:45 +00:00
|
|
|
if(SDL_Init(flags) != 0)
|
2013-06-23 23:45:23 +00:00
|
|
|
{
|
|
|
|
throw std::runtime_error("Could not initialize SDL! " + std::string(SDL_GetError()));
|
|
|
|
}
|
2013-01-14 01:32:45 +00:00
|
|
|
}
|
2010-06-27 23:44:15 +00:00
|
|
|
}
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2010-07-02 11:12:05 +00:00
|
|
|
OMW::Engine::~Engine()
|
|
|
|
{
|
2012-05-04 15:20:57 +00:00
|
|
|
mEnvironment.cleanup();
|
2010-07-02 15:21:27 +00:00
|
|
|
delete mScriptContext;
|
2011-10-09 11:05:38 +00:00
|
|
|
delete mOgre;
|
2013-01-14 01:32:45 +00:00
|
|
|
SDL_Quit();
|
2010-07-02 11:12:05 +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)
|
|
|
|
{
|
2011-10-09 11:05:38 +00:00
|
|
|
mOgre->getRoot()->addResourceLocation (path.string(), "FileSystem",
|
2010-06-16 10:58:53 +00:00
|
|
|
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
|
2010-06-25 20:28:59 +00:00
|
|
|
}
|
|
|
|
|
2012-05-09 00:16:10 +00:00
|
|
|
void OMW::Engine::addZipResource (const boost::filesystem::path& path)
|
|
|
|
{
|
|
|
|
mOgre->getRoot()->addResourceLocation (path.string(), "Zip",
|
|
|
|
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, false);
|
|
|
|
}
|
|
|
|
|
2011-08-19 19:06:09 +00:00
|
|
|
void OMW::Engine::enableFSStrict(bool fsStrict)
|
2011-05-05 17:56:16 +00:00
|
|
|
{
|
2011-08-19 19:06:09 +00:00
|
|
|
mFSStrict = fsStrict;
|
2011-05-05 17:56:16 +00:00
|
|
|
}
|
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
// Set data dir
|
|
|
|
|
2011-09-02 20:45:21 +00:00
|
|
|
void OMW::Engine::setDataDirs (const Files::PathContainer& dataDirs)
|
2010-06-16 10:13:21 +00:00
|
|
|
{
|
2012-01-29 19:27:03 +00:00
|
|
|
mDataDirs = dataDirs;
|
2011-05-05 17:56:16 +00:00
|
|
|
mFileCollections = Files::Collections (dataDirs, !mFSStrict);
|
2010-06-16 10:13:21 +00:00
|
|
|
}
|
|
|
|
|
2013-03-09 20:08:08 +00:00
|
|
|
// Add BSA archive
|
|
|
|
void OMW::Engine::addArchive (const std::string& archive) {
|
|
|
|
mArchives.push_back(archive);
|
|
|
|
}
|
|
|
|
|
2011-01-04 00:34:55 +00:00
|
|
|
// Set resource dir
|
|
|
|
void OMW::Engine::setResourceDir (const boost::filesystem::path& parResDir)
|
|
|
|
{
|
2014-05-21 11:39:58 +00:00
|
|
|
mResDir = parResDir;
|
2011-01-04 00:34:55 +00:00
|
|
|
}
|
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
// Set start cell name (only interiors for now)
|
|
|
|
|
|
|
|
void OMW::Engine::setCell (const std::string& cellName)
|
|
|
|
{
|
|
|
|
mCellName = cellName;
|
|
|
|
}
|
|
|
|
|
2013-09-29 07:11:57 +00:00
|
|
|
void OMW::Engine::addContentFile(const std::string& file)
|
2010-06-16 10:13:21 +00:00
|
|
|
{
|
2014-01-27 12:27:42 +00:00
|
|
|
mContentFiles.push_back(file);
|
2010-06-16 10:13:21 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 19:06:09 +00:00
|
|
|
void OMW::Engine::setScriptsVerbosity(bool scriptsVerbosity)
|
2010-07-02 14:18:25 +00:00
|
|
|
{
|
2011-08-19 19:06:09 +00:00
|
|
|
mVerboseScripts = scriptsVerbosity;
|
2010-07-02 14:18:25 +00:00
|
|
|
}
|
2010-07-01 18:49:00 +00:00
|
|
|
|
2014-09-01 09:55:12 +00:00
|
|
|
void OMW::Engine::setSkipMenu (bool skipMenu, bool newGame)
|
2010-07-04 14:00:32 +00:00
|
|
|
{
|
2013-11-16 10:33:20 +00:00
|
|
|
mSkipMenu = skipMenu;
|
2014-09-01 09:55:12 +00:00
|
|
|
mNewGame = newGame;
|
2010-07-04 14:00:32 +00:00
|
|
|
}
|
|
|
|
|
2013-01-08 17:45:01 +00:00
|
|
|
std::string OMW::Engine::loadSettings (Settings::Manager & settings)
|
2010-06-16 10:13:21 +00:00
|
|
|
{
|
2012-04-02 11:47:25 +00:00
|
|
|
// Create the settings manager and load default settings file
|
2012-04-01 15:14:49 +00:00
|
|
|
const std::string localdefault = mCfgMgr.getLocalPath().string() + "/settings-default.cfg";
|
|
|
|
const std::string globaldefault = mCfgMgr.getGlobalPath().string() + "/settings-default.cfg";
|
|
|
|
|
|
|
|
// prefer local
|
|
|
|
if (boost::filesystem::exists(localdefault))
|
|
|
|
settings.loadDefault(localdefault);
|
|
|
|
else if (boost::filesystem::exists(globaldefault))
|
|
|
|
settings.loadDefault(globaldefault);
|
2012-05-07 21:16:29 +00:00
|
|
|
else
|
|
|
|
throw std::runtime_error ("No default settings file found! Make sure the file \"settings-default.cfg\" was properly installed.");
|
2012-04-01 14:59:35 +00:00
|
|
|
|
2012-04-02 11:47:25 +00:00
|
|
|
// load user settings if they exist, otherwise just load the default settings as user settings
|
2013-12-26 00:24:43 +00:00
|
|
|
const std::string settingspath = mCfgMgr.getUserConfigPath().string() + "/settings.cfg";
|
2012-04-01 14:59:35 +00:00
|
|
|
if (boost::filesystem::exists(settingspath))
|
|
|
|
settings.loadUser(settingspath);
|
2012-04-02 11:47:25 +00:00
|
|
|
else if (boost::filesystem::exists(localdefault))
|
|
|
|
settings.loadUser(localdefault);
|
|
|
|
else if (boost::filesystem::exists(globaldefault))
|
|
|
|
settings.loadUser(globaldefault);
|
2012-04-01 14:59:35 +00:00
|
|
|
|
2012-04-02 14:10:54 +00:00
|
|
|
mFpsLevel = settings.getInt("fps", "HUD");
|
|
|
|
|
2012-04-11 18:13:15 +00:00
|
|
|
// load nif overrides
|
|
|
|
NifOverrides::Overrides nifOverrides;
|
2014-01-05 15:52:06 +00:00
|
|
|
std::string transparencyOverrides = "/transparency-overrides.cfg";
|
|
|
|
std::string materialOverrides = "/material-overrides.cfg";
|
|
|
|
if (boost::filesystem::exists(mCfgMgr.getLocalPath().string() + transparencyOverrides))
|
|
|
|
nifOverrides.loadTransparencyOverrides(mCfgMgr.getLocalPath().string() + transparencyOverrides);
|
|
|
|
else if (boost::filesystem::exists(mCfgMgr.getGlobalPath().string() + transparencyOverrides))
|
|
|
|
nifOverrides.loadTransparencyOverrides(mCfgMgr.getGlobalPath().string() + transparencyOverrides);
|
|
|
|
if (boost::filesystem::exists(mCfgMgr.getLocalPath().string() + materialOverrides))
|
|
|
|
nifOverrides.loadMaterialOverrides(mCfgMgr.getLocalPath().string() + materialOverrides);
|
|
|
|
else if (boost::filesystem::exists(mCfgMgr.getGlobalPath().string() + materialOverrides))
|
|
|
|
nifOverrides.loadMaterialOverrides(mCfgMgr.getGlobalPath().string() + materialOverrides);
|
2013-01-12 15:57:29 +00:00
|
|
|
|
2013-01-08 17:45:01 +00:00
|
|
|
return settingspath;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OMW::Engine::prepareEngine (Settings::Manager & settings)
|
|
|
|
{
|
2013-11-25 12:00:05 +00:00
|
|
|
mEnvironment.setStateManager (
|
2014-01-05 23:02:03 +00:00
|
|
|
new MWState::StateManager (mCfgMgr.getUserDataPath() / "saves", mContentFiles.at (0)));
|
2013-11-16 09:31:46 +00:00
|
|
|
|
2012-05-22 01:36:03 +00:00
|
|
|
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
|
|
|
|
}
|
2013-01-08 17:45:01 +00:00
|
|
|
|
|
|
|
mOgre = new OEngine::Render::OgreRenderer;
|
2013-02-21 22:18:54 +00:00
|
|
|
|
2012-05-22 01:36:03 +00:00
|
|
|
mOgre->configure(
|
2012-03-02 14:15:44 +00:00
|
|
|
mCfgMgr.getLogPath().string(),
|
2012-05-22 01:36:03 +00:00
|
|
|
renderSystem,
|
2013-10-30 13:04:33 +00:00
|
|
|
Settings::Manager::getString("opengl rtt mode", "Video"));
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-07-17 12:01:47 +00:00
|
|
|
// This has to be added BEFORE MyGUI is initialized, as it needs
|
|
|
|
// to find core.xml here.
|
2012-01-20 22:59:56 +00:00
|
|
|
|
2012-09-20 11:56:37 +00:00
|
|
|
addResourcesDirectory(mCfgMgr.getCachePath ().string());
|
|
|
|
|
2011-01-04 00:34:55 +00:00
|
|
|
addResourcesDirectory(mResDir / "mygui");
|
2012-01-19 03:42:07 +00:00
|
|
|
addResourcesDirectory(mResDir / "water");
|
2012-04-11 16:53:13 +00:00
|
|
|
addResourcesDirectory(mResDir / "shadows");
|
2010-07-17 12:01:47 +00:00
|
|
|
|
2012-05-22 01:36:03 +00:00
|
|
|
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");
|
2013-07-01 01:56:33 +00:00
|
|
|
windowSettings.screen = settings.getInt("screen", "Video");
|
2012-05-22 01:36:03 +00:00
|
|
|
windowSettings.vsync = settings.getBool("vsync", "Video");
|
2013-06-12 14:15:04 +00:00
|
|
|
windowSettings.icon = "openmw.png";
|
2012-05-22 01:36:03 +00:00
|
|
|
std::string aa = settings.getString("antialiasing", "Video");
|
|
|
|
windowSettings.fsaa = (aa.substr(0, 4) == "MSAA") ? aa.substr(5, aa.size()-5) : "0";
|
2013-01-14 01:32:45 +00:00
|
|
|
|
2014-03-27 03:15:47 +00:00
|
|
|
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
|
|
|
|
settings.getBool("minimize on focus loss", "Video") ? "1" : "0");
|
|
|
|
|
2012-05-22 01:36:03 +00:00
|
|
|
mOgre->createWindow("OpenMW", windowSettings);
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2014-03-09 10:42:39 +00:00
|
|
|
Bsa::registerResources (mFileCollections, mArchives, true, mFSStrict);
|
2013-08-27 13:48:13 +00:00
|
|
|
|
|
|
|
// Create input and UI first to set up a bootstrapping environment for
|
|
|
|
// showing a loading screen and keeping the window responsive while doing so
|
|
|
|
|
2014-09-13 19:45:03 +00:00
|
|
|
std::string keybinderUser = (mCfgMgr.getUserConfigPath() / "input_v2.xml").string();
|
2013-08-27 13:48:13 +00:00
|
|
|
bool keybinderUserExists = boost::filesystem::exists(keybinderUser);
|
2013-11-29 19:06:54 +00:00
|
|
|
MWInput::InputManager* input = new MWInput::InputManager (*mOgre, *this, keybinderUser, keybinderUserExists, mGrab);
|
2013-08-27 13:48:13 +00:00
|
|
|
mEnvironment.setInputManager (input);
|
|
|
|
|
|
|
|
MWGui::WindowManager* window = new MWGui::WindowManager(
|
|
|
|
mExtensions, mFpsLevel, mOgre, mCfgMgr.getLogPath().string() + std::string("/"),
|
2014-08-11 18:37:29 +00:00
|
|
|
mCfgMgr.getCachePath ().string(), mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts);
|
2013-08-27 13:48:13 +00:00
|
|
|
mEnvironment.setWindowManager (window);
|
|
|
|
|
2014-03-27 03:15:47 +00:00
|
|
|
// Create sound system
|
|
|
|
mEnvironment.setSoundManager (new MWSound::SoundManager(mUseSound));
|
|
|
|
|
2014-03-27 18:59:33 +00:00
|
|
|
if (!mSkipMenu)
|
|
|
|
{
|
|
|
|
std::string logo = mFallbackMap["Movies_Company_Logo"];
|
|
|
|
if (!logo.empty())
|
|
|
|
window->playVideo(logo, 1);
|
|
|
|
}
|
2014-03-27 03:15:47 +00:00
|
|
|
|
2010-07-02 07:00:06 +00:00
|
|
|
// Create the world
|
2013-09-29 07:11:57 +00:00
|
|
|
mEnvironment.setWorld( new MWWorld::World (*mOgre, mFileCollections, mContentFiles,
|
2013-05-15 15:54:18 +00:00
|
|
|
mResDir, mCfgMgr.getCachePath(), mEncoder, mFallbackMap,
|
2014-05-21 07:25:45 +00:00
|
|
|
mActivationDistanceOverride, mCellName, mStartupScript));
|
2013-04-29 15:56:16 +00:00
|
|
|
MWBase::Environment::get().getWorld()->setupPlayer();
|
2013-08-27 13:48:13 +00:00
|
|
|
input->setPlayer(&mEnvironment.getWorld()->getPlayer());
|
|
|
|
|
|
|
|
window->initUI();
|
|
|
|
window->renderWorldMap();
|
2011-02-26 23:50:08 +00:00
|
|
|
|
2012-12-23 19:23:24 +00:00
|
|
|
//Load translation data
|
2013-01-12 00:18:36 +00:00
|
|
|
mTranslationDataStorage.setEncoder(mEncoder);
|
2013-09-29 07:11:57 +00:00
|
|
|
for (size_t i = 0; i < mContentFiles.size(); i++)
|
|
|
|
mTranslationDataStorage.loadTranslationData(mFileCollections, mContentFiles[i]);
|
2012-12-23 19:23:24 +00:00
|
|
|
|
2013-11-16 09:31:46 +00:00
|
|
|
Compiler::registerExtensions (mExtensions);
|
2010-07-07 16:48:06 +00:00
|
|
|
|
2010-07-26 09:15:38 +00:00
|
|
|
// Create script system
|
2012-04-23 13:27:03 +00:00
|
|
|
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full);
|
2010-07-03 10:12:13 +00:00
|
|
|
mScriptContext->setExtensions (&mExtensions);
|
2010-07-02 15:21:27 +00:00
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
mEnvironment.setScriptManager (new MWScript::ScriptManager (MWBase::Environment::get().getWorld()->getStore(),
|
2014-07-21 07:34:10 +00:00
|
|
|
mVerboseScripts, *mScriptContext, mWarningsMode,
|
|
|
|
mScriptBlacklistUse ? mScriptBlacklist : std::vector<std::string>()));
|
2010-08-01 08:25:50 +00:00
|
|
|
|
2010-07-26 09:15:38 +00:00
|
|
|
// Create game mechanics system
|
2013-11-14 13:41:10 +00:00
|
|
|
MWMechanics::MechanicsManager* mechanics = new MWMechanics::MechanicsManager;
|
|
|
|
mEnvironment.setMechanicsManager (mechanics);
|
2010-07-02 15:30:26 +00:00
|
|
|
|
2010-08-06 16:01:34 +00:00
|
|
|
// Create dialog system
|
2012-04-23 13:27:03 +00:00
|
|
|
mEnvironment.setJournal (new MWDialogue::Journal);
|
2012-12-31 00:15:47 +00:00
|
|
|
mEnvironment.setDialogueManager (new MWDialogue::DialogueManager (mExtensions, mVerboseScripts, mTranslationDataStorage));
|
2010-08-06 16:01:34 +00:00
|
|
|
|
2011-10-09 11:05:38 +00:00
|
|
|
mOgre->getRoot()->addFrameListener (this);
|
2010-07-02 15:30:26 +00:00
|
|
|
|
2010-10-06 12:52:53 +00:00
|
|
|
// scripts
|
|
|
|
if (mCompileAll)
|
|
|
|
{
|
2012-04-23 13:27:03 +00:00
|
|
|
std::pair<int, int> result = MWBase::Environment::get().getScriptManager()->compileAll();
|
2010-10-06 12:52:53 +00:00
|
|
|
|
2011-10-09 10:05:13 +00:00
|
|
|
if (result.first)
|
2010-10-06 12:52:53 +00:00
|
|
|
std::cout
|
2011-10-09 10:05:13 +00:00
|
|
|
<< "compiled " << result.second << " of " << result.first << " scripts ("
|
|
|
|
<< 100*static_cast<double> (result.second)/result.first
|
2010-10-06 12:52:53 +00:00
|
|
|
<< "%)"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2013-01-08 17:45:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialise and enter main loop.
|
|
|
|
|
|
|
|
void OMW::Engine::go()
|
|
|
|
{
|
2013-09-29 07:11:57 +00:00
|
|
|
assert (!mContentFiles.empty());
|
2013-01-08 17:45:01 +00:00
|
|
|
assert (!mOgre);
|
|
|
|
|
|
|
|
Settings::Manager settings;
|
2013-08-07 00:38:41 +00:00
|
|
|
std::string settingspath;
|
2013-01-08 17:45:01 +00:00
|
|
|
|
|
|
|
settingspath = loadSettings (settings);
|
|
|
|
|
2013-01-12 00:18:36 +00:00
|
|
|
// Create encoder
|
|
|
|
ToUTF8::Utf8Encoder encoder (mEncoding);
|
|
|
|
mEncoder = &encoder;
|
|
|
|
|
2013-01-08 17:45:01 +00:00
|
|
|
prepareEngine (settings);
|
|
|
|
|
|
|
|
// Play some good 'ol tunes
|
|
|
|
MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Explore"));
|
2010-10-06 12:52:53 +00:00
|
|
|
|
2013-11-16 10:33:20 +00:00
|
|
|
// start in main menu
|
|
|
|
if (!mSkipMenu)
|
2014-03-27 03:15:47 +00:00
|
|
|
{
|
2013-11-16 10:33:20 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
|
2014-03-27 03:15:47 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// Is there an ini setting for this filename or something?
|
|
|
|
MWBase::Environment::get().getSoundManager()->streamMusic("Special/morrowind title.mp3");
|
|
|
|
|
2014-03-27 18:51:48 +00:00
|
|
|
std::string logo = mFallbackMap["Movies_Morrowind_Logo"];
|
|
|
|
if (!logo.empty())
|
|
|
|
MWBase::Environment::get().getWindowManager()->playVideo(logo, true);
|
2014-03-27 03:15:47 +00:00
|
|
|
}
|
|
|
|
catch (...) {}
|
|
|
|
}
|
2013-11-16 11:22:28 +00:00
|
|
|
else
|
2014-05-20 16:35:17 +00:00
|
|
|
{
|
2014-09-01 09:55:12 +00:00
|
|
|
MWBase::Environment::get().getStateManager()->newGame (!mNewGame);
|
2014-05-20 16:35:17 +00:00
|
|
|
}
|
2014-03-13 12:19:32 +00:00
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
// Start the main rendering loop
|
2013-11-16 10:07:23 +00:00
|
|
|
while (!mEnvironment.get().getStateManager()->hasQuitRequest())
|
2013-10-30 12:05:28 +00:00
|
|
|
Ogre::Root::getSingleton().renderOneFrame();
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2012-04-01 16:48:37 +00:00
|
|
|
// Save user settings
|
|
|
|
settings.saveUser(settingspath);
|
|
|
|
|
2013-01-10 00:46:00 +00:00
|
|
|
std::cout << "Quitting peacefully." << std::endl;
|
2010-06-16 10:13:21 +00:00
|
|
|
}
|
2010-08-05 11:36:33 +00:00
|
|
|
|
|
|
|
void OMW::Engine::activate()
|
|
|
|
{
|
2012-05-23 10:23:35 +00:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
2012-03-18 10:09:38 +00:00
|
|
|
return;
|
|
|
|
|
2013-01-08 07:27:37 +00:00
|
|
|
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getFacedObject();
|
2010-08-05 13:40:03 +00:00
|
|
|
|
2012-10-18 20:21:39 +00:00
|
|
|
if (ptr.isEmpty())
|
2011-11-09 23:12:10 +00:00
|
|
|
return;
|
2010-08-05 13:40:03 +00:00
|
|
|
|
2014-01-24 12:22:39 +00:00
|
|
|
if (ptr.getClass().getName(ptr) == "") // objects without name presented to user can never be activated
|
|
|
|
return;
|
|
|
|
|
2014-06-12 22:01:29 +00:00
|
|
|
MWBase::Environment::get().getWorld()->activate(ptr, MWBase::Environment::get().getWorld()->getPlayerPtr());
|
2010-08-05 11:36:33 +00:00
|
|
|
}
|
2010-10-06 12:52:53 +00:00
|
|
|
|
2012-02-10 18:17:49 +00:00
|
|
|
void OMW::Engine::screenshot()
|
|
|
|
{
|
|
|
|
// Count screenshots.
|
|
|
|
int shotCount = 0;
|
|
|
|
|
2013-12-26 00:24:43 +00:00
|
|
|
const std::string& screenshotPath = mCfgMgr.getUserDataPath().string();
|
2014-09-11 02:28:14 +00:00
|
|
|
std::string format = Settings::Manager::getString("screenshot format", "General");
|
2012-02-10 18:17:49 +00:00
|
|
|
// Find the first unused filename with a do-while
|
|
|
|
std::ostringstream stream;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
// Reset the stream
|
|
|
|
stream.str("");
|
|
|
|
stream.clear();
|
|
|
|
|
2014-09-11 02:28:14 +00:00
|
|
|
stream << screenshotPath << "screenshot" << std::setw(3) << std::setfill('0') << shotCount++ << "." << format;
|
2012-02-10 18:17:49 +00:00
|
|
|
|
|
|
|
} while (boost::filesystem::exists(stream.str()));
|
|
|
|
|
2014-09-11 02:28:14 +00:00
|
|
|
mOgre->screenshot(stream.str(), format);
|
2012-02-10 18:17:49 +00:00
|
|
|
}
|
|
|
|
|
2010-10-06 12:52:53 +00:00
|
|
|
void OMW::Engine::setCompileAll (bool all)
|
|
|
|
{
|
|
|
|
mCompileAll = all;
|
|
|
|
}
|
Added new command line option: "encoding"
Added new command line option: "encoding" which allow to
change font encoding used in game messages.
Currently there are three evailable encodings:
win1250 - Central and Eastern European (languages
that use Latin script, such as Polish,
Czech, Slovak, Hungarian, Slovene, Bosnian,
Croatian, Serbian (Latin script),
Romanian and Albanian)
win1251 - languages that use the Cyrillic alphabet
such as Russian, Bulgarian, Serbian Cyrillic
and others
win1252 - Western European (Latin) - default
Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
2011-07-17 20:16:50 +00:00
|
|
|
|
2011-08-19 19:06:09 +00:00
|
|
|
void OMW::Engine::setSoundUsage(bool soundUsage)
|
|
|
|
{
|
|
|
|
mUseSound = soundUsage;
|
|
|
|
}
|
|
|
|
|
2012-01-16 15:33:21 +00:00
|
|
|
void OMW::Engine::showFPS(int level)
|
2011-08-19 19:06:09 +00:00
|
|
|
{
|
2012-01-16 15:33:21 +00:00
|
|
|
mFpsLevel = level;
|
2011-08-19 19:06:09 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 19:23:24 +00:00
|
|
|
void OMW::Engine::setEncoding(const ToUTF8::FromType& encoding)
|
Added new command line option: "encoding"
Added new command line option: "encoding" which allow to
change font encoding used in game messages.
Currently there are three evailable encodings:
win1250 - Central and Eastern European (languages
that use Latin script, such as Polish,
Czech, Slovak, Hungarian, Slovene, Bosnian,
Croatian, Serbian (Latin script),
Romanian and Albanian)
win1251 - languages that use the Cyrillic alphabet
such as Russian, Bulgarian, Serbian Cyrillic
and others
win1252 - Western European (Latin) - default
Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
2011-07-17 20:16:50 +00:00
|
|
|
{
|
|
|
|
mEncoding = encoding;
|
2011-08-19 19:06:09 +00:00
|
|
|
}
|
2012-04-02 18:47:09 +00:00
|
|
|
|
2012-04-03 00:14:39 +00:00
|
|
|
void OMW::Engine::setFallbackValues(std::map<std::string,std::string> fallbackMap)
|
2012-04-02 18:47:09 +00:00
|
|
|
{
|
2012-04-03 00:14:39 +00:00
|
|
|
mFallbackMap = fallbackMap;
|
2012-04-02 18:47:09 +00:00
|
|
|
}
|
2012-07-30 09:43:28 +00:00
|
|
|
|
|
|
|
void OMW::Engine::setScriptConsoleMode (bool enabled)
|
|
|
|
{
|
|
|
|
mScriptConsoleMode = enabled;
|
|
|
|
}
|
2012-07-30 10:37:46 +00:00
|
|
|
|
|
|
|
void OMW::Engine::setStartupScript (const std::string& path)
|
|
|
|
{
|
|
|
|
mStartupScript = path;
|
|
|
|
}
|
2013-01-09 03:52:18 +00:00
|
|
|
|
|
|
|
void OMW::Engine::setActivationDistanceOverride (int distance)
|
|
|
|
{
|
|
|
|
mActivationDistanceOverride = distance;
|
2013-08-16 11:01:52 +00:00
|
|
|
}
|
2014-02-02 13:09:59 +00:00
|
|
|
|
|
|
|
void OMW::Engine::setWarningsMode (int mode)
|
|
|
|
{
|
|
|
|
mWarningsMode = mode;
|
2014-02-28 16:23:58 +00:00
|
|
|
}
|
2014-07-21 07:34:10 +00:00
|
|
|
|
|
|
|
void OMW::Engine::setScriptBlacklist (const std::vector<std::string>& list)
|
|
|
|
{
|
|
|
|
mScriptBlacklist = list;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OMW::Engine::setScriptBlacklistUse (bool use)
|
|
|
|
{
|
|
|
|
mScriptBlacklistUse = use;
|
2014-08-11 18:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OMW::Engine::enableFontExport(bool exportFonts)
|
|
|
|
{
|
|
|
|
mExportFonts = exportFonts;
|
|
|
|
}
|