mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-29 17:06:43 +00:00
Preliminary region sound framework
This commit is contained in:
parent
a7c3a29ffd
commit
cab2341259
4 changed files with 111 additions and 37 deletions
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
#include <components/misc/fileops.hpp>
|
#include <components/misc/fileops.hpp>
|
||||||
#include <components/bsa/bsa_archive.hpp>
|
#include <components/bsa/bsa_archive.hpp>
|
||||||
|
#include <components/esm/loadregn.hpp>
|
||||||
|
#include <components/esm/esm_reader.hpp>
|
||||||
#include <openengine/gui/manager.hpp>
|
#include <openengine/gui/manager.hpp>
|
||||||
#include "mwgui/window_manager.hpp"
|
#include "mwgui/window_manager.hpp"
|
||||||
|
|
||||||
|
@ -59,35 +60,27 @@ void OMW::Engine::executeLocalScripts()
|
||||||
void OMW::Engine::MP3Lookup()
|
void OMW::Engine::MP3Lookup()
|
||||||
{
|
{
|
||||||
boost::filesystem::directory_iterator dir_iter(mDataDir / "Music/Explore/"), dir_end;
|
boost::filesystem::directory_iterator dir_iter(mDataDir / "Music/Explore/"), dir_end;
|
||||||
//std::list<boost::filesystem::path> files;
|
|
||||||
|
|
||||||
nFiles = 0;
|
|
||||||
std::string mp3extension = ".mp3";
|
std::string mp3extension = ".mp3";
|
||||||
for(;dir_iter != dir_end; dir_iter++)
|
for(;dir_iter != dir_end; dir_iter++)
|
||||||
{
|
{
|
||||||
if(boost::filesystem::extension(*dir_iter) == mp3extension)
|
if(boost::filesystem::extension(*dir_iter) == mp3extension)
|
||||||
{
|
{
|
||||||
files.push_front((*dir_iter));
|
files.push_back(*dir_iter);
|
||||||
nFiles++;
|
}
|
||||||
}
|
}
|
||||||
}//*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OMW::Engine::startRandomTitle()
|
void OMW::Engine::startRandomTitle()
|
||||||
{
|
{
|
||||||
|
std::vector<boost::filesystem::path>::iterator fileIter;
|
||||||
|
|
||||||
std::list<boost::filesystem::path>::iterator fileIter;
|
if(files.size() > 0)
|
||||||
if(nFiles > 0)
|
|
||||||
{
|
{
|
||||||
fileIter = files.begin();
|
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++)
|
for(int i = 1; i < r; i++)
|
||||||
{
|
{
|
||||||
fileIter++;
|
fileIter++;
|
||||||
|
@ -113,8 +106,30 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
|
||||||
startRandomTitle();
|
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
|
try
|
||||||
{
|
{
|
||||||
|
@ -165,6 +180,7 @@ bool OMW::Engine::frameStarted(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;
|
||||||
}
|
}
|
||||||
|
@ -274,6 +290,7 @@ void OMW::Engine::go()
|
||||||
assert (!mMaster.empty());
|
assert (!mMaster.empty());
|
||||||
|
|
||||||
MP3Lookup();
|
MP3Lookup();
|
||||||
|
test.name = "";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,8 @@ namespace OMW
|
||||||
|
|
||||||
class Engine : private Ogre::FrameListener
|
class Engine : private Ogre::FrameListener
|
||||||
{
|
{
|
||||||
std::list<boost::filesystem::path> files;
|
std::vector<boost::filesystem::path> files;
|
||||||
int nFiles;
|
//int nFiles;
|
||||||
boost::filesystem::path mDataDir;
|
boost::filesystem::path mDataDir;
|
||||||
OEngine::Render::OgreRenderer mOgre;
|
OEngine::Render::OgreRenderer mOgre;
|
||||||
std::string mCellName;
|
std::string mCellName;
|
||||||
|
@ -68,6 +68,7 @@ namespace OMW
|
||||||
Compiler::Extensions mExtensions;
|
Compiler::Extensions mExtensions;
|
||||||
Compiler::Context *mScriptContext;
|
Compiler::Context *mScriptContext;
|
||||||
OEngine::GUI::MyGUIManager *mGuiManager;
|
OEngine::GUI::MyGUIManager *mGuiManager;
|
||||||
|
ESM::Region test;
|
||||||
|
|
||||||
int focusFrameCounter;
|
int focusFrameCounter;
|
||||||
static const int focusUpdateFrame = 10;
|
static const int focusUpdateFrame = 10;
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
#include "environment.hpp"
|
#include "environment.hpp"
|
||||||
#include "class.hpp"
|
#include "class.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
#include "refdata.hpp"
|
||||||
|
#include "globals.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -62,6 +66,30 @@ namespace
|
||||||
|
|
||||||
namespace MWWorld
|
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)
|
void World::insertInteriorScripts (ESMS::CellStore<RefData>& cell)
|
||||||
{
|
{
|
||||||
listCellScripts (mStore, cell.activators, mLocalScripts, &cell);
|
listCellScripts (mStore, cell.activators, mLocalScripts, &cell);
|
||||||
|
@ -315,6 +343,7 @@ namespace MWWorld
|
||||||
: mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0),
|
: mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0),
|
||||||
mSky (false), mCellChanged (false), mEnvironment (environment)
|
mSky (false), mCellChanged (false), mEnvironment (environment)
|
||||||
{
|
{
|
||||||
|
isExterior = false;
|
||||||
boost::filesystem::path masterPath (dataDir);
|
boost::filesystem::path masterPath (dataDir);
|
||||||
masterPath /= master;
|
masterPath /= master;
|
||||||
|
|
||||||
|
@ -605,6 +634,8 @@ namespace MWWorld
|
||||||
adjustSky();
|
adjustSky();
|
||||||
|
|
||||||
mCellChanged = true;
|
mCellChanged = true;
|
||||||
|
isExterior = false;
|
||||||
|
//currentRegion->name = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::changeCell (int X, int Y, const ESM::Position& position)
|
void World::changeCell (int X, int Y, const ESM::Position& position)
|
||||||
|
@ -685,6 +716,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
isExterior = true;
|
||||||
|
|
||||||
positionToIndex (position.pos[0], position.pos[1], x, y);
|
positionToIndex (position.pos[0], position.pos[1], x, y);
|
||||||
|
|
||||||
|
@ -695,8 +727,20 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
// first try named cells
|
// first try named cells
|
||||||
if (const ESM::Cell *cell = mStore.cells.searchExtByName (cellName))
|
if (const ESM::Cell *cell = mStore.cells.searchExtByName (cellName))
|
||||||
|
{
|
||||||
|
//mCellChanged = true;
|
||||||
|
|
||||||
|
getExteriorRegion(cell->region);
|
||||||
return cell;
|
return cell;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return getExteriorRegion(cellName);
|
||||||
|
}
|
||||||
|
|
||||||
|
const ESM::Cell *World::getExteriorRegion(const std::string& cellName) const
|
||||||
|
{
|
||||||
// didn't work -> now check for regions
|
// didn't work -> now check for regions
|
||||||
std::string cellName2 = ESMS::RecListT<ESM::Region>::toLower (cellName);
|
std::string cellName2 = ESMS::RecListT<ESM::Region>::toLower (cellName);
|
||||||
|
|
||||||
|
@ -705,6 +749,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
if (ESMS::RecListT<ESM::Region>::toLower (iter->second.name)==cellName2)
|
if (ESMS::RecListT<ESM::Region>::toLower (iter->second.name)==cellName2)
|
||||||
{
|
{
|
||||||
|
*currentRegion = iter->second;
|
||||||
if (const ESM::Cell *cell = mStore.cells.searchExtByRegion (iter->first))
|
if (const ESM::Cell *cell = mStore.cells.searchExtByRegion (iter->first))
|
||||||
return cell;
|
return cell;
|
||||||
|
|
||||||
|
@ -794,6 +839,8 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void World::positionToIndex (float x, float y, int &cellX, int &cellY) const
|
void World::positionToIndex (float x, float y, int &cellX, int &cellY) const
|
||||||
{
|
{
|
||||||
const int cellSize = 8192;
|
const int cellSize = 8192;
|
||||||
|
|
|
@ -39,10 +39,16 @@ namespace MWWorld
|
||||||
|
|
||||||
class World
|
class World
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
typedef std::list<std::pair<std::string, Ptr> > ScriptList;
|
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:
|
private:
|
||||||
|
|
||||||
typedef std::map<Ptr::CellStore *, MWRender::CellRender *> CellRenderCollection;
|
typedef std::map<Ptr::CellStore *, MWRender::CellRender *> CellRenderCollection;
|
||||||
|
@ -61,7 +67,9 @@ namespace MWWorld
|
||||||
MWWorld::Globals *mGlobalVariables;
|
MWWorld::Globals *mGlobalVariables;
|
||||||
bool mSky;
|
bool mSky;
|
||||||
bool mCellChanged;
|
bool mCellChanged;
|
||||||
|
bool isExterior;
|
||||||
Environment& mEnvironment;
|
Environment& mEnvironment;
|
||||||
|
ESM::Region *currentRegion;
|
||||||
|
|
||||||
// not implemented
|
// not implemented
|
||||||
World (const World&);
|
World (const World&);
|
||||||
|
@ -146,6 +154,7 @@ namespace MWWorld
|
||||||
void changeToExteriorCell (const ESM::Position& position);
|
void changeToExteriorCell (const ESM::Position& position);
|
||||||
|
|
||||||
const ESM::Cell *getExterior (const std::string& cellName) const;
|
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.
|
///< Return a cell matching the given name or a 0-pointer, if there is no such cell.
|
||||||
|
|
||||||
void markCellAsUnchanged();
|
void markCellAsUnchanged();
|
||||||
|
|
Loading…
Reference in a new issue