Advertisement
Guest User

Untitled

a guest
May 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. enum SoundType{
  2.     BOSS_JOY,
  3.     BOSS_PAIN
  4. };
  5.  
  6. typedef map<SoundType, CIwSoundSpec*> SoundMap;//mapping of soundtype to the actual sound
  7. typedef pair<SoundType, CIwSoundSpec*> SoundPair;
  8. typedef map<SoundType, const char*> EffectMap;//mapping of soundtype to the sound filename
  9. typedef pair<SoundType, const char*> EffectPair;
  10.  
  11.  
  12. void SoundBoard::play_fx(SoundType fx)
  13. {
  14.     this->sounds.find(fx)->second->Play();
  15. }
  16.  
  17. void SoundBoard::load_sounds(string group, EffectMap mapping)
  18. {
  19.     string group_s = string(group);
  20.     int found = group_s.find_last_of("/\\") + 1;
  21.     this->group_name = group_s.substr(found);
  22.     CIwResManager* res = IwGetResManager();
  23.     res->LoadGroup(group.c_str());//load the group and loop through the mapping
  24.     EffectMap::iterator pos;
  25.     SoundMap* sounds_p = &this->sounds;
  26.  
  27.     for (pos = mapping.begin(); pos != mapping.end(); ++pos)
  28.     {
  29.         sounds_p->insert(SoundPair(pos->first, (CIwSoundSpec*)res->GetResNamed(pos->second, IW_SOUND_RESTYPE_SPEC)));
  30.     }
  31. }
  32.  
  33. ///////////
  34. void Sound::Init(string fileName,string filePath)
  35. {
  36.  
  37.      // Create resource handlers, and add them to the resource manager
  38.      IwGetResManager()->AddHandler(new CIwResHandlerWAV);
  39.  
  40.       // Make res manager allocate its group buffer now to avoid fragmentation
  41.       IwGetResManager()->ReserveGroups(10);
  42.  
  43.      // Initialise sound
  44.         IwSoundInit();
  45.  
  46.       g_fileName = fileName.c_str();
  47.       g_filePath = filePath.c_str();
  48.  
  49.    
  50.     IwGetResManager()->LoadGroup("sound/sound.group");
  51.  
  52.     // set pointers to sound resources
  53.     CIwResGroup* pGroup = IwGetResManager()->GetGroupNamed("sound");
  54.    
  55.     _soundRef = new CIwSoundManager();
  56.  
  57.     g_SoundSpecs[SFX_AMBIENCE] = (CIwSoundSpec*)pGroup->GetResNamed("ambience", IW_SOUND_RESTYPE_SPEC);
  58.     g_SoundSpecs[SFX_KICK] = (CIwSoundSpec*)pGroup->GetResNamed("kick", IW_SOUND_RESTYPE_SPEC);
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement