Issue #19: fixed exception handling in engine's frame listener

This commit is contained in:
Marc Zinnschlag 2011-10-06 12:34:13 +02:00
parent 10778d8c3e
commit 3bef04cb1d

View file

@ -73,84 +73,82 @@ void OMW::Engine::executeLocalScripts()
mEnvironment.mWorld->getLocalScripts().setIgnore (MWWorld::Ptr()); mEnvironment.mWorld->getLocalScripts().setIgnore (MWWorld::Ptr());
} }
bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
{ {
if(mShowFPS) try
{ {
mEnvironment.mWindowManager->wmSetFPS(mOgre.getFPS()); if(mShowFPS)
}
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; mEnvironment.mWindowManager->wmSetFPS(mOgre.getFPS());
test = (ESM::Region) *(mEnvironment.mWorld->getStore().regions.find(current->cell->region));
} }
if(test.soundList.size() > 0) if(mUseSound && !(mEnvironment.mSoundManager->isMusicPlaying()))
{ {
std::vector<ESM::Region::SoundRef>::iterator soundIter = test.soundList.begin(); // Play some good 'ol tunes
//mEnvironment.mSoundManager mEnvironment.mSoundManager->startRandomTitle();
if(total == 0){ }
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;
}
}
srand ( time(NULL) );
int r = rand() % total; //old random code
int pos = 0;
soundIter = test.soundList.begin();
while (!(soundIter == test.soundList.end())) while (!(soundIter == test.soundList.end()))
{ {
ESM::NAME32 go = soundIter->sound; const ESM::NAME32 go = soundIter->sound;
int chance = (int) soundIter->chance; int chance = (int) soundIter->chance;
//std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n"; //std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n";
soundIter++; 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) ); //mEnvironment.mSoundManager->playSound(effect, 1.0, 1.0);
int r = rand() % total; //old random code //printf("REGION: %s\n", test.name);
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; }
else if(current->cell->data.flags & current->cell->Interior)
} {
pos += chance; 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; 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::cerr << "Error in framelistener: " << e.what() << std::endl;
} }
//std::cout << "TESTING2";
return true; return true;
} }