diff --git a/include/SoundManager.h b/include/SoundManager.h index f1dd7e7..8663d34 100644 --- a/include/SoundManager.h +++ b/include/SoundManager.h @@ -7,14 +7,6 @@ #include "ECS.h" #include "TextureManager.h" -// enum SoundTypes -// { -// STEPS, -// THROW_EGG, -// }; - -// class Game; - class GameInternal; /*! @@ -43,28 +35,43 @@ class SoundManager std::map music_cache; std::map sound_cache; - Mix_Music* loadMusic(const char* fileName); //!< Loads music from a file (mp3) - //! \returns a pointer to Mix_Music, which is added to a map in the AssetManager - //! \sa AssetManager::AddMusic(std::string id, const char* path) - Mix_Chunk* loadSound(const char* fileName); //!< Loads sound effects from a file (wav) - //! \returns a pointer to Mix_Chunk, which is added to a map in the AssetManager - //! \sa AssetManager::AddSound(std::string id, const char* path) + /*! + * \brief Loads music from a file (mp3) + * \returns a pointer to Mix_Music + * \sa AssetManager::AddMusic(std::string id, const char* path) + */ + Mix_Music* loadMusic(const char* fileName); + /*! + * \brief Loads sound effects from a file (wav) + * \returns a pointer to Mix_Chunk + * \sa AssetManager::AddSound(std::string id, const char* path) + */ + Mix_Chunk* loadSound(const char* fileName); - static void playSound(GameInternal* game, std::string sound, bool canOverlap, int loops, int volume, int channel); //!< Plays sound effects - //! handles if sounds can overlap, how often they can loop, as well as the volume at which the specified sound effect should play - static void playMusic(GameInternal* game, std::string sound, int loops, int volume, int ms); //music_cache.emplace(fileName, music); - printf("Loaded music at '%s'\n", fileName); + std::cout << "Loaded music at " << fileName << std::endl; return music; } @@ -38,22 +38,21 @@ Mix_Chunk* SoundManager::loadSound(const char* fileName) auto sound = Mix_LoadWAV(fileName); if (sound == NULL) - throw std::runtime_error(std::string("Couldn't load sound '") + fileName + "'"); + std::cerr << "Couldn't load sound '" << fileName << "'" << std::endl; this->sound_cache.emplace(fileName, sound); - printf("Loaded sound at '%s'\n", fileName); + std::cout << "Loaded sound at " << fileName << std::endl; return sound; } -// TODO: using a string here is probably... a less than stellar method, figure out how to change this void SoundManager::playSound(GameInternal* game, std::string sound, bool canOverlap, int loops, int volume, int channel) { if(!canOverlap) { if (Mix_Playing(channel) != 0) - return; + Mix_HaltChannel(channel); } if(Mix_VolumeChunk(game->assets->getSound(sound), volume) == -1)