|
|
|
@ -123,14 +123,13 @@ CSoundBank::~CSoundBank()
|
|
|
|
|
|
|
|
|
|
void CSoundBank::addSound(CSound *sound)
|
|
|
|
|
{
|
|
|
|
|
std::pair<TSoundTable::iterator, bool> ret;
|
|
|
|
|
ret = _Sounds.insert(make_pair(sound->getName(), sound));
|
|
|
|
|
nlassert(ret.second);
|
|
|
|
|
nlassert(_Sounds.size() > sound->getName().getShortId());
|
|
|
|
|
_Sounds[sound->getName().getShortId()] = sound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBank::removeSound(const NLMISC::CSheetId &name)
|
|
|
|
|
void CSoundBank::removeSound(const NLMISC::CSheetId &sheetId)
|
|
|
|
|
{
|
|
|
|
|
_Sounds.erase(name);
|
|
|
|
|
_Sounds[sheetId.getShortId()] = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -155,7 +154,7 @@ public:
|
|
|
|
|
void readGeorges (const NLMISC::CSmartPtr<NLGEORGES::UForm> &form, const NLMISC::CSheetId &name)
|
|
|
|
|
{
|
|
|
|
|
// just call the sound creation method with the xml form.
|
|
|
|
|
Sound = CSound::createSound(name.toString(), form->getRootNode());
|
|
|
|
|
Sound = CSound::createSound(name, form->getRootNode());
|
|
|
|
|
|
|
|
|
|
// success ?
|
|
|
|
|
// if (_Sound != 0)
|
|
|
|
@ -259,36 +258,51 @@ void CSoundBank::load(const std::string &packedSheetDir, bool packedSheetUpdate)
|
|
|
|
|
{
|
|
|
|
|
// this structure is fill by the loadForm() function and will contain all you need
|
|
|
|
|
//std::map<std::string, CSoundSerializer> Container;
|
|
|
|
|
std::map<NLMISC::CSheetId, CSoundSerializer> Container;
|
|
|
|
|
std::map<NLMISC::CSheetId, CSoundSerializer> container;
|
|
|
|
|
nlassert(!_Loaded);
|
|
|
|
|
// Just call the GEORGE::loadFrom method to read all available sounds
|
|
|
|
|
::loadForm("sound", packedSheetDir + "sounds.packed_sheets", Container, packedSheetUpdate, false);
|
|
|
|
|
::loadForm("sound", packedSheetDir + "sounds.packed_sheets", container, packedSheetUpdate, false);
|
|
|
|
|
_Loaded = true;
|
|
|
|
|
|
|
|
|
|
// get the largest sheet id needed and init the sound bank
|
|
|
|
|
uint32 maxShortId = 0;
|
|
|
|
|
{
|
|
|
|
|
std::map<NLMISC::CSheetId, CSoundSerializer>::iterator first(container.begin()), last(container.end());
|
|
|
|
|
for (; first != last; ++first)
|
|
|
|
|
{
|
|
|
|
|
if (first->first.getShortId() > maxShortId)
|
|
|
|
|
maxShortId = first->first.getShortId();
|
|
|
|
|
}
|
|
|
|
|
++maxShortId; // inc for size = last idx + 1
|
|
|
|
|
nlassert(maxShortId < (container.size() * 8)); // ensure no ridiculous sheet id values
|
|
|
|
|
if (maxShortId > _Sounds.size())
|
|
|
|
|
_Sounds.resize(maxShortId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add all the loaded sound in the sound banks
|
|
|
|
|
//std::map<std::string, CSoundSerializer>::iterator first(Container.begin()), last(Container.end());
|
|
|
|
|
std::map<NLMISC::CSheetId, CSoundSerializer>::iterator first(Container.begin()), last(Container.end());
|
|
|
|
|
for (; first != last; ++first)
|
|
|
|
|
{
|
|
|
|
|
if (first->second.Sound != 0)
|
|
|
|
|
addSound(first->second.Sound);
|
|
|
|
|
std::map<NLMISC::CSheetId, CSoundSerializer>::iterator first(container.begin()), last(container.end());
|
|
|
|
|
for (; first != last; ++first)
|
|
|
|
|
{
|
|
|
|
|
if (first->second.Sound != 0)
|
|
|
|
|
addSound(first->second.Sound);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Container.clear();
|
|
|
|
|
container.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Unload all the sound samples in this bank.
|
|
|
|
|
*/
|
|
|
|
|
void CSoundBank::unload()
|
|
|
|
|
void CSoundBank::unload()
|
|
|
|
|
{
|
|
|
|
|
nlassert(_Loaded);
|
|
|
|
|
|
|
|
|
|
TSoundTable::iterator first(_Sounds.begin()), last(_Sounds.end());
|
|
|
|
|
for (; first != last; ++first)
|
|
|
|
|
for (TSoundTable::size_type i = 0; i < _Sounds.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
delete first->second;
|
|
|
|
|
delete _Sounds[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_Sounds.clear();
|
|
|
|
@ -322,7 +336,7 @@ void CSoundBank::unload()
|
|
|
|
|
/*
|
|
|
|
|
* Returns true if the samples in this bank have been loaded.
|
|
|
|
|
*/
|
|
|
|
|
bool CSoundBank::isLoaded()
|
|
|
|
|
bool CSoundBank::isLoaded()
|
|
|
|
|
{
|
|
|
|
|
return _Loaded;
|
|
|
|
|
}
|
|
|
|
@ -330,37 +344,32 @@ bool CSoundBank::isLoaded()
|
|
|
|
|
/*
|
|
|
|
|
* Return a sound sample corresponding to a name.
|
|
|
|
|
*/
|
|
|
|
|
CSound* CSoundBank::getSound(const NLMISC::CSheetId &name)
|
|
|
|
|
CSound* CSoundBank::getSound(const NLMISC::CSheetId &sheetId)
|
|
|
|
|
{
|
|
|
|
|
// Find sound
|
|
|
|
|
TSoundTable::iterator iter = _Sounds.find(name);
|
|
|
|
|
if ( iter == _Sounds.end() )
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return (*iter).second;
|
|
|
|
|
}
|
|
|
|
|
if (sheetId == NLMISC::CSheetId::Unknown)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
nlassert(sheetId.getShortId() < _Sounds.size());
|
|
|
|
|
|
|
|
|
|
return _Sounds[sheetId.getShortId()];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the names of the sounds
|
|
|
|
|
*/
|
|
|
|
|
void CSoundBank::getNames( std::vector<NLMISC::CSheetId> &names )
|
|
|
|
|
void CSoundBank::getNames( std::vector<NLMISC::CSheetId> &sheetIds )
|
|
|
|
|
{
|
|
|
|
|
TSoundTable::const_iterator iter;
|
|
|
|
|
for (iter = _Sounds.begin(); iter != _Sounds.end(); ++iter)
|
|
|
|
|
for (TSoundTable::size_type i = 0; i < _Sounds.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
names.push_back((*iter).first);
|
|
|
|
|
//nlwarning("getting sound %s", (*iter).first);
|
|
|
|
|
if (_Sounds[i])
|
|
|
|
|
sheetIds.push_back(_Sounds[i]->getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Return the number of buffers in this bank.
|
|
|
|
|
*/
|
|
|
|
|
uint CSoundBank::countSounds()
|
|
|
|
|
uint CSoundBank::countSounds()
|
|
|
|
|
{
|
|
|
|
|
return (uint)_Sounds.size();
|
|
|
|
|
}
|
|
|
|
|