Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum SoundType{
- BOSS_JOY,
- BOSS_PAIN
- };
- typedef map<SoundType, CIwSoundSpec*> SoundMap;//mapping of soundtype to the actual sound
- typedef pair<SoundType, CIwSoundSpec*> SoundPair;
- typedef map<SoundType, const char*> EffectMap;//mapping of soundtype to the sound filename
- typedef pair<SoundType, const char*> EffectPair;
- void SoundBoard::play_fx(SoundType fx)
- {
- this->sounds.find(fx)->second->Play();
- }
- void SoundBoard::load_sounds(string group, EffectMap mapping)
- {
- string group_s = string(group);
- int found = group_s.find_last_of("/\\") + 1;
- this->group_name = group_s.substr(found);
- CIwResManager* res = IwGetResManager();
- res->LoadGroup(group.c_str());//load the group and loop through the mapping
- EffectMap::iterator pos;
- SoundMap* sounds_p = &this->sounds;
- for (pos = mapping.begin(); pos != mapping.end(); ++pos)
- {
- sounds_p->insert(SoundPair(pos->first, (CIwSoundSpec*)res->GetResNamed(pos->second, IW_SOUND_RESTYPE_SPEC)));
- }
- }
- ///////////
- void Sound::Init(string fileName,string filePath)
- {
- // Create resource handlers, and add them to the resource manager
- IwGetResManager()->AddHandler(new CIwResHandlerWAV);
- // Make res manager allocate its group buffer now to avoid fragmentation
- IwGetResManager()->ReserveGroups(10);
- // Initialise sound
- IwSoundInit();
- g_fileName = fileName.c_str();
- g_filePath = filePath.c_str();
- IwGetResManager()->LoadGroup("sound/sound.group");
- // set pointers to sound resources
- CIwResGroup* pGroup = IwGetResManager()->GetGroupNamed("sound");
- _soundRef = new CIwSoundManager();
- g_SoundSpecs[SFX_AMBIENCE] = (CIwSoundSpec*)pGroup->GetResNamed("ambience", IW_SOUND_RESTYPE_SPEC);
- g_SoundSpecs[SFX_KICK] = (CIwSoundSpec*)pGroup->GetResNamed("kick", IW_SOUND_RESTYPE_SPEC);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement