From 10778d8c3e78169594c0b3474c63d708628d6570 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 6 Oct 2011 12:29:59 +0200 Subject: [PATCH 01/11] Issue #19: factored out local script handling into a separate class This also fixes a bug related to self-destructing references (introduced during the cell handling improvements) --- apps/openmw/CMakeLists.txt | 2 + apps/openmw/engine.cpp | 29 +++++----- apps/openmw/engine.hpp | 2 - apps/openmw/mwworld/localscripts.cpp | 80 ++++++++++++++++++++++++++++ apps/openmw/mwworld/localscripts.hpp | 47 ++++++++++++++++ apps/openmw/mwworld/scene.cpp | 2 +- apps/openmw/mwworld/world.cpp | 29 ++-------- apps/openmw/mwworld/world.hpp | 10 ++-- 8 files changed, 152 insertions(+), 49 deletions(-) create mode 100644 apps/openmw/mwworld/localscripts.cpp create mode 100644 apps/openmw/mwworld/localscripts.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 21f3e18a2a..54abb948a4 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -149,6 +149,7 @@ set(GAMEWORLD mwworld/containerutil.cpp mwworld/player.cpp mwworld/cells.cpp + mwworld/localscripts.cpp ) set(GAMEWORLD_HEADER mwworld/refdata.hpp @@ -170,6 +171,7 @@ set(GAMEWORLD_HEADER mwworld/player.hpp mwworld/cellfunctors.hpp mwworld/cells.hpp + mwworld/localscripts.hpp ) source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index e9ceea2f34..7e69e40f99 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -54,22 +54,23 @@ void OMW::Engine::executeLocalScripts() { - for (MWWorld::World::ScriptList::const_iterator iter ( - mEnvironment.mWorld->getLocalScripts().begin()); - iter!=mEnvironment.mWorld->getLocalScripts().end(); ++iter) - { - if (mIgnoreLocalPtr.isEmpty() || mIgnoreLocalPtr!=iter->second) - { - MWScript::InterpreterContext interpreterContext (mEnvironment, - &iter->second.getRefData().getLocals(), MWWorld::Ptr (iter->second)); - mScriptManager->run (iter->first, interpreterContext); + MWWorld::LocalScripts& localScripts = mEnvironment.mWorld->getLocalScripts(); - if (mEnvironment.mWorld->hasCellChanged()) - break; - } + localScripts.startIteration(); + + while (!localScripts.isFinished()) + { + std::pair script = localScripts.getNext(); + + MWScript::InterpreterContext interpreterContext (mEnvironment, + &script.second.getRefData().getLocals(), script.second); + mScriptManager->run (script.first, interpreterContext); + + if (mEnvironment.mWorld->hasCellChanged()) + break; } - mIgnoreLocalPtr = MWWorld::Ptr(); + mEnvironment.mWorld->getLocalScripts().setIgnore (MWWorld::Ptr()); } @@ -488,7 +489,7 @@ void OMW::Engine::activate() if (!script.empty()) { - mIgnoreLocalPtr = ptr; + mEnvironment.mWorld->getLocalScripts().setIgnore (ptr); mScriptManager->run (script, interpreterContext); } diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 3df0d0b3af..96b7cf52e1 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -81,8 +81,6 @@ namespace OMW int focusFrameCounter; static const int focusUpdateFrame = 10; - MWWorld::Ptr mIgnoreLocalPtr; - Files::Collections mFileCollections; bool mFSStrict; diff --git a/apps/openmw/mwworld/localscripts.cpp b/apps/openmw/mwworld/localscripts.cpp new file mode 100644 index 0000000000..3fa1103380 --- /dev/null +++ b/apps/openmw/mwworld/localscripts.cpp @@ -0,0 +1,80 @@ + +#include "localscripts.hpp" + +void MWWorld::LocalScripts::setIgnore (const Ptr& ptr) +{ + mIgnore = ptr; +} + +void MWWorld::LocalScripts::startIteration() +{ + mIter = mScripts.begin(); +} + +bool MWWorld::LocalScripts::isFinished() const +{ + if (mIter==mScripts.end()) + return true; + + if (!mIgnore.isEmpty() && mIter->second==mIgnore) + { + std::list >::iterator iter = mIter; + return ++iter==mScripts.end(); + } + + return false; +} + +std::pair MWWorld::LocalScripts::getNext() +{ + assert (!isFinished()); + + std::list >::iterator iter = mIter++; + + if (mIgnore.isEmpty() || iter->second!=mIgnore) + return *iter; + + return getNext(); +} + +void MWWorld::LocalScripts::add (const std::string& scriptName, const Ptr& ptr) +{ + mScripts.push_back (std::make_pair (scriptName, ptr)); +} + +void MWWorld::LocalScripts::clear() +{ + mScripts.clear(); +} + +void MWWorld::LocalScripts::clearCell (Ptr::CellStore *cell) +{ + std::list >::iterator iter = mScripts.begin(); + + while (iter!=mScripts.end()) + { + if (iter->second.getCell()==cell) + { + if (iter==mIter) + ++mIter; + + mScripts.erase (iter++); + } + else + ++iter; + } +} + +void MWWorld::LocalScripts::remove (const Ptr& ptr) +{ + for (std::list >::iterator iter = mScripts.begin(); + iter!=mScripts.end(); ++iter) + if (iter->second==ptr) + { + if (iter==mIter) + ++mIter; + + mScripts.erase (iter); + break; + } +} diff --git a/apps/openmw/mwworld/localscripts.hpp b/apps/openmw/mwworld/localscripts.hpp new file mode 100644 index 0000000000..bc5a7c1f6d --- /dev/null +++ b/apps/openmw/mwworld/localscripts.hpp @@ -0,0 +1,47 @@ +#ifndef GAME_MWWORLD_LOCALSCRIPTS_H +#define GAME_MWWORLD_LOCALSCRIPTS_H + +#include +#include + +#include "ptr.hpp" + +namespace MWWorld +{ + /// \brief List of active local scripts + class LocalScripts + { + std::list > mScripts; + std::list >::iterator mIter; + MWWorld::Ptr mIgnore; + + public: + + void setIgnore (const Ptr& ptr); + ///< Mark a single reference for ignoring during iteration over local scripts (will revoke + /// previous ignores). + + void startIteration(); + ///< Set the iterator to the begin of the script list. + + bool isFinished() const; + ///< Is iteration finished? + + std::pair getNext(); + ///< Get next local script (must not be called if isFinished()) + + void add (const std::string& scriptName, const Ptr& ptr); + ///< Add script to collection of active local scripts. + + void clear(); + ///< Clear active local scripts collection. + + void clearCell (Ptr::CellStore *cell); + ///< Remove all scripts belonging to \a cell. + + void remove (const Ptr& ptr); + ///< Remove script for given reference (ignored if reference does not have a scirpt listed). + }; +} + +#endif diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 11bdad35f6..9cc432ee64 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -57,7 +57,7 @@ namespace MWWorld mPhysics->removeObject (*iter); } - mWorld->removeScripts (iter->first); + mWorld->getLocalScripts().clearCell (iter->first); mEnvironment.mMechanicsManager->dropActors (iter->first); mEnvironment.mSoundManager->stopSound (iter->first); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index f2e846ef44..62f477bfbb 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -27,7 +27,7 @@ namespace { template void listCellScripts (const ESMS::ESMStore& store, - ESMS::CellRefList& cellRefList, MWWorld::World::ScriptList& scriptList, + ESMS::CellRefList& cellRefList, MWWorld::LocalScripts& localScripts, MWWorld::Ptr::CellStore *cell) { for (typename ESMS::CellRefList::List::iterator iter ( @@ -40,8 +40,7 @@ namespace { iter->mData.setLocals (*script); - scriptList.push_back ( - std::make_pair (iter->base->script, MWWorld::Ptr (&*iter, cell))); + localScripts.add (iter->base->script, MWWorld::Ptr (&*iter, cell)); } } } @@ -185,20 +184,6 @@ namespace MWWorld throw std::runtime_error ("month out of range"); } - void World::removeScripts (Ptr::CellStore *cell) - { - ScriptList::iterator iter = mLocalScripts.begin(); - - while (iter!=mLocalScripts.end()) - { - if (iter->second.getCell()==cell) - mLocalScripts.erase (iter++); - else - ++iter; - } - } - - void World::adjustSky() { if (mSky) @@ -306,7 +291,7 @@ namespace MWWorld return mEsm; } - const World::ScriptList& World::getLocalScripts() const + LocalScripts& World::getLocalScripts() { return mLocalScripts; } @@ -575,13 +560,7 @@ namespace MWWorld mPhysics->removeObject (ptr.getRefData().getHandle()); - for (ScriptList::iterator iter = mLocalScripts.begin(); iter!=mLocalScripts.end(); - ++iter) - if (ptr==iter->second) - { - mLocalScripts.erase (iter); - break; - } + mLocalScripts.remove (ptr); } render->deleteObject (ptr.getRefData().getHandle()); diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 89c6057fa8..ea9f5a56fa 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -17,6 +17,7 @@ #include "scene.hpp" #include "physicssystem.hpp" #include "cells.hpp" +#include "localscripts.hpp" #include @@ -55,9 +56,7 @@ namespace MWWorld class World { - public: - typedef std::list > ScriptList; enum RenderMode { @@ -71,7 +70,7 @@ namespace MWWorld MWWorld::Player *mPlayer; ESM::ESMReader mEsm; ESMS::ESMStore mStore; - ScriptList mLocalScripts; + LocalScripts mLocalScripts; MWWorld::Globals *mGlobalVariables; MWWorld::PhysicsSystem *mPhysics; bool mSky; @@ -108,8 +107,6 @@ namespace MWWorld Ptr::CellStore *getInterior (const std::string& name); - void removeScripts (Ptr::CellStore *cell); - void insertInteriorScripts (ESMS::CellStore& cell); void adjustSky(); @@ -120,8 +117,7 @@ namespace MWWorld ESM::ESMReader& getEsmReader(); - const ScriptList& getLocalScripts() const; - ///< Names and local variable state of all local scripts in active cells. + LocalScripts& getLocalScripts(); bool hasCellChanged() const; ///< Has the player moved to a different cell, since the last frame? From 3bef04cb1d39e2e84d88c91dcb5196dc5dd8f718 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 6 Oct 2011 12:34:13 +0200 Subject: [PATCH 02/11] Issue #19: fixed exception handling in engine's frame listener --- apps/openmw/engine.cpp | 119 ++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 61 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 7e69e40f99..52f7753dbf 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -73,84 +73,82 @@ void OMW::Engine::executeLocalScripts() mEnvironment.mWorld->getLocalScripts().setIgnore (MWWorld::Ptr()); } - bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) { - if(mShowFPS) + try { - mEnvironment.mWindowManager->wmSetFPS(mOgre.getFPS()); - } - - if(mUseSound && !(mEnvironment.mSoundManager->isMusicPlaying())) - { - // Play some good 'ol tunes - mEnvironment.mSoundManager->startRandomTitle(); - } - - std::string effect; - - MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell(); - - - //If the region has changed - if(!(current->cell->data.flags & current->cell->Interior) && timer.elapsed() >= 10){ - timer.restart(); - if (test.name != current->cell->region) + if(mShowFPS) { - total = 0; - test = (ESM::Region) *(mEnvironment.mWorld->getStore().regions.find(current->cell->region)); + mEnvironment.mWindowManager->wmSetFPS(mOgre.getFPS()); } - if(test.soundList.size() > 0) + if(mUseSound && !(mEnvironment.mSoundManager->isMusicPlaying())) { - std::vector::iterator soundIter = test.soundList.begin(); - //mEnvironment.mSoundManager - if(total == 0){ + // Play some good 'ol tunes + mEnvironment.mSoundManager->startRandomTitle(); + } + + std::string effect; + + MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell(); + + //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; + test = (ESM::Region) *(mEnvironment.mWorld->getStore().regions.find(current->cell->region)); + } + + if(test.soundList.size() > 0) + { + std::vector::iterator soundIter = test.soundList.begin(); + //mEnvironment.mSoundManager + 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(); while (!(soundIter == test.soundList.end())) { - ESM::NAME32 go = soundIter->sound; + const ESM::NAME32 go = soundIter->sound; int chance = (int) soundIter->chance; //std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n"; soundIter++; - total += chance; + 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; } } - 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); + //mEnvironment.mSoundManager->playSound(effect, 1.0, 1.0); + //printf("REGION: %s\n", test.name); - break; - - } - pos += chance; - } + } + else if(current->cell->data.flags & current->cell->Interior) + { + test.name = ""; } - //mEnvironment.mSoundManager->playSound(effect, 1.0, 1.0); - //printf("REGION: %s\n", test.name); - - } - else if(current->cell->data.flags & current->cell->Interior) - { - test.name = ""; - } - - try - { mEnvironment.mFrameDuration = evt.timeSinceLastFrame; // @@ -205,7 +203,6 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) { std::cerr << "Error in framelistener: " << e.what() << std::endl; } - //std::cout << "TESTING2"; return true; } From 896b7da23db259d8437143e0966bcc44717fece4 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 6 Oct 2011 12:36:16 +0200 Subject: [PATCH 03/11] Issue #19: fixed RNG in engine's frame listener --- apps/openmw/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 52f7753dbf..a5c0adbf15 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -116,7 +116,6 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) } } - srand ( time(NULL) ); int r = rand() % total; //old random code int pos = 0; soundIter = test.soundList.begin(); @@ -221,6 +220,7 @@ OMW::Engine::Engine(Cfg::ConfigurationManager& configurationManager) , mFSStrict (false) , mCfgMgr(configurationManager) { + std::srand ( std::time(NULL) ); MWClass::registerClasses(); } From 8bebae17aa87aff7518e9c779f0f74bd7d53394b Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 7 Oct 2011 09:52:42 +0200 Subject: [PATCH 04/11] Issue #19: More local script related cleanup --- apps/openmw/engine.cpp | 2 +- apps/openmw/mwworld/localscripts.cpp | 48 +++++++++++++++++++++++++++- apps/openmw/mwworld/localscripts.hpp | 11 +++++++ apps/openmw/mwworld/scene.cpp | 2 +- apps/openmw/mwworld/world.cpp | 24 +------------- apps/openmw/mwworld/world.hpp | 2 -- 6 files changed, 61 insertions(+), 28 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index a5c0adbf15..fcadace158 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -70,7 +70,7 @@ void OMW::Engine::executeLocalScripts() break; } - mEnvironment.mWorld->getLocalScripts().setIgnore (MWWorld::Ptr()); + localScripts.setIgnore (MWWorld::Ptr()); } bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) diff --git a/apps/openmw/mwworld/localscripts.cpp b/apps/openmw/mwworld/localscripts.cpp index 3fa1103380..2d90d90e01 100644 --- a/apps/openmw/mwworld/localscripts.cpp +++ b/apps/openmw/mwworld/localscripts.cpp @@ -1,6 +1,26 @@ #include "localscripts.hpp" +namespace +{ + template + void listCellScripts (MWWorld::LocalScripts& localScripts, + ESMS::CellRefList& cellRefList, MWWorld::Ptr::CellStore *cell) + { + for (typename ESMS::CellRefList::List::iterator iter ( + cellRefList.list.begin()); + iter!=cellRefList.list.end(); ++iter) + { + if (!iter->base->script.empty() && iter->mData.getCount()) + { + localScripts.add (iter->base->script, MWWorld::Ptr (&*iter, cell)); + } + } + } +} + +MWWorld::LocalScripts::LocalScripts (const ESMS::ESMStore& store) : mStore (store) {} + void MWWorld::LocalScripts::setIgnore (const Ptr& ptr) { mIgnore = ptr; @@ -39,7 +59,33 @@ std::pair MWWorld::LocalScripts::getNext() void MWWorld::LocalScripts::add (const std::string& scriptName, const Ptr& ptr) { - mScripts.push_back (std::make_pair (scriptName, ptr)); + if (const ESM::Script *script = mStore.scripts.find (scriptName)) + { + ptr.getRefData().setLocals (*script); + + mScripts.push_back (std::make_pair (scriptName, ptr)); + } +} + +void MWWorld::LocalScripts::addCell (Ptr::CellStore *cell) +{ + listCellScripts (*this, cell->activators, cell); + listCellScripts (*this, cell->potions, cell); + listCellScripts (*this, cell->appas, cell); + listCellScripts (*this, cell->armors, cell); + listCellScripts (*this, cell->books, cell); + listCellScripts (*this, cell->clothes, cell); + listCellScripts (*this, cell->containers, cell); + listCellScripts (*this, cell->creatures, cell); + listCellScripts (*this, cell->doors, cell); + listCellScripts (*this, cell->ingreds, cell); + listCellScripts (*this, cell->lights, cell); + listCellScripts (*this, cell->lockpicks, cell); + listCellScripts (*this, cell->miscItems, cell); + listCellScripts (*this, cell->npcs, cell); + listCellScripts (*this, cell->probes, cell); + listCellScripts (*this, cell->repairs, cell); + listCellScripts (*this, cell->weapons, cell); } void MWWorld::LocalScripts::clear() diff --git a/apps/openmw/mwworld/localscripts.hpp b/apps/openmw/mwworld/localscripts.hpp index bc5a7c1f6d..1ea2cf4d5a 100644 --- a/apps/openmw/mwworld/localscripts.hpp +++ b/apps/openmw/mwworld/localscripts.hpp @@ -6,6 +6,11 @@ #include "ptr.hpp" +namespace ESMS +{ + struct ESMStore; +} + namespace MWWorld { /// \brief List of active local scripts @@ -14,9 +19,12 @@ namespace MWWorld std::list > mScripts; std::list >::iterator mIter; MWWorld::Ptr mIgnore; + const ESMS::ESMStore& mStore; public: + LocalScripts (const ESMS::ESMStore& store); + void setIgnore (const Ptr& ptr); ///< Mark a single reference for ignoring during iteration over local scripts (will revoke /// previous ignores). @@ -33,6 +41,9 @@ namespace MWWorld void add (const std::string& scriptName, const Ptr& ptr); ///< Add script to collection of active local scripts. + void addCell (Ptr::CellStore *cell); + ///< Add all local scripts in a cell. + void clear(); ///< Clear active local scripts collection. diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 9cc432ee64..da9bff6b2e 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -68,7 +68,7 @@ namespace MWWorld void Scene::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render) { // register local scripts - mWorld->insertInteriorScripts (*cell); + mWorld->getLocalScripts().addCell (cell); // This connects the cell data with the rendering scene. std::pair result = diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 62f477bfbb..78827f150a 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -66,28 +66,6 @@ namespace namespace MWWorld { - - void World::insertInteriorScripts (ESMS::CellStore& cell) - { - listCellScripts (mStore, cell.activators, mLocalScripts, &cell); - listCellScripts (mStore, cell.potions, mLocalScripts, &cell); - listCellScripts (mStore, cell.appas, mLocalScripts, &cell); - listCellScripts (mStore, cell.armors, mLocalScripts, &cell); - listCellScripts (mStore, cell.books, mLocalScripts, &cell); - listCellScripts (mStore, cell.clothes, mLocalScripts, &cell); - listCellScripts (mStore, cell.containers, mLocalScripts, &cell); - listCellScripts (mStore, cell.creatures, mLocalScripts, &cell); - listCellScripts (mStore, cell.doors, mLocalScripts, &cell); - listCellScripts (mStore, cell.ingreds, mLocalScripts, &cell); - listCellScripts (mStore, cell.lights, mLocalScripts, &cell); - listCellScripts (mStore, cell.lockpicks, mLocalScripts, &cell); - listCellScripts (mStore, cell.miscItems, mLocalScripts, &cell); - listCellScripts (mStore, cell.npcs, mLocalScripts, &cell); - listCellScripts (mStore, cell.probes, mLocalScripts, &cell); - listCellScripts (mStore, cell.repairs, mLocalScripts, &cell); - listCellScripts (mStore, cell.weapons, mLocalScripts, &cell); - } - Ptr World::getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell) { if (ESMS::LiveCellRef *ref = @@ -198,7 +176,7 @@ namespace MWWorld const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding) - : mScene (renderer,physEng), mPlayer (0), mGlobalVariables (0), + : mScene (renderer,physEng), mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this) { mPhysEngine = physEng; diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index ea9f5a56fa..978f14c8ea 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -107,8 +107,6 @@ namespace MWWorld Ptr::CellStore *getInterior (const std::string& name); - void insertInteriorScripts (ESMS::CellStore& cell); - void adjustSky(); MWWorld::Player& getPlayer(); From fbcb5fe6814b298ab3215eff6b852d21edfbbc0d Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 8 Oct 2011 10:15:03 +0200 Subject: [PATCH 05/11] Issue #19: Some more framelistener cleanup --- apps/openmw/engine.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index fcadace158..5e83a20056 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -77,6 +77,8 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) { try { + mEnvironment.mFrameDuration = evt.timeSinceLastFrame; + if(mShowFPS) { mEnvironment.mWindowManager->wmSetFPS(mOgre.getFPS()); @@ -138,19 +140,15 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) pos += chance; } } - - //mEnvironment.mSoundManager->playSound(effect, 1.0, 1.0); - //printf("REGION: %s\n", test.name); - } else if(current->cell->data.flags & current->cell->Interior) { test.name = ""; } - mEnvironment.mFrameDuration = evt.timeSinceLastFrame; - // + + // update GUI mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration); // global scripts @@ -175,28 +173,27 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) std::vector > movement; mEnvironment.mMechanicsManager->update (movement); + if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game) + mEnvironment.mWorld->doPhysics (movement, mEnvironment.mFrameDuration); + if (focusFrameCounter++ == focusUpdateFrame) { std::string handle = mEnvironment.mWorld->getFacedHandle(); - std::string name; - if (!handle.empty()) { MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); if (!ptr.isEmpty()) - name = MWWorld::Class::get (ptr).getName (ptr); + { + std::string name = MWWorld::Class::get (ptr).getName (ptr); + if (!name.empty()) + std::cout << "Object: " << name << std::endl; + } } - if (!name.empty()) - std::cout << "Object: " << name << std::endl; - focusFrameCounter = 0; } - - if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game) - mEnvironment.mWorld->doPhysics (movement, mEnvironment.mFrameDuration); } catch (const std::exception& e) { From 8bf4abf53b8975d307e4cf77b01289e1a497c67f Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 8 Oct 2011 10:31:23 +0200 Subject: [PATCH 06/11] Issue #19: Focus Reporting Improvements - moved focus reporting code out of the framelistener - made focus reporting optional (new --report-focus switch) - report based on tiem passed instead of number of frames passed - only report if focus has changed --- apps/openmw/engine.cpp | 60 ++++++++++++++++++++++++++++-------------- apps/openmw/engine.hpp | 14 ++++++---- apps/openmw/main.cpp | 4 +++ 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 5e83a20056..474d8d78c3 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -73,6 +73,36 @@ void OMW::Engine::executeLocalScripts() localScripts.setIgnore (MWWorld::Ptr()); } +void OMW::Engine::updateFocusReport (float duration) +{ + if ((mFocusTDiff += duration)>0.25) + { + mFocusTDiff = 0; + + std::string name; + + std::string handle = mEnvironment.mWorld->getFacedHandle(); + + if (!handle.empty()) + { + MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); + + if (!ptr.isEmpty()) + name = MWWorld::Class::get (ptr).getName (ptr); + } + + if (name!=mFocusName) + { + mFocusName = name; + + if (mFocusName.empty()) + std::cout << "Unfocus" << std::endl; + else + std::cout << "Focus: " << name << std::endl; + } + } +} + bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) { try @@ -176,24 +206,9 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game) mEnvironment.mWorld->doPhysics (movement, mEnvironment.mFrameDuration); - if (focusFrameCounter++ == focusUpdateFrame) - { - std::string handle = mEnvironment.mWorld->getFacedHandle(); - - if (!handle.empty()) - { - MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); - - if (!ptr.isEmpty()) - { - std::string name = MWWorld::Class::get (ptr).getName (ptr); - if (!name.empty()) - std::cout << "Object: " << name << std::endl; - } - } - - focusFrameCounter = 0; - } + // report focus object (for debugging) + if (mReportFocus) + updateFocusReport (mEnvironment.mFrameDuration); } catch (const std::exception& e) { @@ -211,6 +226,8 @@ OMW::Engine::Engine(Cfg::ConfigurationManager& configurationManager) , mNewGame (false) , mUseSound (true) , mCompileAll (false) + , mReportFocus (false) + , mFocusTDiff (0) , mScriptManager (0) , mScriptContext (0) , mGuiManager (0) @@ -320,6 +337,11 @@ void OMW::Engine::setNewGame(bool newGame) mNewGame = newGame; } +void OMW::Engine::setReportFocus (bool report) +{ + mReportFocus = report; +} + // Initialise and enter main loop. void OMW::Engine::go() @@ -416,8 +438,6 @@ void OMW::Engine::go() *mEnvironment.mWindowManager, mDebug, *this); mEnvironment.mInputManager = &input; - focusFrameCounter = 0; - std::cout << "\nPress Q/ESC or close window to exit.\n"; mOgre.getRoot()->addFrameListener (this); diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 96b7cf52e1..8bf2dbbcf8 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -68,6 +68,10 @@ namespace OMW bool mNewGame; bool mUseSound; bool mCompileAll; + bool mReportFocus; + float mFocusTDiff; + std::string mFocusName; + int total; MWWorld::Environment mEnvironment; @@ -78,9 +82,6 @@ namespace OMW ESM::Region test; boost::timer timer; - int focusFrameCounter; - static const int focusUpdateFrame = 10; - Files::Collections mFileCollections; bool mFSStrict; @@ -98,9 +99,9 @@ namespace OMW void executeLocalScripts(); - virtual bool frameRenderingQueued (const Ogre::FrameEvent& evt); + void updateFocusReport (float duration); - /// Process pending commands + virtual bool frameRenderingQueued (const Ogre::FrameEvent& evt); public: Engine(Cfg::ConfigurationManager& configurationManager); @@ -142,6 +143,9 @@ namespace OMW /// Start as a new game. void setNewGame(bool newGame); + /// Write name of focussed object to cout + void setReportFocus (bool report); + /// Initialise and enter main loop. void go(); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index aa8b13b80d..933d1c48aa 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -102,6 +102,9 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio "\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n" "\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n" "\n\twin1252 - Western European (Latin) alphabet, used by default") + + ("report-focus", boost::program_options::value()->implicit_value(true) + ->default_value(false), "write name of focussed object to cout") ; bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv) @@ -202,6 +205,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio engine.setSoundUsage(!variables["nosound"].as()); engine.setScriptsVerbosity(variables["script-verbose"].as()); engine.setCompileAll(variables["script-all"].as()); + engine.setReportFocus(variables["report-focus"].as()); return true; } From 38c0f36d449de5b613c741b192012fc2d5f67560 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 9 Oct 2011 09:28:36 +0200 Subject: [PATCH 07/11] Issue #19: Finished cleaning out the Engine framelistener --- apps/openmw/engine.cpp | 80 ++++----------------------- apps/openmw/engine.hpp | 5 -- apps/openmw/mwsound/soundmanager.cpp | 81 ++++++++++++++++++++++++++-- apps/openmw/mwsound/soundmanager.hpp | 22 ++++++-- 4 files changed, 104 insertions(+), 84 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 474d8d78c3..614658691f 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -109,76 +109,19 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) { mEnvironment.mFrameDuration = evt.timeSinceLastFrame; - if(mShowFPS) + // sound + if (mUseSound) { - mEnvironment.mWindowManager->wmSetFPS(mOgre.getFPS()); + if (!mEnvironment.mSoundManager->isMusicPlaying()) + mEnvironment.mSoundManager->startRandomTitle(); + + mEnvironment.mSoundManager->update (evt.timeSinceLastFrame); } - if(mUseSound && !(mEnvironment.mSoundManager->isMusicPlaying())) - { - // Play some good 'ol tunes - mEnvironment.mSoundManager->startRandomTitle(); - } - - std::string effect; - - MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell(); - - //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; - test = (ESM::Region) *(mEnvironment.mWorld->getStore().regions.find(current->cell->region)); - } - - if(test.soundList.size() > 0) - { - std::vector::iterator soundIter = test.soundList.begin(); - //mEnvironment.mSoundManager - 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; - } - } - - 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); - - break; - - } - pos += chance; - } - } - } - else if(current->cell->data.flags & current->cell->Interior) - { - test.name = ""; - } - - - // update GUI + if(mShowFPS) + mEnvironment.mWindowManager->wmSetFPS(mOgre.getFPS()); + mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration); // global scripts @@ -350,9 +293,6 @@ void OMW::Engine::go() assert (!mCellName.empty()); assert (!mMaster.empty()); - test.name = ""; - total = 0; - mOgre.configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()), mCfgMgr.getOgreConfigPath().string(), mCfgMgr.getLogPath().string() + std::string("/"), @@ -396,7 +336,7 @@ void OMW::Engine::go() mOgre.getCamera(), mEnvironment.mWorld->getStore(), (mDataDir), - mUseSound, mFSStrict); + mUseSound, mFSStrict, mEnvironment); // Create script system mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full, diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 8bf2dbbcf8..30172c3049 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -14,7 +14,6 @@ #include "mwworld/environment.hpp" #include "mwworld/ptr.hpp" -#include #include namespace Compiler @@ -72,15 +71,11 @@ namespace OMW float mFocusTDiff; std::string mFocusName; - int total; - MWWorld::Environment mEnvironment; MWScript::ScriptManager *mScriptManager; Compiler::Extensions mExtensions; Compiler::Context *mScriptContext; OEngine::GUI::MyGUIManager *mGuiManager; - ESM::Region test; - boost::timer timer; Files::Collections mFileCollections; bool mFSStrict; diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 970118a13b..7390e4c5ca 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -1,18 +1,23 @@ #include "soundmanager.hpp" #include +#include +#include + using namespace std; +#include + #include #include #include #include #include -#include -#include -#include +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" +#include "../mwworld/player.hpp" /* Set up the sound manager to use Audiere, FFMPEG or MPG123/libsndfile for input. The OPENMW_USE_x macros are set in @@ -378,12 +383,18 @@ namespace MWSound SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera, const ESMS::ESMStore &store, boost::filesystem::path dataDir, - bool useSound, bool fsstrict) - : mData(NULL), fsStrict (fsstrict) + bool useSound, bool fsstrict, MWWorld::Environment& environment) + : mData(NULL), fsStrict (fsstrict), mEnvironment (environment) { MP3Lookup(dataDir / "Music/Explore/"); if(useSound) mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), (dataDir / "Music").string(), fsstrict); + + + test.name = ""; + total = 0; + + } SoundManager::~SoundManager() @@ -533,4 +544,64 @@ namespace MWSound if(!mData) return; mData->updatePositions(ptr); } + + void SoundManager::update (float duration) + { + std::string effect; + + MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell(); + + //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; + test = (ESM::Region) *(mEnvironment.mWorld->getStore().regions.find(current->cell->region)); + } + + if(test.soundList.size() > 0) + { + std::vector::iterator soundIter = test.soundList.begin(); + //mEnvironment.mSoundManager + 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; + } + } + + 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); + + break; + + } + pos += chance; + } + } + } + else if(current->cell->data.flags & current->cell->Interior) + { + test.name = ""; + } + + } } diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index ab9559176e..7dff16c761 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -8,6 +8,9 @@ #include "../mwworld/ptr.hpp" #include + +#include + namespace Ogre { class Root; @@ -19,6 +22,11 @@ namespace ESMS struct ESMStore; } +namespace MWWorld +{ + struct Environment; +} + namespace MWSound { //SoundPtr *music; @@ -31,6 +39,11 @@ namespace MWSound SoundImpl *mData; std::vector files; bool fsStrict; + MWWorld::Environment& mEnvironment; + + int total; + ESM::Region test; + boost::timer timer; void streamMusicFull (const std::string& filename); ///< Play a soundifle @@ -38,8 +51,9 @@ namespace MWSound public: - SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store, - boost::filesystem::path dataDir, bool useSound, bool fsstrict); + SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store, + boost::filesystem::path dataDir, bool useSound, bool fsstrict, + MWWorld::Environment& environment); ~SoundManager(); void streamMusic(const std::string& filename); @@ -60,8 +74,6 @@ namespace MWSound bool sayDone (MWWorld::Ptr reference) const; ///< Is actor not speaking? - - void playSound (const std::string& soundId, float volume, float pitch); ///< Play a sound, independently of 3D-position @@ -81,6 +93,8 @@ namespace MWSound void updateObject(MWWorld::Ptr reference); ///< Update the position of all sounds connected to the given object. + + void update (float duration); }; } From 39af941d6fcbce69c1f85207259451f8dd4a57ca Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 9 Oct 2011 12:05:13 +0200 Subject: [PATCH 08/11] Issue #19: Moved code from Engine to WindowManager and ScriptManager --- apps/openmw/engine.cpp | 26 +++++--------------------- apps/openmw/mwgui/window_manager.cpp | 8 +++++++- apps/openmw/mwscript/scriptmanager.cpp | 16 ++++++++++++++++ apps/openmw/mwscript/scriptmanager.hpp | 4 ++++ 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 614658691f..c09e4133a8 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -319,12 +319,6 @@ void OMW::Engine::go() mGuiManager = new OEngine::GUI::MyGUIManager(mOgre.getWindow(), mOgre.getScene(), false, mCfgMgr.getLogPath().string() + std::string("/")); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - // Create window manager - this manages all the MW-specific GUI windows MWScript::registerExtensions (mExtensions); @@ -383,29 +377,19 @@ void OMW::Engine::go() mOgre.getRoot()->addFrameListener (this); // Play some good 'ol tunes - mEnvironment.mSoundManager->startRandomTitle(); + mEnvironment.mSoundManager->startRandomTitle(); // scripts if (mCompileAll) { - typedef ESMS::ScriptListT::MapType Container; + std::pair result = mScriptManager->compileAll(); - 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) + if (result.first) std::cout - << "compiled " << success << " of " << count << " scripts (" - << 100*static_cast (success)/count + << "compiled " << result.second << " of " << result.first << " scripts (" + << 100*static_cast (result.second)/result.first << "%)" << std::endl; - } // Start the main rendering loop diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 84e45859fb..095d347e7c 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -77,6 +77,12 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment playerSkillValues.insert(std::make_pair(ESM::Skill::skillIds[i], MWMechanics::Stat())); } + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + // Set up visibility updateVisible(); } @@ -329,7 +335,7 @@ void WindowManager::updateVisible() dialogueWindow->open(); return; } - + if(mode == GM_InterMessageBox) { if(!mMessageBoxManager->isInteractiveMessageBox()) { diff --git a/apps/openmw/mwscript/scriptmanager.cpp b/apps/openmw/mwscript/scriptmanager.cpp index 07fa934547..5fcfcc6050 100644 --- a/apps/openmw/mwscript/scriptmanager.cpp +++ b/apps/openmw/mwscript/scriptmanager.cpp @@ -116,4 +116,20 @@ namespace MWScript iter->second.clear(); // don't execute again. } } + + std::pair ScriptManager::compileAll() + { + typedef ESMS::ScriptListT::MapType Container; + + const Container& scripts = mStore.scripts.list; + + int count = 0; + int success = 0; + + for (Container::const_iterator iter (scripts.begin()); iter!=scripts.end(); ++iter, ++count) + if (compile (iter->first)) + ++success; + + return std::make_pair (count, success); + } } diff --git a/apps/openmw/mwscript/scriptmanager.hpp b/apps/openmw/mwscript/scriptmanager.hpp index eab9bdcc08..74511f456e 100644 --- a/apps/openmw/mwscript/scriptmanager.hpp +++ b/apps/openmw/mwscript/scriptmanager.hpp @@ -52,6 +52,10 @@ namespace MWScript bool compile (const std::string& name); ///< Compile script with the given namen /// \return Success? + + std::pair compileAll(); + ///< Compile all scripts + /// \return count, success }; }; From bc8db3612ab6d4ef6047b15c1b4cf82d14958705 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 9 Oct 2011 13:05:38 +0200 Subject: [PATCH 09/11] Issue #19: Create OGRE renderer in go function instead of Engine's constructor This avoids setting up a renderer each time openmw is called with the --help switch. --- apps/openmw/engine.cpp | 31 +++++++++++++++++++------------ apps/openmw/engine.hpp | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index c09e4133a8..cabb1113b0 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -120,7 +120,7 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) // update GUI if(mShowFPS) - mEnvironment.mWindowManager->wmSetFPS(mOgre.getFPS()); + mEnvironment.mWindowManager->wmSetFPS(mOgre->getFPS()); mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration); @@ -162,7 +162,8 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) } OMW::Engine::Engine(Cfg::ConfigurationManager& configurationManager) - : mPhysicEngine (0) + : mOgre (0) + , mPhysicEngine (0) , mShowFPS (false) , mDebug (false) , mVerboseScripts (false) @@ -193,6 +194,7 @@ OMW::Engine::~Engine() delete mScriptManager; delete mScriptContext; delete mPhysicEngine; + delete mOgre; } // Load all BSA files in data directory. @@ -216,7 +218,7 @@ void OMW::Engine::loadBSA() void OMW::Engine::addResourcesDirectory (const boost::filesystem::path& path) { - mOgre.getRoot()->addResourceLocation (path.string(), "FileSystem", + mOgre->getRoot()->addResourceLocation (path.string(), "FileSystem", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true); } @@ -292,8 +294,11 @@ void OMW::Engine::go() assert (!mEnvironment.mWorld); assert (!mCellName.empty()); assert (!mMaster.empty()); + assert (!mOgre); - mOgre.configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()), + mOgre = new OEngine::Render::OgreRenderer; + + mOgre->configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()), mCfgMgr.getOgreConfigPath().string(), mCfgMgr.getLogPath().string() + std::string("/"), mCfgMgr.getPluginsConfigPath().string(), false); @@ -303,20 +308,22 @@ void OMW::Engine::go() addResourcesDirectory(mResDir / "mygui"); // Create the window - mOgre.createWindow("OpenMW"); + mOgre->createWindow("OpenMW"); loadBSA(); + /// \todo move this into the physics manager // Create physics. shapeLoader is deleted by the physic engine NifBullet::ManualBulletShapeLoader* shapeLoader = new NifBullet::ManualBulletShapeLoader(); mPhysicEngine = new OEngine::Physic::PhysicEngine(shapeLoader); // Create the world - mEnvironment.mWorld = new MWWorld::World (mOgre, mPhysicEngine, mFileCollections, mMaster, + mEnvironment.mWorld = new MWWorld::World (*mOgre, mPhysicEngine, mFileCollections, mMaster, mResDir, mNewGame, mEnvironment, mEncoding); + /// \todo move this into the GUI manager (a.k.a WindowManager) // Set up the GUI system - mGuiManager = new OEngine::GUI::MyGUIManager(mOgre.getWindow(), mOgre.getScene(), false, + mGuiManager = new OEngine::GUI::MyGUIManager(mOgre->getWindow(), mOgre->getScene(), false, mCfgMgr.getLogPath().string() + std::string("/")); // Create window manager - this manages all the MW-specific GUI windows @@ -326,8 +333,8 @@ void OMW::Engine::go() mExtensions, mShowFPS, mNewGame); // Create sound system - mEnvironment.mSoundManager = new MWSound::SoundManager(mOgre.getRoot(), - mOgre.getCamera(), + mEnvironment.mSoundManager = new MWSound::SoundManager(mOgre->getRoot(), + mOgre->getCamera(), mEnvironment.mWorld->getStore(), (mDataDir), mUseSound, mFSStrict, mEnvironment); @@ -368,13 +375,13 @@ void OMW::Engine::go() } // Sets up the input system - MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayer(), + MWInput::MWInputManager input(*mOgre, mEnvironment.mWorld->getPlayer(), *mEnvironment.mWindowManager, mDebug, *this); mEnvironment.mInputManager = &input; std::cout << "\nPress Q/ESC or close window to exit.\n"; - mOgre.getRoot()->addFrameListener (this); + mOgre->getRoot()->addFrameListener (this); // Play some good 'ol tunes mEnvironment.mSoundManager->startRandomTitle(); @@ -393,7 +400,7 @@ void OMW::Engine::go() } // Start the main rendering loop - mOgre.start(); + mOgre->start(); std::cout << "Quitting peacefully.\n"; } diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 30172c3049..b162e25e92 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -57,7 +57,7 @@ namespace OMW std::string mEncoding; boost::filesystem::path mDataDir; boost::filesystem::path mResDir; - OEngine::Render::OgreRenderer mOgre; + OEngine::Render::OgreRenderer *mOgre; OEngine::Physic::PhysicEngine* mPhysicEngine; std::string mCellName; std::string mMaster; From abeb3a22d4db959e2f4667847a5538eb91e21d82 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 9 Oct 2011 13:12:44 +0200 Subject: [PATCH 10/11] Issue #19: Cleaned up Engine includes --- apps/openmw/engine.cpp | 27 ++++++++++----------------- apps/openmw/engine.hpp | 9 +++++++-- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index cabb1113b0..4e58e8a4ca 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -6,22 +6,24 @@ #include #include -#include -#include +#include -#include "components/esm/records.hpp" +#include + +#include +#include + +#include #include -#include #include -#include #include #include - -#include -#include "mwgui/window_manager.hpp" +#include #include "mwinput/inputmanager.hpp" +#include "mwgui/window_manager.hpp" + #include "mwscript/scriptmanager.hpp" #include "mwscript/compilercontext.hpp" #include "mwscript/interpretercontext.hpp" @@ -43,15 +45,6 @@ #include "mwmechanics/mechanicsmanager.hpp" -#include - -#include -#include "mwgui/class.hpp" - -#include "components/nifbullet/bullet_nif_loader.hpp" - -//using namespace ESM; - void OMW::Engine::executeLocalScripts() { MWWorld::LocalScripts& localScripts = mEnvironment.mWorld->getLocalScripts(); diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index b162e25e92..443f790a47 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -7,14 +7,14 @@ #include -#include #include + #include #include +#include #include "mwworld/environment.hpp" #include "mwworld/ptr.hpp" -#include namespace Compiler { @@ -47,6 +47,11 @@ namespace OEngine { class MyGUIManager; } + + namespace Render + { + class OgreRenderer; + } } namespace OMW From a3a1b829299e0b38399c35cce5e17ee10bac97e5 Mon Sep 17 00:00:00 2001 From: Brother Brick Date: Wed, 12 Oct 2011 13:58:59 +0200 Subject: [PATCH 11/11] Updated deb dependancies against Ubuntu 11.10 which is more or less in parity with Debian Sid. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47c7d6b49c..daf17ba3db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -494,7 +494,7 @@ if(DPKG_PROGRAM) SET(CPACK_DEBIAN_PACKAGE_NAME "openmw") SET(CPACK_DEBIAN_PACKAGE_VERSION "${VERSION_STRING}") SET(CPACK_PACKAGE_EXECUTABLES "openmw;OpenMW esmtool;Esmtool omwlauncher;OMWLauncher") - SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libogremain-1.7.3 (>= 1.7.3), libbullet0 (>= 2.77), libboost-filesystem1.42.0 (>= 1.42.0), libboost-program-options1.42.0 (>= 1.42.0), libboost-system1.42.0 (>= 1.42.0), libboost-thread1.42.0 (>= 1.42.0), libc6 (>= 2.11.2), libfreetype6 (>= 2.2.1), libgcc1 (>= 1:4.1.1), libmpg123-0 (>= 1.12.1), libois-1.2.0 (>= 1.2.0), libopenal1 (>= 1:1.12.854), libsndfile1 (>= 1.0.23), libstdc++6 (>= 4.4.5), libuuid1 (>= 2.17.2), libqtgui4 (>= 4.7.0)") + SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libogre-1.7.3 (>= 1.7.3), libbullet0 (>= 2.77), libboost-filesystem1.46.1 (>= 1.46.1), libboost-program-options1.46.1 (>= 1.46.1), libboost-system1.46.1 (>= 1.46.1), libboost-thread1.46.1 (>= 1.46.1), libc6 (>= 2.11.2), libfreetype6 (>= 2.2.1), libgcc1 (>= 1:4.1.1), libmpg123-0 (>= 1.12.1), libois-1.3.0 (>= 1.3.0), libopenal1 (>= 1:1.12.854), libsndfile1 (>= 1.0.23), libstdc++6 (>= 4.4.5), libuuid1 (>= 2.17.2), libqtgui4 (>= 4.7.0)") SET(CPACK_DEBIAN_PACKAGE_SECTION "Games")