2010-06-16 10:13:21 +00:00
|
|
|
#include "engine.hpp"
|
2010-11-07 17:51:59 +00:00
|
|
|
#include "components/esm/loadcell.hpp"
|
2010-06-16 10:13:21 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include <iostream>
|
2010-08-03 18:40:45 +00:00
|
|
|
#include <utility>
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2010-11-12 00:47:26 +00:00
|
|
|
#include "components/esm/records.hpp"
|
2010-11-07 17:51:59 +00:00
|
|
|
#include <components/esm_store/cell_store.hpp>
|
2010-07-03 13:41:20 +00:00
|
|
|
#include <components/misc/fileops.hpp>
|
|
|
|
#include <components/bsa/bsa_archive.hpp>
|
2010-11-06 17:11:09 +00:00
|
|
|
#include <components/esm/loadregn.hpp>
|
|
|
|
#include <components/esm/esm_reader.hpp>
|
2010-07-17 12:01:47 +00:00
|
|
|
#include <openengine/gui/manager.hpp>
|
2010-07-20 18:23:37 +00:00
|
|
|
#include "mwgui/window_manager.hpp"
|
2010-07-16 20:27:50 +00:00
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
#include "mwinput/inputmanager.hpp"
|
2010-07-03 13:41:20 +00:00
|
|
|
|
2010-07-02 14:18:25 +00:00
|
|
|
#include "mwscript/scriptmanager.hpp"
|
2010-07-04 07:59:29 +00:00
|
|
|
#include "mwscript/compilercontext.hpp"
|
2010-07-02 16:08:00 +00:00
|
|
|
#include "mwscript/interpretercontext.hpp"
|
2010-07-03 10:12:13 +00:00
|
|
|
#include "mwscript/extensions.hpp"
|
2010-07-04 08:43:34 +00:00
|
|
|
#include "mwscript/globalscripts.hpp"
|
2010-07-02 07:00:06 +00:00
|
|
|
|
2010-07-03 13:17:02 +00:00
|
|
|
#include "mwsound/soundmanager.hpp"
|
|
|
|
|
2010-07-03 13:41:20 +00:00
|
|
|
#include "mwworld/world.hpp"
|
2010-07-03 15:46:55 +00:00
|
|
|
#include "mwworld/ptr.hpp"
|
2010-07-04 08:43:34 +00:00
|
|
|
#include "mwworld/environment.hpp"
|
2010-08-03 20:06:48 +00:00
|
|
|
#include "mwworld/class.hpp"
|
2010-08-03 11:17:31 +00:00
|
|
|
|
|
|
|
#include "mwclass/classes.hpp"
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2010-08-06 17:10:56 +00:00
|
|
|
#include "mwdialogue/dialoguemanager.hpp"
|
2010-08-06 16:01:34 +00:00
|
|
|
|
2010-07-26 09:15:38 +00:00
|
|
|
#include "mwmechanics/mechanicsmanager.hpp"
|
|
|
|
|
2010-07-17 17:58:15 +00:00
|
|
|
#include <OgreRoot.h>
|
|
|
|
|
2010-09-20 11:17:02 +00:00
|
|
|
#include <MyGUI_WidgetManager.h>
|
|
|
|
#include "mwgui/class.hpp"
|
|
|
|
|
2010-11-08 23:01:33 +00:00
|
|
|
|
2010-11-12 00:47:26 +00:00
|
|
|
//using namespace ESM;
|
|
|
|
|
2010-07-02 14:18:25 +00:00
|
|
|
void OMW::Engine::executeLocalScripts()
|
|
|
|
{
|
2010-07-04 08:43:34 +00:00
|
|
|
for (MWWorld::World::ScriptList::const_iterator iter (
|
|
|
|
mEnvironment.mWorld->getLocalScripts().begin());
|
|
|
|
iter!=mEnvironment.mWorld->getLocalScripts().end(); ++iter)
|
2010-07-02 14:18:25 +00:00
|
|
|
{
|
2010-08-12 16:44:16 +00:00
|
|
|
if (mIgnoreLocalPtr.isEmpty() || mIgnoreLocalPtr!=iter->second)
|
2010-08-05 13:46:50 +00:00
|
|
|
{
|
|
|
|
MWScript::InterpreterContext interpreterContext (mEnvironment,
|
|
|
|
&iter->second.getRefData().getLocals(), MWWorld::Ptr (iter->second));
|
|
|
|
mScriptManager->run (iter->first, interpreterContext);
|
2010-08-01 08:25:50 +00:00
|
|
|
|
2010-08-05 13:46:50 +00:00
|
|
|
if (mEnvironment.mWorld->hasCellChanged())
|
|
|
|
break;
|
|
|
|
}
|
2010-07-02 14:18:25 +00:00
|
|
|
}
|
2010-08-05 13:46:50 +00:00
|
|
|
|
|
|
|
mIgnoreLocalPtr = MWWorld::Ptr();
|
2010-07-02 14:18:25 +00:00
|
|
|
}
|
2010-10-31 16:23:03 +00:00
|
|
|
|
|
|
|
|
2010-07-02 15:30:26 +00:00
|
|
|
bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
|
|
|
|
{
|
2010-11-01 21:06:13 +00:00
|
|
|
if(! (mEnvironment.mSoundManager->isMusicPlaying()))
|
2010-10-31 16:23:03 +00:00
|
|
|
{
|
|
|
|
// Play some good 'ol tunes
|
2010-11-12 00:47:26 +00:00
|
|
|
mEnvironment.mSoundManager->startRandomTitle();
|
2010-10-31 16:23:03 +00:00
|
|
|
}
|
2010-11-08 23:01:33 +00:00
|
|
|
|
|
|
|
std::string effect;
|
|
|
|
|
2010-11-06 17:11:09 +00:00
|
|
|
|
2010-11-08 23:01:33 +00:00
|
|
|
|
2010-11-07 17:51:59 +00:00
|
|
|
MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayerPos().getPlayer().getCell();
|
2010-11-08 23:01:33 +00:00
|
|
|
//If the region has changed
|
|
|
|
if(!(current->cell->data.flags & current->cell->Interior) && timer.elapsed() >= 10){
|
|
|
|
timer.restart();
|
|
|
|
if (test.name != current->cell->region)
|
|
|
|
{
|
|
|
|
total = 0;
|
2010-11-12 00:47:26 +00:00
|
|
|
test = (ESM::Region) *(mEnvironment.mWorld->getStore().regions.find(current->cell->region));
|
2010-11-08 23:01:33 +00:00
|
|
|
}
|
|
|
|
|
2010-11-06 17:11:09 +00:00
|
|
|
if(test.soundList.size() > 0)
|
|
|
|
{
|
|
|
|
std::vector<ESM::Region::SoundRef>::iterator soundIter = test.soundList.begin();
|
2010-11-07 17:51:59 +00:00
|
|
|
//mEnvironment.mSoundManager
|
2010-11-08 23:01:33 +00:00
|
|
|
if(total == 0){
|
|
|
|
while (!(soundIter == test.soundList.end()))
|
|
|
|
{
|
|
|
|
ESM::NAME32 go = soundIter->sound;
|
|
|
|
int chance = (int) soundIter->chance;
|
|
|
|
//std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n";
|
|
|
|
soundIter++;
|
|
|
|
total += chance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
srand ( time(NULL) );
|
|
|
|
int r = rand() % total; //old random code
|
|
|
|
int pos = 0;
|
|
|
|
soundIter = test.soundList.begin();
|
2010-11-06 17:11:09 +00:00
|
|
|
while (!(soundIter == test.soundList.end()))
|
|
|
|
{
|
2010-11-08 23:01:33 +00:00
|
|
|
const ESM::NAME32 go = soundIter->sound;
|
|
|
|
int chance = (int) soundIter->chance;
|
|
|
|
//std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n";
|
2010-11-06 17:11:09 +00:00
|
|
|
soundIter++;
|
2010-11-08 23:01:33 +00:00
|
|
|
if( r - pos < chance)
|
|
|
|
{
|
|
|
|
effect = go.name;
|
|
|
|
//play sound
|
|
|
|
std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n";
|
|
|
|
mEnvironment.mSoundManager->playSound(effect, 20.0, 1.0);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
pos += chance;
|
2010-11-06 17:11:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-08 23:01:33 +00:00
|
|
|
//mEnvironment.mSoundManager->playSound(effect, 1.0, 1.0);
|
2010-11-06 17:11:09 +00:00
|
|
|
//printf("REGION: %s\n", test.name);
|
2010-10-31 16:23:03 +00:00
|
|
|
|
2010-11-06 17:11:09 +00:00
|
|
|
}
|
2010-11-07 17:51:59 +00:00
|
|
|
else if(current->cell->data.flags & current->cell->Interior)
|
2010-11-06 17:11:09 +00:00
|
|
|
{
|
|
|
|
test.name = "";
|
|
|
|
}
|
2010-10-31 16:23:03 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
mEnvironment.mFrameDuration = evt.timeSinceLastFrame;
|
2010-07-06 10:06:50 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
// global scripts
|
|
|
|
mEnvironment.mGlobalScripts->run (mEnvironment);
|
2010-07-02 15:30:26 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
bool changed = mEnvironment.mWorld->hasCellChanged();
|
2010-07-22 10:46:24 +00:00
|
|
|
|
2010-09-18 06:39:21 +00: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-08-01 08:25:50 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
// passing of time
|
|
|
|
if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game)
|
|
|
|
mEnvironment.mWorld->advanceTime (
|
|
|
|
mEnvironment.mFrameDuration*mEnvironment.mWorld->getTimeScaleFactor()/3600);
|
2010-07-18 16:29:16 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
if (changed) // keep change flag for another frame, if cell changed happend in local script
|
|
|
|
mEnvironment.mWorld->markCellAsUnchanged();
|
2010-08-01 08:25:50 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
// update actors
|
|
|
|
mEnvironment.mMechanicsManager->update();
|
2010-07-22 10:29:23 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
if (focusFrameCounter++ == focusUpdateFrame)
|
|
|
|
{
|
|
|
|
std::string handle = mEnvironment.mWorld->getFacedHandle();
|
2010-08-03 20:06:48 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
std::string name;
|
2010-08-03 20:06:48 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
if (!handle.empty())
|
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle);
|
2010-08-03 20:06:48 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
if (!ptr.isEmpty())
|
|
|
|
name = MWWorld::Class::get (ptr).getName (ptr);
|
|
|
|
}
|
2010-08-03 20:06:48 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
if (!name.empty())
|
|
|
|
std::cout << "Object: " << name << std::endl;
|
2010-08-03 18:40:45 +00:00
|
|
|
|
2010-09-18 06:39:21 +00:00
|
|
|
focusFrameCounter = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
std::cerr << "Error in framelistener: " << e.what() << std::endl;
|
2010-08-03 18:40:45 +00:00
|
|
|
}
|
2010-11-06 17:11:09 +00:00
|
|
|
//std::cout << "TESTING2";
|
2010-08-03 18:40:45 +00:00
|
|
|
|
2010-07-02 15:30:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-02 15:21:27 +00:00
|
|
|
OMW::Engine::Engine()
|
2010-07-07 07:55:44 +00:00
|
|
|
: mDebug (false)
|
|
|
|
, mVerboseScripts (false)
|
|
|
|
, mNewGame (false)
|
2010-08-18 09:16:15 +00:00
|
|
|
, mUseSound (true)
|
2010-07-07 07:55:44 +00:00
|
|
|
, mScriptManager (0)
|
|
|
|
, mScriptContext (0)
|
2010-08-29 15:46:06 +00:00
|
|
|
, mGuiManager (0)
|
2010-08-01 08:25:50 +00:00
|
|
|
{
|
2010-08-03 11:17:31 +00:00
|
|
|
MWClass::registerClasses();
|
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()
|
|
|
|
{
|
2010-07-17 12:01:47 +00:00
|
|
|
delete mGuiManager;
|
2010-07-04 08:43:34 +00:00
|
|
|
delete mEnvironment.mWorld;
|
|
|
|
delete mEnvironment.mSoundManager;
|
2010-07-04 14:00:32 +00:00
|
|
|
delete mEnvironment.mGlobalScripts;
|
2010-07-26 09:15:38 +00:00
|
|
|
delete mEnvironment.mMechanicsManager;
|
2010-08-06 17:16:44 +00:00
|
|
|
delete mEnvironment.mDialogueManager;
|
2010-07-02 14:18:25 +00:00
|
|
|
delete mScriptManager;
|
2010-07-02 15:21:27 +00:00
|
|
|
delete mScriptContext;
|
2010-07-02 11:12:05 +00:00
|
|
|
}
|
|
|
|
|
2010-06-16 18:15:48 +00:00
|
|
|
// Load all BSA files in data directory.
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2010-06-16 18:15:48 +00:00
|
|
|
void OMW::Engine::loadBSA()
|
|
|
|
{
|
|
|
|
boost::filesystem::directory_iterator end;
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-06-16 18:15:48 +00:00
|
|
|
for (boost::filesystem::directory_iterator iter (mDataDir); iter!=end; ++iter)
|
2010-06-16 10:13:21 +00:00
|
|
|
{
|
2010-06-16 18:15:48 +00:00
|
|
|
if (boost::filesystem::extension (iter->path())==".bsa")
|
|
|
|
{
|
|
|
|
std::cout << "Adding " << iter->path().string() << std::endl;
|
2010-06-25 20:28:59 +00:00
|
|
|
addBSA(iter->path().file_string());
|
2010-06-16 18:15:48 +00:00
|
|
|
}
|
2010-06-16 10:13:21 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-25 20:28:59 +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)
|
|
|
|
{
|
|
|
|
mOgre.getRoot()->addResourceLocation (path.file_string(), "FileSystem",
|
|
|
|
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
|
2010-06-25 20:28:59 +00:00
|
|
|
}
|
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
// Set data dir
|
|
|
|
|
|
|
|
void OMW::Engine::setDataDir (const boost::filesystem::path& dataDir)
|
|
|
|
{
|
|
|
|
mDataDir = boost::filesystem::system_complete (dataDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set start cell name (only interiors for now)
|
|
|
|
|
|
|
|
void OMW::Engine::setCell (const std::string& cellName)
|
|
|
|
{
|
|
|
|
mCellName = cellName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set master file (esm)
|
|
|
|
// - If the given name does not have an extension, ".esm" is added automatically
|
|
|
|
// - Currently OpenMW only supports one master at the same time.
|
|
|
|
|
|
|
|
void OMW::Engine::addMaster (const std::string& master)
|
|
|
|
{
|
|
|
|
assert (mMaster.empty());
|
|
|
|
mMaster = master;
|
2010-06-30 18:32:40 +00:00
|
|
|
|
|
|
|
// Append .esm if not already there
|
|
|
|
std::string::size_type sep = mMaster.find_last_of (".");
|
|
|
|
if (sep == std::string::npos)
|
|
|
|
{
|
|
|
|
mMaster += ".esm";
|
|
|
|
}
|
2010-06-16 10:13:21 +00:00
|
|
|
}
|
|
|
|
|
2010-07-02 11:12:05 +00:00
|
|
|
void OMW::Engine::enableDebugMode()
|
2010-06-27 23:44:15 +00:00
|
|
|
{
|
2010-07-02 11:12:05 +00:00
|
|
|
mDebug = true;
|
2010-06-27 23:44:15 +00:00
|
|
|
}
|
2010-08-01 08:25:50 +00:00
|
|
|
|
2010-07-02 14:18:25 +00:00
|
|
|
void OMW::Engine::enableVerboseScripts()
|
|
|
|
{
|
|
|
|
mVerboseScripts = true;
|
|
|
|
}
|
2010-07-01 18:49:00 +00:00
|
|
|
|
2010-07-04 14:00:32 +00:00
|
|
|
void OMW::Engine::setNewGame()
|
|
|
|
{
|
|
|
|
mNewGame = true;
|
|
|
|
}
|
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
// Initialise and enter main loop.
|
|
|
|
|
|
|
|
void OMW::Engine::go()
|
|
|
|
{
|
2010-07-04 08:43:34 +00:00
|
|
|
assert (!mEnvironment.mWorld);
|
2010-06-16 10:13:21 +00:00
|
|
|
assert (!mDataDir.empty());
|
|
|
|
assert (!mCellName.empty());
|
|
|
|
assert (!mMaster.empty());
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-11-06 17:11:09 +00:00
|
|
|
test.name = "";
|
2010-11-08 23:01:33 +00:00
|
|
|
total = 0;
|
2010-11-01 21:06:13 +00:00
|
|
|
|
2010-10-31 16:23:03 +00:00
|
|
|
|
|
|
|
|
2010-07-17 12:01:47 +00:00
|
|
|
std::cout << "Data directory: " << mDataDir << "\n";
|
2010-06-16 10:13:21 +00:00
|
|
|
|
|
|
|
const char* plugCfg = "plugins.cfg";
|
|
|
|
|
2010-06-28 19:44:55 +00:00
|
|
|
mOgre.configure(!isFile("ogre.cfg"), plugCfg, false);
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-06-16 10:58:53 +00:00
|
|
|
addResourcesDirectory (mDataDir / "Meshes");
|
|
|
|
addResourcesDirectory (mDataDir / "Textures");
|
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.
|
|
|
|
addResourcesDirectory("resources/mygui/");
|
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
// Create the window
|
|
|
|
mOgre.createWindow("OpenMW");
|
|
|
|
|
2010-07-02 07:00:06 +00:00
|
|
|
loadBSA();
|
2010-06-28 00:28:49 +00:00
|
|
|
|
2010-07-02 07:00:06 +00:00
|
|
|
// Create the world
|
2010-07-27 12:05:05 +00:00
|
|
|
mEnvironment.mWorld = new MWWorld::World (mOgre, mDataDir, mMaster, mNewGame, mEnvironment);
|
2010-07-02 15:21:27 +00:00
|
|
|
|
2010-07-17 12:01:47 +00:00
|
|
|
// Set up the GUI system
|
|
|
|
mGuiManager = new OEngine::GUI::MyGUIManager(mOgre.getWindow(),
|
|
|
|
mOgre.getScene());
|
2010-09-20 11:17:02 +00:00
|
|
|
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget");
|
|
|
|
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWAttribute>("Widget");
|
2010-09-20 11:36:55 +00:00
|
|
|
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpell>("Widget");
|
2010-09-21 10:34:47 +00:00
|
|
|
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpellEffect>("Widget");
|
2010-07-17 12:01:47 +00:00
|
|
|
|
|
|
|
// Create window manager - this manages all the MW-specific GUI windows
|
2010-07-20 21:21:48 +00:00
|
|
|
MWScript::registerExtensions (mExtensions);
|
2010-07-07 16:48:06 +00:00
|
|
|
|
2010-07-20 21:21:48 +00:00
|
|
|
mEnvironment.mWindowManager = new MWGui::WindowManager(mGuiManager->getGui(), mEnvironment,
|
2010-07-21 08:28:58 +00:00
|
|
|
mExtensions, mNewGame);
|
2010-07-03 13:17:02 +00:00
|
|
|
|
2010-07-26 09:15:38 +00:00
|
|
|
// Create sound system
|
2010-08-12 14:13:54 +00:00
|
|
|
mEnvironment.mSoundManager = new MWSound::SoundManager(mOgre.getRoot(),
|
2010-08-14 12:28:17 +00:00
|
|
|
mOgre.getCamera(),
|
|
|
|
mEnvironment.mWorld->getStore(),
|
2010-11-12 00:47:26 +00:00
|
|
|
(mDataDir),
|
2010-08-18 09:16:15 +00:00
|
|
|
mUseSound);
|
2010-07-03 10:12:13 +00:00
|
|
|
|
2010-07-26 09:15:38 +00:00
|
|
|
// Create script system
|
2010-07-04 10:55:55 +00:00
|
|
|
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full,
|
|
|
|
mEnvironment);
|
2010-07-03 10:12:13 +00:00
|
|
|
mScriptContext->setExtensions (&mExtensions);
|
2010-07-02 15:21:27 +00:00
|
|
|
|
2010-07-04 08:43:34 +00:00
|
|
|
mScriptManager = new MWScript::ScriptManager (mEnvironment.mWorld->getStore(), mVerboseScripts,
|
2010-08-01 08:25:50 +00:00
|
|
|
*mScriptContext);
|
|
|
|
|
2010-07-04 14:00:32 +00:00
|
|
|
mEnvironment.mGlobalScripts = new MWScript::GlobalScripts (mEnvironment.mWorld->getStore(),
|
|
|
|
*mScriptManager);
|
2010-08-01 08:25:50 +00:00
|
|
|
|
2010-07-26 09:15:38 +00:00
|
|
|
// Create game mechanics system
|
2010-09-15 10:22:06 +00:00
|
|
|
mEnvironment.mMechanicsManager = new MWMechanics::MechanicsManager (mEnvironment);
|
2010-07-02 15:30:26 +00:00
|
|
|
|
2010-08-06 16:01:34 +00:00
|
|
|
// Create dialog system
|
2010-08-06 17:16:44 +00:00
|
|
|
mEnvironment.mDialogueManager = new MWDialogue::DialogueManager (mEnvironment);
|
2010-08-06 16:01:34 +00:00
|
|
|
|
2010-07-27 11:09:35 +00:00
|
|
|
// load cell
|
|
|
|
ESM::Position pos;
|
|
|
|
pos.pos[0] = pos.pos[1] = pos.pos[2] = 0;
|
2010-08-01 08:25:50 +00:00
|
|
|
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
2010-07-27 11:09:35 +00:00
|
|
|
mEnvironment.mWorld->changeCell (mCellName, pos);
|
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
// Sets up the input system
|
2010-07-17 12:01:47 +00:00
|
|
|
MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayerPos(),
|
2010-08-05 11:36:33 +00:00
|
|
|
*mEnvironment.mWindowManager, mDebug, *this);
|
2010-09-15 12:48:19 +00:00
|
|
|
mEnvironment.mInputManager = &input;
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2010-08-03 18:40:45 +00:00
|
|
|
focusFrameCounter = 0;
|
2010-08-03 20:06:48 +00:00
|
|
|
|
2010-07-17 12:01:47 +00:00
|
|
|
std::cout << "\nPress Q/ESC or close window to exit.\n";
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2010-07-02 15:30:26 +00:00
|
|
|
mOgre.getRoot()->addFrameListener (this);
|
|
|
|
|
2010-08-12 15:58:29 +00:00
|
|
|
// Play some good 'ol tunes
|
2010-11-12 00:47:26 +00:00
|
|
|
mEnvironment.mSoundManager->startRandomTitle();
|
2010-08-12 15:58:29 +00:00
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
// Start the main rendering loop
|
|
|
|
mOgre.start();
|
|
|
|
|
2010-07-17 12:01:47 +00:00
|
|
|
std::cout << "Quitting peacefully.\n";
|
2010-06-16 10:13:21 +00:00
|
|
|
}
|
2010-08-05 11:36:33 +00:00
|
|
|
|
|
|
|
void OMW::Engine::activate()
|
|
|
|
{
|
2010-08-05 11:51:26 +00:00
|
|
|
std::string handle = mEnvironment.mWorld->getFacedHandle();
|
|
|
|
|
|
|
|
if (handle.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle);
|
|
|
|
|
|
|
|
if (ptr.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2010-08-05 13:40:03 +00:00
|
|
|
MWScript::InterpreterContext interpreterContext (mEnvironment,
|
|
|
|
&ptr.getRefData().getLocals(), ptr);
|
|
|
|
|
2010-08-05 11:51:26 +00:00
|
|
|
boost::shared_ptr<MWWorld::Action> action =
|
|
|
|
MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayerPos().getPlayer(),
|
|
|
|
mEnvironment);
|
|
|
|
|
2010-08-05 13:40:03 +00:00
|
|
|
interpreterContext.activate (ptr, action);
|
|
|
|
|
|
|
|
std::string script = MWWorld::Class::get (ptr).getScript (ptr);
|
|
|
|
|
|
|
|
if (!script.empty())
|
2010-08-05 13:46:50 +00:00
|
|
|
{
|
|
|
|
mIgnoreLocalPtr = ptr;
|
2010-08-05 13:40:03 +00:00
|
|
|
mScriptManager->run (script, interpreterContext);
|
2010-08-05 13:46:50 +00:00
|
|
|
}
|
2010-08-05 13:40:03 +00:00
|
|
|
|
|
|
|
if (!interpreterContext.hasActivationBeenHandled())
|
|
|
|
{
|
|
|
|
interpreterContext.executeActivation();
|
|
|
|
}
|
2010-08-05 11:36:33 +00:00
|
|
|
}
|