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
|
|
|
|
2011-02-01 09:11:41 +00:00
|
|
|
#include <OgreVector3.h>
|
|
|
|
|
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"
|
2011-01-04 14:58:22 +00:00
|
|
|
#include "mwworld/player.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"
|
2011-04-04 09:16:56 +00:00
|
|
|
#include "mwdialogue/journal.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>
|
|
|
|
|
2011-03-08 19:27:57 +00:00
|
|
|
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
|
|
|
#include <OSX/macUtils.h>
|
|
|
|
#endif
|
|
|
|
|
2010-09-20 11:17:02 +00:00
|
|
|
#include <MyGUI_WidgetManager.h>
|
|
|
|
#include "mwgui/class.hpp"
|
2011-01-04 00:34:55 +00:00
|
|
|
#include "path.hpp"
|
2010-09-20 11:17:02 +00:00
|
|
|
|
2011-03-18 12:22:51 +00:00
|
|
|
#include "components/nifbullet/bullet_nif_loader.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-07-01 18:49:00 +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)
|
|
|
|
{
|
2011-02-18 14:46:24 +00:00
|
|
|
if(mShowFPS)
|
|
|
|
{
|
|
|
|
mEnvironment.mWindowManager->wmSetFPS(mOgre.getFPS());
|
|
|
|
}
|
|
|
|
|
2011-01-06 08:45:14 +00:00
|
|
|
if(mUseSound && !(mEnvironment.mSoundManager->isMusicPlaying()))
|
2011-01-05 21:18:21 +00:00
|
|
|
{
|
|
|
|
// Play some good 'ol tunes
|
2011-01-06 08:45:14 +00:00
|
|
|
mEnvironment.mSoundManager->startRandomTitle();
|
2011-01-05 21:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string effect;
|
|
|
|
|
2011-01-09 19:56:21 +00:00
|
|
|
MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell();
|
2011-01-05 21:18:21 +00:00
|
|
|
//If the region has changed
|
|
|
|
if(!(current->cell->data.flags & current->cell->Interior) && timer.elapsed() >= 10){
|
2011-01-06 08:45:14 +00:00
|
|
|
timer.restart();
|
|
|
|
if (test.name != current->cell->region)
|
|
|
|
{
|
|
|
|
total = 0;
|
|
|
|
test = (ESM::Region) *(mEnvironment.mWorld->getStore().regions.find(current->cell->region));
|
|
|
|
}
|
2011-01-05 21:18:21 +00:00
|
|
|
|
2011-01-06 08:45:14 +00:00
|
|
|
if(test.soundList.size() > 0)
|
|
|
|
{
|
|
|
|
std::vector<ESM::Region::SoundRef>::iterator soundIter = test.soundList.begin();
|
|
|
|
//mEnvironment.mSoundManager
|
|
|
|
if(total == 0){
|
2011-01-05 21:18:21 +00:00
|
|
|
while (!(soundIter == test.soundList.end()))
|
|
|
|
{
|
2011-01-06 08:45:14 +00:00
|
|
|
ESM::NAME32 go = soundIter->sound;
|
2011-01-05 21:18:21 +00:00
|
|
|
int chance = (int) soundIter->chance;
|
|
|
|
//std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n";
|
|
|
|
soundIter++;
|
2011-01-06 08:45:14 +00:00
|
|
|
total += chance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
srand ( time(NULL) );
|
|
|
|
int r = rand() % total; //old random code
|
|
|
|
int pos = 0;
|
|
|
|
soundIter = test.soundList.begin();
|
|
|
|
while (!(soundIter == test.soundList.end()))
|
|
|
|
{
|
|
|
|
const ESM::NAME32 go = soundIter->sound;
|
|
|
|
int chance = (int) soundIter->chance;
|
|
|
|
//std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n";
|
|
|
|
soundIter++;
|
|
|
|
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);
|
2011-01-05 21:18:21 +00:00
|
|
|
|
2011-01-06 08:45:14 +00:00
|
|
|
break;
|
2011-01-05 21:18:21 +00:00
|
|
|
|
|
|
|
}
|
2011-01-06 08:45:14 +00:00
|
|
|
pos += chance;
|
2011-01-05 21:18:21 +00:00
|
|
|
}
|
2011-01-06 08:45:14 +00:00
|
|
|
}
|
2011-01-05 21:18:21 +00:00
|
|
|
|
2011-01-06 08:45:14 +00:00
|
|
|
//mEnvironment.mSoundManager->playSound(effect, 1.0, 1.0);
|
|
|
|
//printf("REGION: %s\n", test.name);
|
2011-01-05 21:18:21 +00:00
|
|
|
|
2011-01-06 08:45:14 +00:00
|
|
|
}
|
2011-01-05 21:18:21 +00:00
|
|
|
else if(current->cell->data.flags & current->cell->Interior)
|
|
|
|
{
|
|
|
|
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
|
2011-02-01 09:11:41 +00:00
|
|
|
std::vector<std::pair<std::string, Ogre::Vector3> > movement;
|
|
|
|
mEnvironment.mMechanicsManager->update (movement);
|
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;
|
|
|
|
}
|
2011-01-29 16:39:34 +00:00
|
|
|
|
2011-03-13 21:39:44 +00:00
|
|
|
if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game)
|
|
|
|
mEnvironment.mWorld->doPhysics (movement, mEnvironment.mFrameDuration);
|
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
|
|
|
}
|
2011-01-05 21:18:21 +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()
|
2011-04-02 11:04:49 +00:00
|
|
|
: mPhysicEngine (0)
|
|
|
|
, mShowFPS (false)
|
2011-02-18 14:46:24 +00:00
|
|
|
, mDebug (false)
|
2010-07-07 07:55:44 +00:00
|
|
|
, mVerboseScripts (false)
|
|
|
|
, mNewGame (false)
|
2010-08-18 09:16:15 +00:00
|
|
|
, mUseSound (true)
|
2010-10-06 12:52:53 +00:00
|
|
|
, mCompileAll (false)
|
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;
|
2011-04-04 09:16:56 +00:00
|
|
|
delete mEnvironment.mJournal;
|
2010-07-02 14:18:25 +00:00
|
|
|
delete mScriptManager;
|
2010-07-02 15:21:27 +00:00
|
|
|
delete mScriptContext;
|
2011-02-27 12:37:17 +00:00
|
|
|
delete mPhysicEngine;
|
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;
|
2011-03-28 15:36:05 +00:00
|
|
|
addBSA(iter->path().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)
|
|
|
|
{
|
2011-03-28 15:36:05 +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
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-01-04 00:34:55 +00:00
|
|
|
// Set resource dir
|
|
|
|
void OMW::Engine::setResourceDir (const boost::filesystem::path& parResDir)
|
|
|
|
{
|
|
|
|
mResDir = boost::filesystem::system_complete(parResDir);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2011-01-05 21:18:21 +00:00
|
|
|
test.name = "";
|
|
|
|
total = 0;
|
2010-11-01 21:06:13 +00:00
|
|
|
|
2010-12-31 14:50:54 +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
|
|
|
|
2011-01-04 19:33:22 +00:00
|
|
|
std::string cfgDir = OMW::Path::getPath(OMW::Path::GLOBAL_CFG_PATH, "openmw", "");
|
|
|
|
std::string cfgUserDir = OMW::Path::getPath(OMW::Path::USER_CFG_PATH, "openmw", "");
|
2011-01-04 00:34:55 +00:00
|
|
|
std::string plugCfg = "plugins.cfg";
|
|
|
|
std::string ogreCfg = "ogre.cfg";
|
2011-01-04 19:33:22 +00:00
|
|
|
ogreCfg.insert(0, cfgUserDir);
|
2011-01-09 12:26:08 +00:00
|
|
|
|
|
|
|
//A local plugins.cfg will be used if it exist, otherwise look in the default path
|
|
|
|
if(!isFile(plugCfg.c_str()))
|
|
|
|
{
|
|
|
|
plugCfg.insert(0, cfgDir);
|
|
|
|
}
|
2010-06-16 10:13:21 +00:00
|
|
|
|
2011-01-04 19:33:22 +00:00
|
|
|
mOgre.configure(!isFile(ogreCfg.c_str()), cfgUserDir, 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.
|
2011-01-04 00:34:55 +00:00
|
|
|
addResourcesDirectory(mResDir / "mygui");
|
2010-07-17 12:01:47 +00:00
|
|
|
|
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
|
|
|
|
2011-03-18 12:22:51 +00:00
|
|
|
// Create physics. shapeLoader is deleted by the physic engine
|
|
|
|
ManualBulletShapeLoader* shapeLoader = new ManualBulletShapeLoader();
|
|
|
|
mPhysicEngine = new OEngine::Physic::PhysicEngine(shapeLoader);
|
2011-02-26 23:50:08 +00:00
|
|
|
|
2010-07-02 07:00:06 +00:00
|
|
|
// Create the world
|
2011-02-19 16:59:40 +00:00
|
|
|
mEnvironment.mWorld = new MWWorld::World (mOgre, mPhysicEngine, mDataDir, mMaster, mResDir, mNewGame, mEnvironment);
|
2010-07-02 15:21:27 +00:00
|
|
|
|
2011-02-26 23:50:08 +00:00
|
|
|
|
2010-07-17 12:01:47 +00:00
|
|
|
// Set up the GUI system
|
2011-01-04 00:34:55 +00:00
|
|
|
mGuiManager = new OEngine::GUI::MyGUIManager(mOgre.getWindow(), mOgre.getScene(), false, cfgDir);
|
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-10-20 19:39:18 +00:00
|
|
|
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWDynamicStat>("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,
|
2011-02-18 14:46:24 +00:00
|
|
|
mExtensions, mShowFPS, 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
|
2011-04-04 09:16:56 +00:00
|
|
|
mEnvironment.mJournal = new MWDialogue::Journal (mEnvironment);
|
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;
|
2010-08-01 08:25:50 +00:00
|
|
|
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
2010-10-05 16:23:53 +00:00
|
|
|
pos.pos[2] = 0;
|
|
|
|
|
|
|
|
if (const ESM::Cell *exterior = mEnvironment.mWorld->getExterior (mCellName))
|
|
|
|
{
|
|
|
|
mEnvironment.mWorld->indexToPosition (exterior->data.gridX, exterior->data.gridY,
|
|
|
|
pos.pos[0], pos.pos[1], true);
|
|
|
|
mEnvironment.mWorld->changeToExteriorCell (pos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos.pos[0] = pos.pos[1] = 0;
|
2011-02-10 09:38:45 +00:00
|
|
|
mEnvironment.mWorld->changeToInteriorCell (mCellName, pos);
|
2010-10-05 16:23:53 +00:00
|
|
|
}
|
2010-07-27 11:09:35 +00:00
|
|
|
|
2010-06-16 10:13:21 +00:00
|
|
|
// Sets up the input system
|
2011-01-04 14:58:22 +00:00
|
|
|
MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayer(),
|
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-10-06 12:52:53 +00:00
|
|
|
// scripts
|
|
|
|
if (mCompileAll)
|
|
|
|
{
|
|
|
|
typedef ESMS::ScriptListT<ESM::Script>::MapType Container;
|
|
|
|
|
|
|
|
Container scripts = mEnvironment.mWorld->getStore().scripts.list;
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
int success = 0;
|
|
|
|
|
|
|
|
for (Container::const_iterator iter (scripts.begin()); iter!=scripts.end(); ++iter, ++count)
|
|
|
|
if (mScriptManager->compile (iter->first))
|
|
|
|
++success;
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
std::cout
|
|
|
|
<< "compiled " << success << " of " << count << " scripts ("
|
|
|
|
<< 100*static_cast<double> (success)/count
|
|
|
|
<< "%)"
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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-12-31 14:50:54 +00:00
|
|
|
// TODO: This is only a workaround. The input dispatcher should catch any exceptions thrown inside
|
|
|
|
// the input handling functions. Looks like this will require an OpenEngine modification.
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::string handle = mEnvironment.mWorld->getFacedHandle();
|
2010-08-05 11:51:26 +00:00
|
|
|
|
2010-12-31 14:50:54 +00:00
|
|
|
if (handle.empty())
|
|
|
|
return;
|
2010-08-05 11:51:26 +00:00
|
|
|
|
2010-12-31 14:50:54 +00:00
|
|
|
MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle);
|
2010-08-05 11:51:26 +00:00
|
|
|
|
2010-12-31 14:50:54 +00:00
|
|
|
if (ptr.isEmpty())
|
|
|
|
return;
|
2010-08-05 11:51:26 +00:00
|
|
|
|
2010-12-31 14:50:54 +00:00
|
|
|
MWScript::InterpreterContext interpreterContext (mEnvironment,
|
|
|
|
&ptr.getRefData().getLocals(), ptr);
|
2010-08-05 13:40:03 +00:00
|
|
|
|
2010-12-31 14:50:54 +00:00
|
|
|
boost::shared_ptr<MWWorld::Action> action =
|
2011-01-04 14:58:22 +00:00
|
|
|
MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayer().getPlayer(),
|
2010-12-31 14:50:54 +00:00
|
|
|
mEnvironment);
|
2010-08-05 11:51:26 +00:00
|
|
|
|
2010-12-31 14:50:54 +00:00
|
|
|
interpreterContext.activate (ptr, action);
|
2010-08-05 13:40:03 +00:00
|
|
|
|
2010-12-31 14:50:54 +00:00
|
|
|
std::string script = MWWorld::Class::get (ptr).getScript (ptr);
|
2010-08-05 13:40:03 +00:00
|
|
|
|
2010-12-31 14:50:54 +00:00
|
|
|
if (!script.empty())
|
|
|
|
{
|
|
|
|
mIgnoreLocalPtr = ptr;
|
|
|
|
mScriptManager->run (script, interpreterContext);
|
|
|
|
}
|
2010-08-05 13:40:03 +00:00
|
|
|
|
2010-12-31 14:50:54 +00:00
|
|
|
if (!interpreterContext.hasActivationBeenHandled())
|
|
|
|
{
|
|
|
|
interpreterContext.executeActivation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
2010-08-05 13:40:03 +00:00
|
|
|
{
|
2010-12-31 14:50:54 +00:00
|
|
|
std::cerr << "Activation failed: " << e.what() << std::endl;
|
2010-08-05 13:40:03 +00:00
|
|
|
}
|
2010-08-05 11:36:33 +00:00
|
|
|
}
|
2010-10-06 12:52:53 +00:00
|
|
|
|
|
|
|
void OMW::Engine::setCompileAll (bool all)
|
|
|
|
{
|
|
|
|
mCompileAll = all;
|
|
|
|
}
|