Preliminary region sound framework

actorid
Jason Hooks 14 years ago
parent a7c3a29ffd
commit cab2341259

@ -7,7 +7,8 @@
#include <components/misc/fileops.hpp>
#include <components/bsa/bsa_archive.hpp>
#include <components/esm/loadregn.hpp>
#include <components/esm/esm_reader.hpp>
#include <openengine/gui/manager.hpp>
#include "mwgui/window_manager.hpp"
@ -59,49 +60,41 @@ void OMW::Engine::executeLocalScripts()
void OMW::Engine::MP3Lookup()
{
boost::filesystem::directory_iterator dir_iter(mDataDir / "Music/Explore/"), dir_end;
//std::list<boost::filesystem::path> files;
nFiles = 0;
std::string mp3extension = ".mp3";
for(;dir_iter != dir_end; dir_iter++)
{
if(boost::filesystem::extension(*dir_iter) == mp3extension)
{
files.push_front((*dir_iter));
nFiles++;
files.push_back(*dir_iter);
}
}//*/
}
}
void OMW::Engine::startRandomTitle()
{
std::vector<boost::filesystem::path>::iterator fileIter;
std::list<boost::filesystem::path>::iterator fileIter;
if(nFiles > 0)
if(files.size() > 0)
{
fileIter = files.begin();
srand ( time(NULL) );
srand ( time(NULL) );
int r = rand() % files.size() + 1; //old random code
int r = rand() % nFiles + 1; //old random code
//int lowest=1, highest=nFiles;
//int range=(highest-lowest)+1;
//int r = lowest+int(range*rand()/(highest + 1.0));
for(int i = 1; i < r; i++)
{
fileIter++;
}
std::string music = fileIter->file_string();
try
{
std::cout << "Playing " << music << "\n";
for(int i = 1; i < r; i++)
{
fileIter++;
}
std::string music = fileIter->file_string();
try
{
std::cout << "Playing " << music << "\n";
mEnvironment.mSoundManager->streamMusic(music);
}
catch(std::exception &e)
{
std::cout << " Music Error: " << e.what() << "\n";
}
}
catch(std::exception &e)
{
std::cout << " Music Error: " << e.what() << "\n";
}
}
}
@ -112,9 +105,31 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
// Play some good 'ol tunes
startRandomTitle();
}
//tesprintf("HERE");t.mSoundManager.
//If the region has changed
if(mEnvironment.mWorld->getIsExterior() && test.name != mEnvironment.mWorld->getCurrentRegion().name){
test = mEnvironment.mWorld->getCurrentRegion();
if(test.soundList.size() > 0)
{
std::vector<ESM::Region::SoundRef>::iterator soundIter = test.soundList.begin();
while (!(soundIter == test.soundList.end()))
{
ESM::NAME32 go = soundIter->sound;
char chance = soundIter->chance;
std::cout << "Sound: " << go.name <<" Chance:" << (int) chance << "\n";
soundIter++;
}
}
//printf("REGION: %s\n", test.name);
}
else if(!mEnvironment.mWorld->getIsExterior())
{
test.name = "";
}
try
{
@ -165,6 +180,7 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
{
std::cerr << "Error in framelistener: " << e.what() << std::endl;
}
//std::cout << "TESTING2";
return true;
}
@ -274,6 +290,7 @@ void OMW::Engine::go()
assert (!mMaster.empty());
MP3Lookup();
test.name = "";

@ -52,8 +52,8 @@ namespace OMW
class Engine : private Ogre::FrameListener
{
std::list<boost::filesystem::path> files;
int nFiles;
std::vector<boost::filesystem::path> files;
//int nFiles;
boost::filesystem::path mDataDir;
OEngine::Render::OgreRenderer mOgre;
std::string mCellName;
@ -68,6 +68,7 @@ namespace OMW
Compiler::Extensions mExtensions;
Compiler::Context *mScriptContext;
OEngine::GUI::MyGUIManager *mGuiManager;
ESM::Region test;
int focusFrameCounter;
static const int focusUpdateFrame = 10;

@ -18,6 +18,10 @@
#include "environment.hpp"
#include "class.hpp"
#include "refdata.hpp"
#include "globals.hpp"
namespace
{
template<typename T>
@ -62,6 +66,30 @@ namespace
namespace MWWorld
{
ESM::ESMReader World::getEsmReader(){
return mEsm;
}
Ptr::CellStore World::getMCurrentCell()
{
return *mCurrentCell;
}
ESM::Region World::getCurrentRegion()
{
return *currentRegion;
}
bool World::getIsExterior()
{
return isExterior;
}
void World::setIsExterior(bool set)
{
isExterior = set;
}
void World::insertInteriorScripts (ESMS::CellStore<RefData>& cell)
{
listCellScripts (mStore, cell.activators, mLocalScripts, &cell);
@ -315,6 +343,7 @@ namespace MWWorld
: mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0),
mSky (false), mCellChanged (false), mEnvironment (environment)
{
isExterior = false;
boost::filesystem::path masterPath (dataDir);
masterPath /= master;
@ -605,6 +634,8 @@ namespace MWWorld
adjustSky();
mCellChanged = true;
isExterior = false;
//currentRegion->name = "";
}
void World::changeCell (int X, int Y, const ESM::Position& position)
@ -685,6 +716,7 @@ namespace MWWorld
{
int x = 0;
int y = 0;
isExterior = true;
positionToIndex (position.pos[0], position.pos[1], x, y);
@ -695,9 +727,21 @@ namespace MWWorld
{
// first try named cells
if (const ESM::Cell *cell = mStore.cells.searchExtByName (cellName))
{
//mCellChanged = true;
getExteriorRegion(cell->region);
return cell;
// didn't work -> now check for regions
}
return getExteriorRegion(cellName);
}
const ESM::Cell *World::getExteriorRegion(const std::string& cellName) const
{
// didn't work -> now check for regions
std::string cellName2 = ESMS::RecListT<ESM::Region>::toLower (cellName);
for (ESMS::RecListT<ESM::Region>::MapType::const_iterator iter (mStore.regions.list.begin());
@ -705,6 +749,7 @@ namespace MWWorld
{
if (ESMS::RecListT<ESM::Region>::toLower (iter->second.name)==cellName2)
{
*currentRegion = iter->second;
if (const ESM::Cell *cell = mStore.cells.searchExtByRegion (iter->first))
return cell;
@ -712,8 +757,8 @@ namespace MWWorld
}
}
return 0;
}
return 0;
}
void World::markCellAsUnchanged()
{
@ -794,6 +839,8 @@ namespace MWWorld
}
}
void World::positionToIndex (float x, float y, int &cellX, int &cellY) const
{
const int cellSize = 8192;

@ -39,10 +39,16 @@ namespace MWWorld
class World
{
public:
typedef std::list<std::pair<std::string, Ptr> > ScriptList;
ESM::ESMReader getEsmReader();
Ptr::CellStore getMCurrentCell();
ESM::Region getCurrentRegion();
bool getIsExterior();
void setIsExterior(bool set);
private:
typedef std::map<Ptr::CellStore *, MWRender::CellRender *> CellRenderCollection;
@ -61,7 +67,9 @@ namespace MWWorld
MWWorld::Globals *mGlobalVariables;
bool mSky;
bool mCellChanged;
bool isExterior;
Environment& mEnvironment;
ESM::Region *currentRegion;
// not implemented
World (const World&);
@ -146,6 +154,7 @@ namespace MWWorld
void changeToExteriorCell (const ESM::Position& position);
const ESM::Cell *getExterior (const std::string& cellName) const;
const ESM::Cell *getExteriorRegion (const std::string& cellName) const;
///< Return a cell matching the given name or a 0-pointer, if there is no such cell.
void markCellAsUnchanged();

Loading…
Cancel
Save