X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Faudio%2Fsound_manager.h;h=b9878e4002fc1f849339ea0e60542830931afd78;hb=d46c78c842ab4090a3f46e560c891234167f124b;hp=48a14406384023f649ddeda28fad025028452218;hpb=4b476ec30e7dd62249328054402d6493c20a685d;p=supertux.git diff --git a/lib/audio/sound_manager.h b/lib/audio/sound_manager.h index 48a144063..b9878e400 100644 --- a/lib/audio/sound_manager.h +++ b/lib/audio/sound_manager.h @@ -21,6 +21,7 @@ #define SUPERTUX_SOUND_MANAGER_H #include +#include #include #include "SDL_mixer.h" @@ -32,25 +33,34 @@ namespace SuperTux class MusicRef; class MovingObject; + /// enum of different internal music types + enum Music_Type { + NO_MUSIC, + LEVEL_MUSIC, + HURRYUP_MUSIC, + HERRING_MUSIC + }; + /// Sound manager /** This class handles all sounds that are played */ class SoundManager { public: - SoundManager(); - ~SoundManager(); - /// Play sound. void play_sound(Mix_Chunk* sound); /// Play sound relative to two Vectors. void play_sound(Mix_Chunk* sound, const Vector& pos, const Vector& pos2); /// Play sound relative to a MovingObject and a Vector. void play_sound(Mix_Chunk* sound, const MovingObject* object, const Vector& pos); - + /// Load music. /** Is used to load the music for a MusicRef. */ MusicRef load_music(const std::string& file); + + /// Load sound. + Mix_Chunk * load_sound(const std::string& file); + /// Test if a certain music file exists. bool exists_music(const std::string& filename); @@ -64,9 +74,68 @@ namespace SuperTux /// Enable/Disable music. void enable_music(bool enable); + /// Is music enabled? + bool music_enabled() + { + return m_music_enabled; + } + + /// Enable/Disable sound. + void enable_sound(bool enable); + + /// Is sound enabled? + bool sound_enabled() + { + return m_sound_enabled; + } + + /* functions handling the sound and music */ + int open_audio(int frequency, Uint16 format, int channels, int chunksize); + void close_audio( void ); + + /// Is audio available? + bool audio_device_available() + { + return audio_device; + } + + void set_audio_device_available(bool available) + { + audio_device = available; + } + + static SoundManager* get() + { + return instance_ ? instance_ : instance_ = new SoundManager(); + } + static void destroy_instance() + { + delete instance_; + instance_ = 0; + } + + void add_sound(Mix_Chunk* sound, int id) + { + sounds[id] = sound; + } + + Mix_Chunk* get_sound(int id) + { + return sounds[id]; + } + private: + SoundManager(); + ~SoundManager(); + // music part friend class MusicRef; + friend class Setup; + friend Mix_Chunk* IDToSound(int id); + + static SoundManager* instance_ ; + + void free_chunk(Mix_Chunk* chunk); /// Resource for music. /** Contains the raw music data and @@ -84,12 +153,17 @@ namespace SuperTux void free_music(MusicResource* music); + /*variables for stocking the sound and music*/ + std::map sounds; std::map musics; MusicResource* current_music; - bool music_enabled; + bool m_music_enabled; + bool m_sound_enabled; + bool audio_device; /* != 0: available and initialized */ }; + Mix_Chunk* IDToSound(int id); + } // namespace SuperTux - #endif /*SUPERTUX_SOUND_MANAGER_H*/