Back to index

supertuxkart  0.5+dfsg1
sound_manager.hpp
Go to the documentation of this file.
00001 //  $Id$
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2006 Patrick Ammann <pammann@aro.ch>
00005 //  Copyright (C) 2008 Patrick Ammann <pammann@aro.ch>, Joerg Henrichs
00006 //
00007 //  This program is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU General Public License
00009 //  as published by the Free Software Foundation; either version 2
00010 //  of the License, or (at your option) any later version.
00011 //
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU General Public License
00018 //  along with this program; if not, write to the Free Software
00019 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 #ifndef HEADER_SOUNDMANAGER_H
00022 #define HEADER_SOUNDMANAGER_H
00023 
00024 #include <map>
00025 #include <vector>
00026 #include <string>
00027 
00028 #include "music.hpp"
00029 #include "music_information.hpp"
00030 #include "sfx.hpp"
00031 
00032 enum enumSFX {SOUND_UGH,  SOUND_WINNER, SOUND_CRASH, SOUND_GRAB,
00033               SOUND_SHOT, SOUND_WEE,   SOUND_EXPLOSION,
00034               SOUND_BZZT, SOUND_BEEP,
00035               SOUND_BACK_MENU, SOUND_USE_ANVIL, SOUND_USE_PARACHUTE,
00036               SOUND_SELECT_MENU, SOUND_MOVE_MENU, SOUND_FULL,
00037               SOUND_PRESTART, SOUND_START, SOUND_MISSILE_LOCK,
00038               NUM_SOUNDS};
00039 
00040 class SoundManager
00041 {
00042 private:
00043 
00044     typedef std::vector<SFX*> SFXsType;
00045 
00046     SFXsType                m_sfxs;
00047     MusicInformation       *m_current_music;
00048        
00049     bool                    m_initialized; //If the sound could not be initialized, e.g.
00050                                            //if the player doesn't has a sound card, we want
00051                                            //to avoid anything sound related so we crash the game.
00052     std::map<std::string,   MusicInformation*> 
00053                             m_allMusic;
00054     void                    loadMusicInformation();
00055 
00056 public:
00057     SoundManager();
00058     virtual ~SoundManager();
00059 
00060     void                    playSfx(unsigned int id);
00061     void                    startMusic(MusicInformation* mi);
00062     void                    stopMusic();
00063     void                    update(float dt)    {if(m_current_music)
00064                                                      m_current_music->update(dt);      }
00065     void                    pauseMusic()        {if(m_current_music)
00066                                                      m_current_music->pauseMusic();    }
00067     void                    resumeMusic()       {if(m_current_music)
00068                                                      m_current_music->resumeMusic();   }
00069     void                    switchToFastMusic() {if(m_current_music)
00070                                                     m_current_music->switchToFastMusic();}
00071     MusicInformation       *getCurrentMusic() {return m_current_music; }    
00072     MusicInformation       *getMusicInformation(const std::string& filename);
00073     void                    loadMusicFromOneDir(const std::string& dir);
00074     void                    addMusicToTracks();
00075 
00076 };
00077 
00078 extern SoundManager* sound_manager;
00079 
00080 #endif // HEADER_SOUNDMANAGER_H
00081