Fixed: Sound CSheetId implementation (part 1) (not tested)

This commit is contained in:
kaetemi 2012-06-02 14:54:39 +02:00
parent 08a449153c
commit ec318f0393
15 changed files with 99 additions and 122 deletions

View file

@ -21,7 +21,6 @@
#include "nel/misc/string_mapper.h" #include "nel/misc/string_mapper.h"
#include "nel/misc/plane.h" #include "nel/misc/plane.h"
#include "nel/misc/aabbox.h" #include "nel/misc/aabbox.h"
#include "nel/misc/sheet_id.h"
#include "nel/3d/transform.h" #include "nel/3d/transform.h"
@ -126,9 +125,9 @@ public:
//\name Sound related. //\name Sound related.
//@{ //@{
void setSoundGroup(const std::string &soundGroup); void setSoundGroup(const std::string &soundGroup);
void setSoundGroup(const NLMISC::CSheetId &soundGroupId); void setSoundGroup(const NLMISC::TStringId &soundGroupId);
const std::string &getSoundGroup(); const std::string &getSoundGroup();
NLMISC::CSheetId getSoundGroupId(); NLMISC::TStringId getSoundGroupId();
void setEnvironmentFx(const std::string &environmentFx); void setEnvironmentFx(const std::string &environmentFx);
void setEnvironmentFx(const NLMISC::TStringId &environmentFxId); void setEnvironmentFx(const NLMISC::TStringId &environmentFxId);
const std::string &getEnvironmentFx(); const std::string &getEnvironmentFx();
@ -189,7 +188,7 @@ private:
std::vector<NLMISC::CPlane> _Volume; std::vector<NLMISC::CPlane> _Volume;
/// Sound group name id /// Sound group name id
NLMISC::CSheetId _SoundGroupId; NLMISC::TStringId _SoundGroupId;
/// Environement Fx name Id (using CStringMapper) /// Environement Fx name Id (using CStringMapper)
NLMISC::TStringId _EnvironmentFxId; NLMISC::TStringId _EnvironmentFxId;

View file

@ -19,6 +19,7 @@
#include "nel/misc/types_nl.h" #include "nel/misc/types_nl.h"
#include "nel/misc/string_mapper.h" #include "nel/misc/string_mapper.h"
#include "nel/misc/sheet_id.h"
#include <vector> #include <vector>
#include <map> #include <map>
@ -249,14 +250,13 @@ private:
/// The segment of all the audio path. /// The segment of all the audio path.
std::vector<std::pair<NLMISC::CVector, NLMISC::CVector> > _AudioPath; std::vector<std::pair<NLMISC::CVector, NLMISC::CVector> > _AudioPath;
typedef CHashMap<NLMISC::CSheetId, CClusterSound, NLMISC::CSheetIdHashMapTraits> TClusterSoundCont; typedef CHashMap<NLMISC::TStringId, CClusterSound, NLMISC::CStringIdHashMapTraits> TClusterSoundCont;
/// The current cluster playing source indexed with sound group id /// The current cluster playing source indexed with sound group id
TClusterSoundCont _Sources; TClusterSoundCont _Sources;
typedef CHashMap<NLMISC::CSheetId, NLMISC::CSheetId, NLMISC::CSheetIdHashMapTraits> TStringStringMap; typedef CHashMap<NLMISC::TStringId, NLMISC::CSheetId, NLMISC::CStringIdHashMapTraits> TStringSheetMap;
//typedef CHashMap<NLMISC::TStringId, NLMISC::TStringId, NLMISC::CStringIdHashMapTraits> TStringStringMap;
/// The sound_group to sound assoc /// The sound_group to sound assoc
TStringStringMap _SoundGroupToSound; TStringSheetMap _SoundGroupToSound;
}; };
} // NLSOUND } // NLSOUND

View file

@ -54,7 +54,7 @@ class CSound
friend class CAudioMixerUser; friend class CAudioMixerUser;
public: public:
/// Factory for specialized sound. /// Factory for specialized sound.
static CSound *createSound(const std::string &filename, NLGEORGES::UFormElm& formRoot); static CSound *createSound(const NLMISC::CSheetId &sheetId, NLGEORGES::UFormElm& formRoot);
enum TSOUND_TYPE enum TSOUND_TYPE
{ {

View file

@ -68,16 +68,16 @@ public:
bool isLoaded(); bool isLoaded();
/// Return a sound corresponding to a name. /// Return a sound corresponding to a name.
CSound *getSound(const NLMISC::CSheetId &name); CSound *getSound(const NLMISC::CSheetId &sheetId);
/// Return the names of the sounds /// Return the names of the sounds
void getNames( std::vector<NLMISC::CSheetId> &names ); void getNames( std::vector<NLMISC::CSheetId> &sheetIds );
/// Return the number of sounds in this bank. /// Return the number of sounds in this bank.
uint countSounds(); uint countSounds();
void addSound(CSound *sound); void addSound(CSound *sound);
void removeSound(const NLMISC::CSheetId &name); void removeSound(const NLMISC::CSheetId &sheetId);
private: private:
@ -89,7 +89,8 @@ private:
typedef CHashMap<NLMISC::TStringId, TSimpleSoundContainer, NLMISC::CStringIdHashMapTraits> TBufferAssocContainer; typedef CHashMap<NLMISC::TStringId, TSimpleSoundContainer, NLMISC::CStringIdHashMapTraits> TBufferAssocContainer;
/// Sound names hash map /// Sound names hash map
// typedef std::hash_map<std::string, CSound*> TSoundTable; // typedef std::hash_map<std::string, CSound*> TSoundTable;
typedef CHashMap<NLMISC::CSheetId, CSound*, NLMISC::CSheetIdHashMapTraits> TSoundTable; // typedef CHashMap<NLMISC::CSheetId, CSound*, NLMISC::CSheetIdHashMapTraits> TSoundTable;
typedef std::vector<CSound *> TSoundTable; // list the sheets by shortId of the sheetId
/// Assoc from buffer to sound. Used for sound unloading. /// Assoc from buffer to sound. Used for sound unloading.
TBufferAssocContainer _BufferAssoc; TBufferAssocContainer _BufferAssoc;

View file

@ -100,7 +100,7 @@ USource *OnAddSource( const char *name, float x, float y, float z )
/* /*
* Create a source with sound 'name', and set some of its initial properties, if successful * Create a source with sound 'name', and set some of its initial properties, if successful
*/ */
USource *source = AudioMixer->createSource( /*CStringMapper::map(name)*/ CSheetId(name) ); USource *source = AudioMixer->createSource(CSheetId(name));
if ( source != NULL ) if ( source != NULL )
{ {
source->setPos( CVector(x,y,z) ); source->setPos( CVector(x,y,z) );
@ -161,8 +161,8 @@ int main()
printf( "One is 20 meters ahead, on the right\n" ); printf( "One is 20 meters ahead, on the right\n" );
printf( "The other is 5 meters ahead, on the left\n" ); printf( "The other is 5 meters ahead, on the left\n" );
getchar(); getchar();
USource *src1 = OnAddSource( "beep", 1.0f, 20.0f, 0.0f ); // Beep on the right, 20 meters ahead USource *src1 = OnAddSource( "beep.sound", 1.0f, 20.0f, 0.0f ); // Beep on the right, 20 meters ahead
USource *src2 = OnAddSource( "tuut", -2.0f, 5.0f, 0.0f ); // Tuut on the left, 5 meters ahead USource *src2 = OnAddSource( "tuut.sound", -2.0f, 5.0f, 0.0f ); // Tuut on the left, 5 meters ahead
// Second step: we will move the listener ahead // Second step: we will move the listener ahead
printf( "Press ENTER again to start moving the listener\n" ); printf( "Press ENTER again to start moving the listener\n" );

View file

@ -97,7 +97,7 @@ static void initSample()
//NLMISC::CHTimer::startBench(); //NLMISC::CHTimer::startBench();
s_Source = s_AudioMixer->createSource(/*CStringMapper::map("stream_file")*/ CSheetId("stream_file")); s_Source = s_AudioMixer->createSource(CSheetId("stream_file.sound"));
nlassert(s_Source); nlassert(s_Source);
s_StreamFileSource = dynamic_cast<CStreamFileSource *>(s_Source); s_StreamFileSource = dynamic_cast<CStreamFileSource *>(s_Source);
nlassert(s_StreamFileSource); nlassert(s_StreamFileSource);

View file

@ -87,7 +87,7 @@ static void initSample()
//NLMISC::CHTimer::startBench(); //NLMISC::CHTimer::startBench();
USource *source = s_AudioMixer->createSource(CSheetId("default_stream")/*CStringMapper::map("default_stream")*/); USource *source = s_AudioMixer->createSource(CSheetId("default_stream.sound"));
nlassert(source); nlassert(source);
s_StreamSource = dynamic_cast<UStreamSource *>(source); s_StreamSource = dynamic_cast<UStreamSource *>(source);
nlassert(s_StreamSource); nlassert(s_StreamSource);

View file

@ -51,9 +51,7 @@ CCluster::CCluster ()
// map a no fx string // map a no fx string
_EnvironmentFxId = CStringMapper::map("no fx"); _EnvironmentFxId = CStringMapper::map("no fx");
// map a no soundgroup string // map a no soundgroup string
_SoundGroupId = NLMISC::CSheetId::Unknown; /*CStringMapper::map("")*/; _SoundGroupId = CStringMapper::map("");
nldebug("SOUNDSHEET: %s", _SoundGroupId.toString().c_str());
// I am a transform cluster // I am a transform cluster
CTransform::setIsCluster(true); CTransform::setIsCluster(true);
@ -78,21 +76,18 @@ CCluster::~CCluster()
void CCluster::setSoundGroup(const std::string &soundGroup) void CCluster::setSoundGroup(const std::string &soundGroup)
{ {
_SoundGroupId = NLMISC::CSheetId(soundGroup);/*CStringMapper::map(soundGroup);*/ _SoundGroupId = CStringMapper::map(soundGroup);
nldebug("SOUNDSHEET: %s", _SoundGroupId.toString().c_str());
} }
void CCluster::setSoundGroup(const NLMISC::CSheetId &soundGroupId) void CCluster::setSoundGroup(const NLMISC::TStringId &soundGroupId)
{ {
_SoundGroupId = soundGroupId; _SoundGroupId = soundGroupId;
nldebug("SOUNDSHEET: %s", _SoundGroupId.toString().c_str());
} }
const std::string &CCluster::getSoundGroup() const std::string &CCluster::getSoundGroup()
{ {
return _SoundGroupId.toString();/*CStringMapper::unmap(_SoundGroupId)*/; return CStringMapper::unmap(_SoundGroupId);
} }
NLMISC::CSheetId CCluster::getSoundGroupId() NLMISC::TStringId CCluster::getSoundGroupId()
{ {
return _SoundGroupId; return _SoundGroupId;
} }
@ -309,8 +304,7 @@ void CCluster::serial (NLMISC::IStream&f)
std::string envFxName; std::string envFxName;
f.serial(soundGroup); f.serial(soundGroup);
_SoundGroupId = NLMISC::CSheetId(soundGroup); /*CStringMapper::map(soundGroup)*/; _SoundGroupId = CStringMapper::map(soundGroup);
nldebug("SOUNDSHEET: %s", _SoundGroupId.toString().c_str());
f.serial(envFxName); f.serial(envFxName);
if (envFxName == "") if (envFxName == "")
@ -320,7 +314,7 @@ void CCluster::serial (NLMISC::IStream&f)
else else
{ {
// write the sound group // write the sound group
std::string soundGroup = _SoundGroupId.toString();/*CStringMapper::unmap(_SoundGroupId)*/; std::string soundGroup = CStringMapper::unmap(_SoundGroupId);
f.serial(soundGroup); f.serial(soundGroup);
// write the env fx name // write the env fx name
std::string envFxName = CStringMapper::unmap(_EnvironmentFxId); std::string envFxName = CStringMapper::unmap(_EnvironmentFxId);

View file

@ -261,17 +261,8 @@ void CPSSound::serial(NLMISC::IStream &f) throw(NLMISC::EStream)
CPSLocatedBindable::serial(f); CPSLocatedBindable::serial(f);
// version 3 : added option to keep original pitch from the .sound // version 3 : added option to keep original pitch from the .sound
sint ver = f.serialVersion(3); sint ver = f.serialVersion(3);
if (f.isReading())
{ _SoundName.serialString(f, "sound");
std::string soundName;
f.serial(soundName);
_SoundName = NLMISC::CSheetId(soundName)/*NLMISC::CStringMapper::map(soundName)*/;
}
else
{
std::string soundName = _SoundName.toString()/*NLMISC::CStringMapper::unmap(_SoundName)*/;
f.serial(soundName);
}
sint32 nbSounds; sint32 nbSounds;
bool hasScheme; bool hasScheme;

View file

@ -1050,9 +1050,8 @@ public:
for (uint i=0; i<size; ++i) for (uint i=0; i<size; ++i)
{ {
items->getArrayValue(soundName, i); items->getArrayValue(soundName, i);
soundName = soundName.substr(0, soundName.find(".sound")); nlassert(soundName.find(".sound") != std::string::npos);
cs.SoundNames.push_back(CSheetId(soundName));
cs.SoundNames.push_back(CSheetId(soundName)/*CStringMapper::map(soundName)*/);
} }
if (!cs.SoundNames.empty()) if (!cs.SoundNames.empty())
@ -1133,7 +1132,7 @@ void CAudioMixerUser::CControledSources::serial(NLMISC::IStream &s)
for (uint i=0; i<size; ++i) for (uint i=0; i<size; ++i)
{ {
s.serial(soundName); s.serial(soundName);
SoundNames.push_back(CSheetId(soundName)/*CStringMapper::map(soundName)*/); SoundNames.push_back(CSheetId(soundName.find(".sound") == std::string::npos ? (soundName + ".sound") : soundName));
} }
} }
else else
@ -1147,7 +1146,7 @@ void CAudioMixerUser::CControledSources::serial(NLMISC::IStream &s)
for (uint i=0; i<size; ++i) for (uint i=0; i<size; ++i)
{ {
soundName = SoundNames[i].toString();/*CStringMapper::unmap(SoundNames[i])*/; soundName = SoundNames[i].toString();;
s.serial(soundName); s.serial(soundName);
} }
} }
@ -2313,7 +2312,6 @@ void CAudioMixerUser::getLoadedSampleBankInfo(std::vector<std::pair<std::strin
} }
void CAudioMixerUser::setListenerPos (const NLMISC::CVector &pos) void CAudioMixerUser::setListenerPos (const NLMISC::CVector &pos)
{ {
_Listener.setPos(pos); _Listener.setPos(pos);

View file

@ -84,7 +84,8 @@ void CBackgroundSound::importForm(const std::string& filename, NLGEORGES::UFormE
// Read the sound name. // Read the sound name.
std::string soundName; std::string soundName;
psoundItem->getValueByName(soundName, "Sound"); psoundItem->getValueByName(soundName, "Sound");
sound.SoundName = NLMISC::CSheetId(CFile::getFilenameWithoutExtension(soundName));/*CStringMapper::map(CFile::getFilenameWithoutExtension(soundName))*/; nlassert(soundName.find(".sound") != std::string::npos);
sound.SoundName = NLMISC::CSheetId(soundName);
// Read the environnement flag. // Read the environnement flag.

View file

@ -86,7 +86,8 @@ void CBackgroundSoundManager::addSound(const std::string &soundName, uint layerI
CAudioMixerUser *mixer = CAudioMixerUser::instance(); CAudioMixerUser *mixer = CAudioMixerUser::instance();
TSoundData sd; TSoundData sd;
sd.SoundName = /*CStringMapper::map(soundName)*/ NLMISC::CSheetId(soundName); nlassert(soundName.find(".sound") != std::string::npos);
sd.SoundName = NLMISC::CSheetId(soundName);
sd.Sound = mixer->getSoundId(sd.SoundName); sd.Sound = mixer->getSoundId(sd.SoundName);
sd.Source = 0; sd.Source = 0;
@ -1431,21 +1432,15 @@ void CBackgroundSoundManager::TBanksData::serial(NLMISC::IStream &s)
void CBackgroundSoundManager::TSoundData::serial(NLMISC::IStream &s) void CBackgroundSoundManager::TSoundData::serial(NLMISC::IStream &s)
{ {
std::string str; //std::string str;
SoundName.serialString(s, "sound");
if (s.isReading()) if (s.isReading())
{ {
CAudioMixerUser *mixer = CAudioMixerUser::instance(); CAudioMixerUser *mixer = CAudioMixerUser::instance();
s.serial(str);
SoundName = /*NLMISC::CStringMapper::map(str)*/ NLMISC::CSheetId(str);
Sound = mixer->getSoundId(SoundName); Sound = mixer->getSoundId(SoundName);
Source = NULL; Source = NULL;
Selected = false; Selected = false;
} }
else
{
s.serial(const_cast<std::string&>(SoundName.toString()/*NLMISC::CStringMapper::unmap(SoundName)*/));
}
s.serial(MinBox); s.serial(MinBox);
s.serial(MaxBox); s.serial(MaxBox);
s.serial(Surface); s.serial(Surface);

View file

@ -70,7 +70,7 @@ float EAX_MATERIAL_PARAM[] =
class CSoundGroupSerializer class CSoundGroupSerializer
{ {
public: public:
std::vector<std::pair<NLMISC::CSheetId, NLMISC::CSheetId> > _SoundGroupAssoc; std::vector<std::pair<NLMISC::TStringId, NLMISC::CSheetId> > _SoundGroupAssoc;
// load the values using the george sheet (called by GEORGE::loadForm) // load the values using the george sheet (called by GEORGE::loadForm)
void readGeorges (const NLMISC::CSmartPtr<NLGEORGES::UForm> &form, const std::string &/* name */) void readGeorges (const NLMISC::CSmartPtr<NLGEORGES::UForm> &form, const std::string &/* name */)
@ -95,15 +95,9 @@ public:
item->getValueByName(soundGroup, ".SoundGroup"); item->getValueByName(soundGroup, ".SoundGroup");
item->getValueByName(sound, ".Sound"); item->getValueByName(sound, ".Sound");
string::size_type n = sound.rfind(".sound"); nlassert(sound.find(".sound") != std::string::npos);
if (n != string::npos) _SoundGroupAssoc.push_back(make_pair(CStringMapper::map(soundGroup), CSheetId(sound)));
{
// remove the tailing .sound
sound = sound.substr(0, n);
}
_SoundGroupAssoc.push_back(make_pair(CSheetId(soundGroup), CSheetId(sound) /*CStringMapper::map(soundGroup), CStringMapper::map(sound)*/));
} }
} }
catch(...) catch(...)
@ -125,24 +119,18 @@ public:
{ {
if (s.isReading()) if (s.isReading())
{ {
std::string soundGroup; TStringId soundGroup;
std::string sound; CSheetId sound;
s.serial(soundGroup); CStringMapper::serialString(s, soundGroup);
s.serial(sound); sound.serialString(s, "sound");
_SoundGroupAssoc.push_back(make_pair(CSheetId(soundGroup), CSheetId(sound) /*CStringMapper::map(soundGroup), CStringMapper::map(sound)*/)); _SoundGroupAssoc.push_back(make_pair(soundGroup, sound));
} }
else else
{ {
std::string soundGroup; CStringMapper::serialString(s, _SoundGroupAssoc[i].first);
std::string sound; _SoundGroupAssoc[i].second.serialString(s, "sound");
soundGroup = _SoundGroupAssoc[i].first.toString();// CStringMapper::unmap(_SoundGroupAssoc[i].first);
sound = _SoundGroupAssoc[i].second.toString(); //CStringMapper::unmap(_SoundGroupAssoc[i].second);
s.serial(soundGroup);
s.serial(sound);
} }
} }
} }
@ -254,10 +242,10 @@ void CClusteredSound::update(const CVector &listenerPos, const CVector &/* view
TClusterStatusMap::const_iterator first(_AudibleClusters.begin()), last(_AudibleClusters.end()); TClusterStatusMap::const_iterator first(_AudibleClusters.begin()), last(_AudibleClusters.end());
for (; first != last; ++first ) for (; first != last; ++first )
{ {
static NLMISC::CSheetId NO_SOUND_GROUP = /*CStringMapper::emptyId()*/NLMISC::CSheetId::Unknown; static NLMISC::TStringId NO_SOUND_GROUP = CStringMapper::emptyId();
const CClusterSoundStatus &css = first->second; const CClusterSoundStatus &css = first->second;
CCluster *cluster = first->first; CCluster *cluster = first->first;
NLMISC::CSheetId soundGroup; NLMISC::TStringId soundGroup;
soundGroup = cluster->getSoundGroupId(); soundGroup = cluster->getSoundGroupId();
@ -289,7 +277,7 @@ void CClusteredSound::update(const CVector &listenerPos, const CVector &/* view
// nldebug("Searching sound assoc for group [%s]", CStringMapper::unmap(soundGroup).c_str()); // nldebug("Searching sound assoc for group [%s]", CStringMapper::unmap(soundGroup).c_str());
TStringStringMap::iterator it2(_SoundGroupToSound.find(soundGroup)); TStringSheetMap::iterator it2(_SoundGroupToSound.find(soundGroup));
if (it2 != _SoundGroupToSound.end()) if (it2 != _SoundGroupToSound.end())
{ {
NLMISC::CSheetId soundName = it2->second; NLMISC::CSheetId soundName = it2->second;

View file

@ -37,8 +37,9 @@ using namespace NLMISC;
namespace NLSOUND { namespace NLSOUND {
CSound *CSound::createSound(const std::string &filename, NLGEORGES::UFormElm& formRoot) CSound *CSound::createSound(const NLMISC::CSheetId &sheetId, NLGEORGES::UFormElm& formRoot)
{ {
std::string filename = sheetId.toString();
CSound *ret = NULL; CSound *ret = NULL;
string soundType; string soundType;
@ -170,7 +171,7 @@ void CSound::serial(NLMISC::IStream &s)
void CSound::importForm(const std::string& filename, NLGEORGES::UFormElm& root) void CSound::importForm(const std::string& filename, NLGEORGES::UFormElm& root)
{ {
// Name // Name
_Name = NLMISC::CSheetId(CFile::getFilenameWithoutExtension(filename));//CStringMapper::map(CFile::getFilenameWithoutExtension(filename)); _Name = NLMISC::CSheetId(filename);
// InternalConeAngle // InternalConeAngle
uint32 inner; uint32 inner;

View file

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