2010-06-16 12:13:21 +02:00
|
|
|
#include "engine.hpp"
|
2013-01-12 17:52:26 -04:00
|
|
|
|
2013-12-05 14:23:39 +01:00
|
|
|
#include <stdexcept>
|
2014-02-19 18:40:29 +01:00
|
|
|
#include <iomanip>
|
2010-06-16 12:13:21 +02:00
|
|
|
|
2011-10-09 13:12:44 +02:00
|
|
|
#include <OgreRoot.h>
|
2012-01-16 15:33:21 +00:00
|
|
|
#include <OgreRenderWindow.h>
|
2011-10-09 13:12:44 +02:00
|
|
|
|
|
|
|
#include <MyGUI_WidgetManager.h>
|
|
|
|
|
2013-11-16 10:31:46 +01:00
|
|
|
#include <SDL.h>
|
|
|
|
|
2013-08-07 13:16:20 -04:00
|
|
|
#include <components/compiler/extensions0.hpp>
|
2013-08-06 20:38:41 -04:00
|
|
|
|
2014-03-09 11:42:39 +01:00
|
|
|
#include <components/bsa/resources.hpp>
|
2012-01-21 01:14:35 +01:00
|
|
|
#include <components/files/configurationmanager.hpp>
|
2012-12-25 23:20:39 +04:00
|
|
|
#include <components/translation/translation.hpp>
|
2013-02-24 13:51:56 -08:00
|
|
|
#include <components/nif/niffile.hpp>
|
2012-04-11 20:13:15 +02:00
|
|
|
#include <components/nifoverrides/nifoverrides.hpp>
|
2012-01-21 01:14:35 +01:00
|
|
|
|
2013-02-24 13:52:23 -08:00
|
|
|
#include <components/nifbullet/bulletnifloader.hpp>
|
|
|
|
#include <components/nifogre/ogrenifloader.hpp>
|
2010-07-16 22:27:50 +02:00
|
|
|
|
2013-12-05 14:23:39 +01:00
|
|
|
#include <components/esm/loadcell.hpp>
|
|
|
|
|
2012-08-11 17:53:39 +02:00
|
|
|
#include "mwinput/inputmanagerimp.hpp"
|
2010-07-03 15:41:20 +02:00
|
|
|
|
2012-08-12 18:11:09 +02:00
|
|
|
#include "mwgui/windowmanagerimp.hpp"
|
2011-10-09 13:12:44 +02:00
|
|
|
|
2012-08-08 15:18:55 +02:00
|
|
|
#include "mwscript/scriptmanagerimp.hpp"
|
2010-07-03 12:12:13 +02:00
|
|
|
#include "mwscript/extensions.hpp"
|
2012-11-10 14:31:58 +01:00
|
|
|
#include "mwscript/interpretercontext.hpp"
|
2010-07-02 09:00:06 +02:00
|
|
|
|
2012-08-09 14:33:21 +02:00
|
|
|
#include "mwsound/soundmanagerimp.hpp"
|
2010-07-03 15:17:02 +02:00
|
|
|
|
2010-08-03 22:06:48 +02:00
|
|
|
#include "mwworld/class.hpp"
|
2011-01-04 15:58:22 +01:00
|
|
|
#include "mwworld/player.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "mwworld/worldimp.hpp"
|
2010-08-03 13:17:31 +02:00
|
|
|
|
|
|
|
#include "mwclass/classes.hpp"
|
2010-06-16 12:13:21 +02:00
|
|
|
|
2012-08-09 10:35:53 +02:00
|
|
|
#include "mwdialogue/dialoguemanagerimp.hpp"
|
2012-08-09 12:56:03 +02:00
|
|
|
#include "mwdialogue/journalimp.hpp"
|
2010-08-06 18:01:34 +02:00
|
|
|
|
2012-08-11 17:30:55 +02:00
|
|
|
#include "mwmechanics/mechanicsmanagerimp.hpp"
|
2010-07-26 11:15:38 +02:00
|
|
|
|
2013-11-16 10:31:46 +01:00
|
|
|
#include "mwstate/statemanagerimp.hpp"
|
2012-01-10 00:34:29 -05:00
|
|
|
|
2010-07-02 16:18:25 +02:00
|
|
|
void OMW::Engine::executeLocalScripts()
|
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
MWWorld::LocalScripts& localScripts = MWBase::Environment::get().getWorld()->getLocalScripts();
|
2011-10-06 12:29:59 +02:00
|
|
|
|
|
|
|
localScripts.startIteration();
|
|
|
|
|
|
|
|
while (!localScripts.isFinished())
|
2010-07-02 16:18:25 +02:00
|
|
|
{
|
2011-10-06 12:29:59 +02:00
|
|
|
std::pair<std::string, MWWorld::Ptr> script = localScripts.getNext();
|
2010-08-01 10:25:50 +02:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
MWScript::InterpreterContext interpreterContext (
|
2011-10-06 12:29:59 +02:00
|
|
|
&script.second.getRefData().getLocals(), script.second);
|
2012-04-23 15:27:03 +02:00
|
|
|
MWBase::Environment::get().getScriptManager()->run (script.first, interpreterContext);
|
2011-10-06 12:29:59 +02:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
if (MWBase::Environment::get().getWorld()->hasCellChanged())
|
2011-10-06 12:29:59 +02:00
|
|
|
break;
|
2010-07-02 16:18:25 +02:00
|
|
|
}
|
2010-08-05 15:46:50 +02:00
|
|
|
|
2011-10-07 09:52:42 +02:00
|
|
|
localScripts.setIgnore (MWWorld::Ptr());
|
2010-07-02 16:18:25 +02:00
|
|
|
}
|
2010-07-01 11:49:00 -07:00
|
|
|
|
2013-03-05 14:24:29 +01:00
|
|
|
bool OMW::Engine::frameStarted (const Ogre::FrameEvent& evt)
|
|
|
|
{
|
2013-08-19 20:30:22 +02:00
|
|
|
bool paused = MWBase::Environment::get().getWindowManager()->isGuiMode();
|
|
|
|
MWBase::Environment::get().getWorld()->frameStarted(evt.timeSinceLastFrame, paused);
|
2013-04-03 00:27:29 +02:00
|
|
|
MWBase::Environment::get().getWindowManager ()->frameStarted(evt.timeSinceLastFrame);
|
2013-03-05 14:24:29 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-18 16:37:09 +02:00
|
|
|
bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
|
2010-07-02 17:30:26 +02:00
|
|
|
{
|
2011-10-06 12:34:13 +02:00
|
|
|
try
|
2011-02-18 17:46:24 +03:00
|
|
|
{
|
2013-02-23 13:15:37 -08:00
|
|
|
float frametime = std::min(evt.timeSinceLastFrame, 0.2f);
|
2013-01-13 21:32:45 -04:00
|
|
|
|
2013-06-12 12:34:33 +02:00
|
|
|
mEnvironment.setFrameDuration (frametime);
|
2011-10-08 10:15:03 +02:00
|
|
|
|
2012-04-05 21:16:51 +02:00
|
|
|
// update input
|
2013-02-23 13:15:37 -08:00
|
|
|
MWBase::Environment::get().getInputManager()->update(frametime, false);
|
2012-04-05 21:16:51 +02:00
|
|
|
|
2011-10-09 09:28:36 +02:00
|
|
|
// sound
|
|
|
|
if (mUseSound)
|
2013-02-23 13:15:37 -08:00
|
|
|
MWBase::Environment::get().getSoundManager()->update(frametime);
|
2010-10-31 12:23:03 -04:00
|
|
|
|
2014-01-25 15:54:24 +01:00
|
|
|
bool paused = MWBase::Environment::get().getWindowManager()->isGuiMode();
|
|
|
|
|
2014-01-25 22:20:46 +01:00
|
|
|
// update game state
|
|
|
|
MWBase::Environment::get().getStateManager()->update (frametime);
|
|
|
|
|
2013-12-16 21:02:21 +02:00
|
|
|
if (MWBase::Environment::get().getStateManager()->getState()==
|
|
|
|
MWBase::StateManager::State_Running)
|
|
|
|
{
|
|
|
|
// global scripts
|
|
|
|
MWBase::Environment::get().getScriptManager()->getGlobalScripts().run();
|
2010-07-22 12:46:24 +02:00
|
|
|
|
2013-12-16 21:02:21 +02:00
|
|
|
bool changed = MWBase::Environment::get().getWorld()->hasCellChanged();
|
2010-07-02 17:30:26 +02:00
|
|
|
|
2013-12-16 21:02:21 +02:00
|
|
|
// local scripts
|
|
|
|
executeLocalScripts(); // This does not handle the case where a global script causes a
|
|
|
|
// cell change, followed by a cell change in a local script during
|
|
|
|
// the same frame.
|
2010-07-22 12:46:24 +02:00
|
|
|
|
2013-12-16 21:02:21 +02:00
|
|
|
if (changed) // keep change flag for another frame, if cell changed happened in local script
|
|
|
|
MWBase::Environment::get().getWorld()->markCellAsUnchanged();
|
2010-08-01 10:25:50 +02:00
|
|
|
|
2014-01-25 15:54:24 +01:00
|
|
|
if (!paused)
|
2013-12-16 21:02:21 +02:00
|
|
|
MWBase::Environment::get().getWorld()->advanceTime(
|
|
|
|
frametime*MWBase::Environment::get().getWorld()->getTimeScaleFactor()/3600);
|
|
|
|
}
|
2012-01-23 14:33:06 +01:00
|
|
|
|
2010-08-01 10:25:50 +02:00
|
|
|
|
2010-09-18 08:39:21 +02:00
|
|
|
// update actors
|
2013-02-23 13:15:37 -08:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->update(frametime,
|
2014-01-25 15:54:24 +01:00
|
|
|
paused);
|
2013-11-28 09:33:50 +01:00
|
|
|
|
2013-12-16 15:40:47 +02:00
|
|
|
if (MWBase::Environment::get().getStateManager()->getState()==
|
|
|
|
MWBase::StateManager::State_Running)
|
|
|
|
{
|
2014-01-25 15:54:24 +01:00
|
|
|
MWWorld::Ptr player = mEnvironment.getWorld()->getPlayerPtr();
|
|
|
|
if(!paused && player.getClass().getCreatureStats(player).isDead())
|
2013-12-16 15:40:47 +02:00
|
|
|
MWBase::Environment::get().getStateManager()->endGame();
|
2013-11-16 17:46:48 +01:00
|
|
|
}
|
2010-07-22 12:29:23 +02:00
|
|
|
|
2012-01-23 14:33:06 +01:00
|
|
|
// update world
|
2014-01-25 15:54:24 +01:00
|
|
|
MWBase::Environment::get().getWorld()->update(frametime, paused);
|
2012-01-23 14:33:06 +01:00
|
|
|
|
2012-04-14 17:47:44 +02:00
|
|
|
// update GUI
|
|
|
|
Ogre::RenderWindow* window = mOgre->getWindow();
|
2012-06-22 12:56:04 +02:00
|
|
|
unsigned int tri, batch;
|
|
|
|
MWBase::Environment::get().getWorld()->getTriangleBatchCount(tri, batch);
|
|
|
|
MWBase::Environment::get().getWindowManager()->wmUpdateFps(window->getLastFPS(), tri, batch);
|
2012-04-14 17:47:44 +02:00
|
|
|
|
2013-02-23 13:15:37 -08:00
|
|
|
MWBase::Environment::get().getWindowManager()->onFrame(frametime);
|
2013-08-27 15:48:13 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->update();
|
2010-09-18 08:39:21 +02:00
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
std::cerr << "Error in framelistener: " << e.what() << std::endl;
|
2010-08-03 20:40:45 +02:00
|
|
|
}
|
|
|
|
|
2010-07-02 17:30:26 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-21 01:14:35 +01:00
|
|
|
OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
|
2011-10-09 13:05:38 +02:00
|
|
|
: mOgre (0)
|
2012-01-16 15:33:21 +00:00
|
|
|
, mFpsLevel(0)
|
2010-07-07 09:55:44 +02:00
|
|
|
, mVerboseScripts (false)
|
2013-11-16 11:33:20 +01:00
|
|
|
, mSkipMenu (false)
|
2010-08-18 11:16:15 +02:00
|
|
|
, mUseSound (true)
|
2010-10-06 14:52:53 +02:00
|
|
|
, mCompileAll (false)
|
2014-02-02 14:09:59 +01:00
|
|
|
, mWarningsMode (1)
|
2010-07-07 09:55:44 +02:00
|
|
|
, mScriptContext (0)
|
2011-05-05 19:56:16 +02:00
|
|
|
, mFSStrict (false)
|
2012-07-30 11:43:28 +02:00
|
|
|
, mScriptConsoleMode (false)
|
2011-08-19 21:06:09 +02:00
|
|
|
, mCfgMgr(configurationManager)
|
2013-07-31 18:46:32 +02:00
|
|
|
, mEncoding(ToUTF8::WINDOWS_1252)
|
|
|
|
, mEncoder(NULL)
|
|
|
|
, mActivationDistanceOverride(-1)
|
2013-11-29 20:06:54 +01:00
|
|
|
, mGrab(true)
|
2013-07-31 18:46:32 +02:00
|
|
|
|
2010-08-01 10:25:50 +02:00
|
|
|
{
|
2011-10-06 12:36:16 +02:00
|
|
|
std::srand ( std::time(NULL) );
|
2010-08-03 13:17:31 +02:00
|
|
|
MWClass::registerClasses();
|
2013-01-13 21:32:45 -04: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 11:00:34 +01:00
|
|
|
SDL_SetMainReady();
|
2013-01-13 21:32:45 -04:00
|
|
|
if(SDL_Init(flags) != 0)
|
2013-06-23 16:45:23 -07:00
|
|
|
{
|
|
|
|
throw std::runtime_error("Could not initialize SDL! " + std::string(SDL_GetError()));
|
|
|
|
}
|
2013-01-13 21:32:45 -04:00
|
|
|
}
|
2010-06-27 16:44:15 -07:00
|
|
|
}
|
2010-06-16 12:13:21 +02:00
|
|
|
|
2010-07-02 13:12:05 +02:00
|
|
|
OMW::Engine::~Engine()
|
|
|
|
{
|
2012-05-04 17:20:57 +02:00
|
|
|
mEnvironment.cleanup();
|
2010-07-02 17:21:27 +02:00
|
|
|
delete mScriptContext;
|
2011-10-09 13:05:38 +02:00
|
|
|
delete mOgre;
|
2013-01-13 21:32:45 -04:00
|
|
|
SDL_Quit();
|
2010-07-02 13:12:05 +02:00
|
|
|
}
|
|
|
|
|
2010-06-16 12:58:53 +02:00
|
|
|
// add resources directory
|
|
|
|
// \note This function works recursively.
|
|
|
|
|
|
|
|
void OMW::Engine::addResourcesDirectory (const boost::filesystem::path& path)
|
|
|
|
{
|
2011-10-09 13:05:38 +02:00
|
|
|
mOgre->getRoot()->addResourceLocation (path.string(), "FileSystem",
|
2010-06-16 12:58:53 +02:00
|
|
|
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
|
2010-06-25 22:28:59 +02:00
|
|
|
}
|
|
|
|
|
2012-05-09 02:16:10 +02: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 21:06:09 +02:00
|
|
|
void OMW::Engine::enableFSStrict(bool fsStrict)
|
2011-05-05 19:56:16 +02:00
|
|
|
{
|
2011-08-19 21:06:09 +02:00
|
|
|
mFSStrict = fsStrict;
|
2011-05-05 19:56:16 +02:00
|
|
|
}
|
|
|
|
|
2010-06-16 12:13:21 +02:00
|
|
|
// Set data dir
|
|
|
|
|
2011-09-02 22:45:21 +02:00
|
|
|
void OMW::Engine::setDataDirs (const Files::PathContainer& dataDirs)
|
2010-06-16 12:13:21 +02:00
|
|
|
{
|
2012-01-29 20:27:03 +01:00
|
|
|
mDataDirs = dataDirs;
|
2011-05-05 19:56:16 +02:00
|
|
|
mFileCollections = Files::Collections (dataDirs, !mFSStrict);
|
2010-06-16 12:13:21 +02:00
|
|
|
}
|
|
|
|
|
2013-03-09 21:08:08 +01:00
|
|
|
// Add BSA archive
|
|
|
|
void OMW::Engine::addArchive (const std::string& archive) {
|
|
|
|
mArchives.push_back(archive);
|
|
|
|
}
|
|
|
|
|
2011-01-04 01:34:55 +01:00
|
|
|
// Set resource dir
|
|
|
|
void OMW::Engine::setResourceDir (const boost::filesystem::path& parResDir)
|
|
|
|
{
|
|
|
|
mResDir = boost::filesystem::system_complete(parResDir);
|
|
|
|
}
|
|
|
|
|
2010-06-16 12:13:21 +02:00
|
|
|
// Set start cell name (only interiors for now)
|
|
|
|
|
|
|
|
void OMW::Engine::setCell (const std::string& cellName)
|
|
|
|
{
|
|
|
|
mCellName = cellName;
|
|
|
|
}
|
|
|
|
|
2013-09-29 09:11:57 +02:00
|
|
|
void OMW::Engine::addContentFile(const std::string& file)
|
2010-06-16 12:13:21 +02:00
|
|
|
{
|
2014-01-27 13:27:42 +01:00
|
|
|
mContentFiles.push_back(file);
|
2010-06-16 12:13:21 +02:00
|
|
|
}
|
|
|
|
|
2011-08-19 21:06:09 +02:00
|
|
|
void OMW::Engine::setScriptsVerbosity(bool scriptsVerbosity)
|
2010-07-02 16:18:25 +02:00
|
|
|
{
|
2011-08-19 21:06:09 +02:00
|
|
|
mVerboseScripts = scriptsVerbosity;
|
2010-07-02 16:18:25 +02:00
|
|
|
}
|
2010-07-01 11:49:00 -07:00
|
|
|
|
2013-11-16 11:33:20 +01:00
|
|
|
void OMW::Engine::setSkipMenu (bool skipMenu)
|
2010-07-04 16:00:32 +02:00
|
|
|
{
|
2013-11-16 11:33:20 +01:00
|
|
|
mSkipMenu = skipMenu;
|
2010-07-04 16:00:32 +02:00
|
|
|
}
|
|
|
|
|
2013-01-08 09:45:01 -08:00
|
|
|
std::string OMW::Engine::loadSettings (Settings::Manager & settings)
|
2010-06-16 12:13:21 +02:00
|
|
|
{
|
2012-04-02 13:47:25 +02:00
|
|
|
// Create the settings manager and load default settings file
|
2012-04-01 17:14:49 +02: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 23:16:29 +02:00
|
|
|
else
|
|
|
|
throw std::runtime_error ("No default settings file found! Make sure the file \"settings-default.cfg\" was properly installed.");
|
2012-04-01 16:59:35 +02:00
|
|
|
|
2012-04-02 13:47:25 +02:00
|
|
|
// load user settings if they exist, otherwise just load the default settings as user settings
|
2013-12-26 01:24:43 +01:00
|
|
|
const std::string settingspath = mCfgMgr.getUserConfigPath().string() + "/settings.cfg";
|
2012-04-01 16:59:35 +02:00
|
|
|
if (boost::filesystem::exists(settingspath))
|
|
|
|
settings.loadUser(settingspath);
|
2012-04-02 13:47:25 +02:00
|
|
|
else if (boost::filesystem::exists(localdefault))
|
|
|
|
settings.loadUser(localdefault);
|
|
|
|
else if (boost::filesystem::exists(globaldefault))
|
|
|
|
settings.loadUser(globaldefault);
|
2012-04-01 16:59:35 +02:00
|
|
|
|
2012-04-02 16:10:54 +02:00
|
|
|
mFpsLevel = settings.getInt("fps", "HUD");
|
|
|
|
|
2012-04-11 20:13:15 +02:00
|
|
|
// load nif overrides
|
|
|
|
NifOverrides::Overrides nifOverrides;
|
2014-01-05 16:52:06 +01: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 11:57:29 -04:00
|
|
|
|
2013-01-08 09:45:01 -08:00
|
|
|
return settingspath;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OMW::Engine::prepareEngine (Settings::Manager & settings)
|
|
|
|
{
|
2013-11-25 13:00:05 +01:00
|
|
|
mEnvironment.setStateManager (
|
2014-01-06 00:02:03 +01:00
|
|
|
new MWState::StateManager (mCfgMgr.getUserDataPath() / "saves", mContentFiles.at (0)));
|
2013-11-16 10:31:46 +01:00
|
|
|
|
2013-01-05 10:58:50 -08:00
|
|
|
Nif::NIFFile::CacheLock cachelock;
|
|
|
|
|
2012-05-22 03:36:03 +02: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 09:45:01 -08:00
|
|
|
|
|
|
|
mOgre = new OEngine::Render::OgreRenderer;
|
2013-02-22 02:18:54 +04:00
|
|
|
|
2012-05-22 03:36:03 +02:00
|
|
|
mOgre->configure(
|
2012-03-02 15:15:44 +01:00
|
|
|
mCfgMgr.getLogPath().string(),
|
2012-05-22 03:36:03 +02:00
|
|
|
renderSystem,
|
2013-10-30 14:04:33 +01:00
|
|
|
Settings::Manager::getString("opengl rtt mode", "Video"));
|
2010-06-25 22:28:59 +02:00
|
|
|
|
2010-07-17 14:01:47 +02:00
|
|
|
// This has to be added BEFORE MyGUI is initialized, as it needs
|
|
|
|
// to find core.xml here.
|
2012-01-20 17:59:56 -05:00
|
|
|
|
2012-01-18 22:42:07 -05:00
|
|
|
//addResourcesDirectory(mResDir);
|
2012-03-30 17:01:55 +02:00
|
|
|
|
2012-09-20 13:56:37 +02:00
|
|
|
addResourcesDirectory(mCfgMgr.getCachePath ().string());
|
|
|
|
|
2011-01-04 01:34:55 +01:00
|
|
|
addResourcesDirectory(mResDir / "mygui");
|
2012-01-18 22:42:07 -05:00
|
|
|
addResourcesDirectory(mResDir / "water");
|
2012-04-11 18:53:13 +02:00
|
|
|
addResourcesDirectory(mResDir / "shadows");
|
2010-07-17 14:01:47 +02:00
|
|
|
|
2012-05-22 03:36:03 +02: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 03:56:33 +02:00
|
|
|
windowSettings.screen = settings.getInt("screen", "Video");
|
2012-05-22 03:36:03 +02:00
|
|
|
windowSettings.vsync = settings.getBool("vsync", "Video");
|
2013-06-12 16:15:04 +02:00
|
|
|
windowSettings.icon = "openmw.png";
|
2012-05-22 03:36:03 +02:00
|
|
|
std::string aa = settings.getString("antialiasing", "Video");
|
|
|
|
windowSettings.fsaa = (aa.substr(0, 4) == "MSAA") ? aa.substr(5, aa.size()-5) : "0";
|
2013-01-13 21:32:45 -04:00
|
|
|
|
2014-03-27 04:15:47 +01:00
|
|
|
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
|
|
|
|
settings.getBool("minimize on focus loss", "Video") ? "1" : "0");
|
|
|
|
|
2012-05-22 03:36:03 +02:00
|
|
|
mOgre->createWindow("OpenMW", windowSettings);
|
2010-06-16 12:13:21 +02:00
|
|
|
|
2014-03-09 11:42:39 +01:00
|
|
|
Bsa::registerResources (mFileCollections, mArchives, true, mFSStrict);
|
2013-08-27 15:48:13 +02: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
|
|
|
|
|
2013-12-26 01:24:43 +01:00
|
|
|
std::string keybinderUser = (mCfgMgr.getUserConfigPath() / "input.xml").string();
|
2013-08-27 15:48:13 +02:00
|
|
|
bool keybinderUserExists = boost::filesystem::exists(keybinderUser);
|
2013-11-29 20:06:54 +01:00
|
|
|
MWInput::InputManager* input = new MWInput::InputManager (*mOgre, *this, keybinderUser, keybinderUserExists, mGrab);
|
2013-08-27 15:48:13 +02:00
|
|
|
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);
|
|
|
|
|
2014-03-27 04:15:47 +01:00
|
|
|
// Create sound system
|
|
|
|
mEnvironment.setSoundManager (new MWSound::SoundManager(mUseSound));
|
|
|
|
|
2014-03-27 19:59:33 +01:00
|
|
|
if (!mSkipMenu)
|
|
|
|
{
|
|
|
|
std::string logo = mFallbackMap["Movies_Company_Logo"];
|
|
|
|
if (!logo.empty())
|
|
|
|
window->playVideo(logo, 1);
|
|
|
|
}
|
2014-03-27 04:15:47 +01:00
|
|
|
|
2010-07-02 09:00:06 +02:00
|
|
|
// Create the world
|
2013-09-29 09:11:57 +02:00
|
|
|
mEnvironment.setWorld( new MWWorld::World (*mOgre, mFileCollections, mContentFiles,
|
2013-05-15 17:54:18 +02:00
|
|
|
mResDir, mCfgMgr.getCachePath(), mEncoder, mFallbackMap,
|
2014-03-13 13:19:32 +01:00
|
|
|
mActivationDistanceOverride, mCellName));
|
2013-04-29 17:56:16 +02:00
|
|
|
MWBase::Environment::get().getWorld()->setupPlayer();
|
2013-08-27 15:48:13 +02:00
|
|
|
input->setPlayer(&mEnvironment.getWorld()->getPlayer());
|
|
|
|
|
|
|
|
window->initUI();
|
|
|
|
window->renderWorldMap();
|
2011-02-27 00:50:08 +01:00
|
|
|
|
2012-12-23 23:23:24 +04:00
|
|
|
//Load translation data
|
2013-01-12 01:18:36 +01:00
|
|
|
mTranslationDataStorage.setEncoder(mEncoder);
|
2013-09-29 09:11:57 +02:00
|
|
|
for (size_t i = 0; i < mContentFiles.size(); i++)
|
|
|
|
mTranslationDataStorage.loadTranslationData(mFileCollections, mContentFiles[i]);
|
2012-12-23 23:23:24 +04:00
|
|
|
|
2013-11-16 10:31:46 +01:00
|
|
|
Compiler::registerExtensions (mExtensions);
|
2010-07-07 18:48:06 +02:00
|
|
|
|
2010-07-26 11:15:38 +02:00
|
|
|
// Create script system
|
2012-04-23 15:27:03 +02:00
|
|
|
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full);
|
2010-07-03 12:12:13 +02:00
|
|
|
mScriptContext->setExtensions (&mExtensions);
|
2010-07-02 17:21:27 +02:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
mEnvironment.setScriptManager (new MWScript::ScriptManager (MWBase::Environment::get().getWorld()->getStore(),
|
2014-02-02 14:09:59 +01:00
|
|
|
mVerboseScripts, *mScriptContext, mWarningsMode));
|
2010-08-01 10:25:50 +02:00
|
|
|
|
2010-07-26 11:15:38 +02:00
|
|
|
// Create game mechanics system
|
2013-11-14 14:41:10 +01:00
|
|
|
MWMechanics::MechanicsManager* mechanics = new MWMechanics::MechanicsManager;
|
|
|
|
mEnvironment.setMechanicsManager (mechanics);
|
2010-07-02 17:30:26 +02:00
|
|
|
|
2010-08-06 18:01:34 +02:00
|
|
|
// Create dialog system
|
2012-04-23 15:27:03 +02:00
|
|
|
mEnvironment.setJournal (new MWDialogue::Journal);
|
2012-12-31 04:15:47 +04:00
|
|
|
mEnvironment.setDialogueManager (new MWDialogue::DialogueManager (mExtensions, mVerboseScripts, mTranslationDataStorage));
|
2010-08-06 18:01:34 +02:00
|
|
|
|
2012-08-14 20:33:29 +04:00
|
|
|
mEnvironment.getWorld()->renderPlayer();
|
2013-11-14 14:41:10 +01:00
|
|
|
mechanics->buildPlayer();
|
|
|
|
window->updatePlayer();
|
2012-08-14 20:33:29 +04:00
|
|
|
|
2011-10-09 13:05:38 +02:00
|
|
|
mOgre->getRoot()->addFrameListener (this);
|
2010-07-02 17:30:26 +02:00
|
|
|
|
2010-10-06 14:52:53 +02:00
|
|
|
// scripts
|
|
|
|
if (mCompileAll)
|
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
std::pair<int, int> result = MWBase::Environment::get().getScriptManager()->compileAll();
|
2010-10-06 14:52:53 +02:00
|
|
|
|
2011-10-09 12:05:13 +02:00
|
|
|
if (result.first)
|
2010-10-06 14:52:53 +02:00
|
|
|
std::cout
|
2011-10-09 12:05:13 +02:00
|
|
|
<< "compiled " << result.second << " of " << result.first << " scripts ("
|
|
|
|
<< 100*static_cast<double> (result.second)/result.first
|
2010-10-06 14:52:53 +02:00
|
|
|
<< "%)"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2013-01-08 09:45:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialise and enter main loop.
|
|
|
|
|
|
|
|
void OMW::Engine::go()
|
|
|
|
{
|
2013-09-29 09:11:57 +02:00
|
|
|
assert (!mContentFiles.empty());
|
2013-01-08 09:45:01 -08:00
|
|
|
assert (!mOgre);
|
|
|
|
|
|
|
|
Settings::Manager settings;
|
2013-08-06 20:38:41 -04:00
|
|
|
std::string settingspath;
|
2013-01-08 09:45:01 -08:00
|
|
|
|
|
|
|
settingspath = loadSettings (settings);
|
|
|
|
|
2013-01-12 01:18:36 +01:00
|
|
|
// Create encoder
|
|
|
|
ToUTF8::Utf8Encoder encoder (mEncoding);
|
|
|
|
mEncoder = &encoder;
|
|
|
|
|
2013-01-08 09:45:01 -08:00
|
|
|
prepareEngine (settings);
|
|
|
|
|
|
|
|
// Play some good 'ol tunes
|
|
|
|
MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Explore"));
|
2010-10-06 14:52:53 +02:00
|
|
|
|
2013-11-16 11:33:20 +01:00
|
|
|
// start in main menu
|
|
|
|
if (!mSkipMenu)
|
2014-03-27 04:15:47 +01:00
|
|
|
{
|
2013-11-16 11:33:20 +01:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
|
2014-03-27 04:15:47 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// Is there an ini setting for this filename or something?
|
|
|
|
MWBase::Environment::get().getSoundManager()->streamMusic("Special/morrowind title.mp3");
|
|
|
|
|
2014-03-27 19:51:48 +01:00
|
|
|
std::string logo = mFallbackMap["Movies_Morrowind_Logo"];
|
|
|
|
if (!logo.empty())
|
|
|
|
MWBase::Environment::get().getWindowManager()->playVideo(logo, true);
|
2014-03-27 04:15:47 +01:00
|
|
|
}
|
|
|
|
catch (...) {}
|
|
|
|
}
|
2013-11-16 12:22:28 +01:00
|
|
|
else
|
|
|
|
MWBase::Environment::get().getStateManager()->newGame (true);
|
2013-11-16 11:33:20 +01:00
|
|
|
|
2014-03-13 13:19:32 +01:00
|
|
|
if (!mStartupScript.empty())
|
|
|
|
MWBase::Environment::get().getWindowManager()->executeInConsole (mStartupScript);
|
|
|
|
|
2010-06-16 12:13:21 +02:00
|
|
|
// Start the main rendering loop
|
2013-11-16 11:07:23 +01:00
|
|
|
while (!mEnvironment.get().getStateManager()->hasQuitRequest())
|
2013-10-30 13:05:28 +01:00
|
|
|
Ogre::Root::getSingleton().renderOneFrame();
|
2010-06-16 12:13:21 +02:00
|
|
|
|
2012-04-01 18:48:37 +02:00
|
|
|
// Save user settings
|
|
|
|
settings.saveUser(settingspath);
|
|
|
|
|
2013-01-10 01:46:00 +01:00
|
|
|
std::cout << "Quitting peacefully." << std::endl;
|
2010-06-16 12:13:21 +02:00
|
|
|
}
|
2010-08-05 13:36:33 +02:00
|
|
|
|
|
|
|
void OMW::Engine::activate()
|
|
|
|
{
|
2012-05-23 12:23:35 +02:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
2012-03-18 11:09:38 +01:00
|
|
|
return;
|
|
|
|
|
2013-01-07 23:27:37 -08:00
|
|
|
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getFacedObject();
|
2010-08-05 15:40:03 +02:00
|
|
|
|
2012-10-18 22:21:39 +02:00
|
|
|
if (ptr.isEmpty())
|
2011-11-09 23:12:10 +00:00
|
|
|
return;
|
2010-08-05 15:40:03 +02:00
|
|
|
|
2014-01-24 13:22:39 +01:00
|
|
|
if (ptr.getClass().getName(ptr) == "") // objects without name presented to user can never be activated
|
|
|
|
return;
|
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr);
|
2010-08-05 15:40:03 +02:00
|
|
|
|
2011-11-09 23:12:10 +00:00
|
|
|
boost::shared_ptr<MWWorld::Action> action =
|
2014-01-08 18:39:44 +01:00
|
|
|
MWWorld::Class::get (ptr).activate (ptr, MWBase::Environment::get().getWorld()->getPlayerPtr());
|
2010-08-05 13:51:26 +02:00
|
|
|
|
2011-11-09 23:12:10 +00:00
|
|
|
interpreterContext.activate (ptr, action);
|
2010-08-05 15:40:03 +02:00
|
|
|
|
2011-11-09 23:12:10 +00:00
|
|
|
std::string script = MWWorld::Class::get (ptr).getScript (ptr);
|
2010-08-05 15:40:03 +02:00
|
|
|
|
2014-01-08 18:39:44 +01:00
|
|
|
MWBase::Environment::get().getWorld()->breakInvisibility(MWBase::Environment::get().getWorld()->getPlayerPtr());
|
2013-12-08 23:36:37 +01:00
|
|
|
|
2011-11-09 23:12:10 +00:00
|
|
|
if (!script.empty())
|
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
MWBase::Environment::get().getWorld()->getLocalScripts().setIgnore (ptr);
|
|
|
|
MWBase::Environment::get().getScriptManager()->run (script, interpreterContext);
|
2010-12-31 15:50:54 +01:00
|
|
|
}
|
2011-11-09 23:12:10 +00:00
|
|
|
|
|
|
|
if (!interpreterContext.hasActivationBeenHandled())
|
2010-08-05 15:40:03 +02:00
|
|
|
{
|
2011-11-09 23:12:10 +00:00
|
|
|
interpreterContext.executeActivation();
|
2010-08-05 15:40:03 +02:00
|
|
|
}
|
2010-08-05 13:36:33 +02:00
|
|
|
}
|
2010-10-06 14:52:53 +02:00
|
|
|
|
2012-02-10 19:17:49 +01:00
|
|
|
void OMW::Engine::screenshot()
|
|
|
|
{
|
|
|
|
// Count screenshots.
|
|
|
|
int shotCount = 0;
|
|
|
|
|
2013-12-26 01:24:43 +01:00
|
|
|
const std::string& screenshotPath = mCfgMgr.getUserDataPath().string();
|
2012-02-10 19:17:49 +01:00
|
|
|
|
|
|
|
// Find the first unused filename with a do-while
|
|
|
|
std::ostringstream stream;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
// Reset the stream
|
|
|
|
stream.str("");
|
|
|
|
stream.clear();
|
|
|
|
|
|
|
|
stream << screenshotPath << "screenshot" << std::setw(3) << std::setfill('0') << shotCount++ << ".png";
|
|
|
|
|
|
|
|
} while (boost::filesystem::exists(stream.str()));
|
|
|
|
|
|
|
|
mOgre->screenshot(stream.str());
|
|
|
|
}
|
|
|
|
|
2010-10-06 14:52:53 +02: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 22:16:50 +02:00
|
|
|
|
2011-08-19 21:06:09 +02: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 21:06:09 +02:00
|
|
|
{
|
2012-01-16 15:33:21 +00:00
|
|
|
mFpsLevel = level;
|
2011-08-19 21:06:09 +02:00
|
|
|
}
|
|
|
|
|
2012-12-23 23:23:24 +04: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 22:16:50 +02:00
|
|
|
{
|
|
|
|
mEncoding = encoding;
|
2011-08-19 21:06:09 +02:00
|
|
|
}
|
2012-04-02 20:47:09 +02:00
|
|
|
|
2012-04-03 02:14:39 +02:00
|
|
|
void OMW::Engine::setFallbackValues(std::map<std::string,std::string> fallbackMap)
|
2012-04-02 20:47:09 +02:00
|
|
|
{
|
2012-04-03 02:14:39 +02:00
|
|
|
mFallbackMap = fallbackMap;
|
2012-04-02 20:47:09 +02:00
|
|
|
}
|
2012-07-30 11:43:28 +02:00
|
|
|
|
|
|
|
void OMW::Engine::setScriptConsoleMode (bool enabled)
|
|
|
|
{
|
|
|
|
mScriptConsoleMode = enabled;
|
|
|
|
}
|
2012-07-30 12:37:46 +02:00
|
|
|
|
|
|
|
void OMW::Engine::setStartupScript (const std::string& path)
|
|
|
|
{
|
|
|
|
mStartupScript = path;
|
|
|
|
}
|
2013-01-08 19:52:18 -08:00
|
|
|
|
|
|
|
void OMW::Engine::setActivationDistanceOverride (int distance)
|
|
|
|
{
|
|
|
|
mActivationDistanceOverride = distance;
|
2013-08-16 13:01:52 +02:00
|
|
|
}
|
2014-02-02 14:09:59 +01:00
|
|
|
|
|
|
|
void OMW::Engine::setWarningsMode (int mode)
|
|
|
|
{
|
|
|
|
mWarningsMode = mode;
|
2014-02-28 17:23:58 +01:00
|
|
|
}
|