forked from mirror/openmw-tes3mp
Issue #19: fixed exception handling in engine's frame listener
This commit is contained in:
parent
10778d8c3e
commit
3bef04cb1d
1 changed files with 58 additions and 61 deletions
|
@ -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<ESM::Region::SoundRef>::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<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()))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue