mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-23 12:09:42 +00:00
Issue #19: Finished cleaning out the Engine framelistener
This commit is contained in:
parent
8bf4abf53b
commit
38c0f36d44
4 changed files with 104 additions and 84 deletions
|
@ -109,76 +109,19 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
|
||||||
{
|
{
|
||||||
mEnvironment.mFrameDuration = evt.timeSinceLastFrame;
|
mEnvironment.mFrameDuration = evt.timeSinceLastFrame;
|
||||||
|
|
||||||
if(mShowFPS)
|
// sound
|
||||||
|
if (mUseSound)
|
||||||
{
|
{
|
||||||
mEnvironment.mWindowManager->wmSetFPS(mOgre.getFPS());
|
if (!mEnvironment.mSoundManager->isMusicPlaying())
|
||||||
}
|
|
||||||
|
|
||||||
if(mUseSound && !(mEnvironment.mSoundManager->isMusicPlaying()))
|
|
||||||
{
|
|
||||||
// Play some good 'ol tunes
|
|
||||||
mEnvironment.mSoundManager->startRandomTitle();
|
mEnvironment.mSoundManager->startRandomTitle();
|
||||||
}
|
|
||||||
|
|
||||||
std::string effect;
|
mEnvironment.mSoundManager->update (evt.timeSinceLastFrame);
|
||||||
|
|
||||||
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<ESM::Region::SoundRef>::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
|
// update GUI
|
||||||
|
if(mShowFPS)
|
||||||
|
mEnvironment.mWindowManager->wmSetFPS(mOgre.getFPS());
|
||||||
|
|
||||||
mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration);
|
mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration);
|
||||||
|
|
||||||
// global scripts
|
// global scripts
|
||||||
|
@ -350,9 +293,6 @@ void OMW::Engine::go()
|
||||||
assert (!mCellName.empty());
|
assert (!mCellName.empty());
|
||||||
assert (!mMaster.empty());
|
assert (!mMaster.empty());
|
||||||
|
|
||||||
test.name = "";
|
|
||||||
total = 0;
|
|
||||||
|
|
||||||
mOgre.configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()),
|
mOgre.configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()),
|
||||||
mCfgMgr.getOgreConfigPath().string(),
|
mCfgMgr.getOgreConfigPath().string(),
|
||||||
mCfgMgr.getLogPath().string() + std::string("/"),
|
mCfgMgr.getLogPath().string() + std::string("/"),
|
||||||
|
@ -396,7 +336,7 @@ void OMW::Engine::go()
|
||||||
mOgre.getCamera(),
|
mOgre.getCamera(),
|
||||||
mEnvironment.mWorld->getStore(),
|
mEnvironment.mWorld->getStore(),
|
||||||
(mDataDir),
|
(mDataDir),
|
||||||
mUseSound, mFSStrict);
|
mUseSound, mFSStrict, mEnvironment);
|
||||||
|
|
||||||
// Create script system
|
// Create script system
|
||||||
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full,
|
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full,
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
#include "mwworld/environment.hpp"
|
#include "mwworld/environment.hpp"
|
||||||
#include "mwworld/ptr.hpp"
|
#include "mwworld/ptr.hpp"
|
||||||
#include <boost/timer.hpp>
|
|
||||||
#include <components/cfg/configurationmanager.hpp>
|
#include <components/cfg/configurationmanager.hpp>
|
||||||
|
|
||||||
namespace Compiler
|
namespace Compiler
|
||||||
|
@ -72,15 +71,11 @@ namespace OMW
|
||||||
float mFocusTDiff;
|
float mFocusTDiff;
|
||||||
std::string mFocusName;
|
std::string mFocusName;
|
||||||
|
|
||||||
int total;
|
|
||||||
|
|
||||||
MWWorld::Environment mEnvironment;
|
MWWorld::Environment mEnvironment;
|
||||||
MWScript::ScriptManager *mScriptManager;
|
MWScript::ScriptManager *mScriptManager;
|
||||||
Compiler::Extensions mExtensions;
|
Compiler::Extensions mExtensions;
|
||||||
Compiler::Context *mScriptContext;
|
Compiler::Context *mScriptContext;
|
||||||
OEngine::GUI::MyGUIManager *mGuiManager;
|
OEngine::GUI::MyGUIManager *mGuiManager;
|
||||||
ESM::Region test;
|
|
||||||
boost::timer timer;
|
|
||||||
|
|
||||||
Files::Collections mFileCollections;
|
Files::Collections mFileCollections;
|
||||||
bool mFSStrict;
|
bool mFSStrict;
|
||||||
|
|
|
@ -1,18 +1,23 @@
|
||||||
#include "soundmanager.hpp"
|
#include "soundmanager.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
#include <OgreRoot.h>
|
||||||
|
|
||||||
#include <openengine/sound/sndmanager.hpp>
|
#include <openengine/sound/sndmanager.hpp>
|
||||||
#include <mangle/sound/clients/ogre_listener_mover.hpp>
|
#include <mangle/sound/clients/ogre_listener_mover.hpp>
|
||||||
#include <mangle/sound/clients/ogre_output_updater.hpp>
|
#include <mangle/sound/clients/ogre_output_updater.hpp>
|
||||||
|
|
||||||
#include <components/file_finder/file_finder.hpp>
|
#include <components/file_finder/file_finder.hpp>
|
||||||
#include <components/esm_store/store.hpp>
|
#include <components/esm_store/store.hpp>
|
||||||
#include <algorithm>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include <OgreRoot.h>
|
#include "../mwworld/environment.hpp"
|
||||||
|
#include "../mwworld/world.hpp"
|
||||||
|
#include "../mwworld/player.hpp"
|
||||||
|
|
||||||
/* Set up the sound manager to use Audiere, FFMPEG or
|
/* Set up the sound manager to use Audiere, FFMPEG or
|
||||||
MPG123/libsndfile for input. The OPENMW_USE_x macros are set in
|
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,
|
SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera,
|
||||||
const ESMS::ESMStore &store,
|
const ESMS::ESMStore &store,
|
||||||
boost::filesystem::path dataDir,
|
boost::filesystem::path dataDir,
|
||||||
bool useSound, bool fsstrict)
|
bool useSound, bool fsstrict, MWWorld::Environment& environment)
|
||||||
: mData(NULL), fsStrict (fsstrict)
|
: mData(NULL), fsStrict (fsstrict), mEnvironment (environment)
|
||||||
{
|
{
|
||||||
MP3Lookup(dataDir / "Music/Explore/");
|
MP3Lookup(dataDir / "Music/Explore/");
|
||||||
if(useSound)
|
if(useSound)
|
||||||
mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), (dataDir / "Music").string(), fsstrict);
|
mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), (dataDir / "Music").string(), fsstrict);
|
||||||
|
|
||||||
|
|
||||||
|
test.name = "";
|
||||||
|
total = 0;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundManager::~SoundManager()
|
SoundManager::~SoundManager()
|
||||||
|
@ -533,4 +544,64 @@ namespace MWSound
|
||||||
if(!mData) return;
|
if(!mData) return;
|
||||||
mData->updatePositions(ptr);
|
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<ESM::Region::SoundRef>::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 = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
#include <openengine/sound/sndmanager.hpp>
|
#include <openengine/sound/sndmanager.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
#include <boost/timer.hpp>
|
||||||
|
|
||||||
namespace Ogre
|
namespace Ogre
|
||||||
{
|
{
|
||||||
class Root;
|
class Root;
|
||||||
|
@ -19,6 +22,11 @@ namespace ESMS
|
||||||
struct ESMStore;
|
struct ESMStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace MWWorld
|
||||||
|
{
|
||||||
|
struct Environment;
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWSound
|
namespace MWSound
|
||||||
{
|
{
|
||||||
//SoundPtr *music;
|
//SoundPtr *music;
|
||||||
|
@ -31,6 +39,11 @@ namespace MWSound
|
||||||
SoundImpl *mData;
|
SoundImpl *mData;
|
||||||
std::vector<boost::filesystem::path> files;
|
std::vector<boost::filesystem::path> files;
|
||||||
bool fsStrict;
|
bool fsStrict;
|
||||||
|
MWWorld::Environment& mEnvironment;
|
||||||
|
|
||||||
|
int total;
|
||||||
|
ESM::Region test;
|
||||||
|
boost::timer timer;
|
||||||
|
|
||||||
void streamMusicFull (const std::string& filename);
|
void streamMusicFull (const std::string& filename);
|
||||||
///< Play a soundifle
|
///< Play a soundifle
|
||||||
|
@ -39,7 +52,8 @@ namespace MWSound
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store,
|
SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store,
|
||||||
boost::filesystem::path dataDir, bool useSound, bool fsstrict);
|
boost::filesystem::path dataDir, bool useSound, bool fsstrict,
|
||||||
|
MWWorld::Environment& environment);
|
||||||
~SoundManager();
|
~SoundManager();
|
||||||
|
|
||||||
void streamMusic(const std::string& filename);
|
void streamMusic(const std::string& filename);
|
||||||
|
@ -60,8 +74,6 @@ namespace MWSound
|
||||||
bool sayDone (MWWorld::Ptr reference) const;
|
bool sayDone (MWWorld::Ptr reference) const;
|
||||||
///< Is actor not speaking?
|
///< Is actor not speaking?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void playSound (const std::string& soundId, float volume, float pitch);
|
void playSound (const std::string& soundId, float volume, float pitch);
|
||||||
///< Play a sound, independently of 3D-position
|
///< Play a sound, independently of 3D-position
|
||||||
|
|
||||||
|
@ -81,6 +93,8 @@ namespace MWSound
|
||||||
|
|
||||||
void updateObject(MWWorld::Ptr reference);
|
void updateObject(MWWorld::Ptr reference);
|
||||||
///< Update the position of all sounds connected to the given object.
|
///< Update the position of all sounds connected to the given object.
|
||||||
|
|
||||||
|
void update (float duration);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue