From d261a4b58504aeb8b5c52f6a602dc899940a4337 Mon Sep 17 00:00:00 2001 From: Askou Date: Wed, 9 Jun 2021 14:59:55 +0200 Subject: [PATCH] add cache to sound --- sources/Component/Sound/SoundComponent.cpp | 8 +++++--- sources/Component/Sound/SoundComponent.hpp | 6 +++++- sources/Runner/Runner.cpp | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sources/Component/Sound/SoundComponent.cpp b/sources/Component/Sound/SoundComponent.cpp index 752efe9f..a2dde1db 100644 --- a/sources/Component/Sound/SoundComponent.cpp +++ b/sources/Component/Sound/SoundComponent.cpp @@ -11,10 +11,12 @@ namespace BBM float SoundComponent::volume = 0.75; SoundComponent::SoundComponent(WAL::Entity &entity, - const std::map &soundPath) + const std::map &soundPath, + bool isLonely) : WAL::Component(entity), _soundIndex(IDLE), - _soundPath(soundPath) + _soundPath(soundPath), + _isLonely(isLonely) { for (int i = 0; i <= DEATH; i++) { this->_isSoundLoad[static_cast(i)] = false; @@ -22,7 +24,7 @@ namespace BBM for (auto &soundPath : soundPath) { this->_isSoundLoad[soundPath.first] = true; - this->_soundList[soundPath.first] = std::make_unique(soundPath.second); + this->_soundList[soundPath.first] = std::make_unique(soundPath.second, this->_isLonely); } } diff --git a/sources/Component/Sound/SoundComponent.hpp b/sources/Component/Sound/SoundComponent.hpp index f5278114..926d02cc 100644 --- a/sources/Component/Sound/SoundComponent.hpp +++ b/sources/Component/Sound/SoundComponent.hpp @@ -53,7 +53,9 @@ namespace BBM //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; //! @brief Create a new SoundComponent at a certain Sound - explicit SoundComponent(WAL::Entity &entity, const std::map &); + explicit SoundComponent(WAL::Entity &entity, + const std::map &, + bool isLonely = false); //! @brief A Sound component is copy constructable SoundComponent(const SoundComponent &) = default; //! @brief A default destructor @@ -68,6 +70,8 @@ namespace BBM std::map> _soundList; //! @brief map to know if sound is loaded std::map _isSoundLoad; + //! @brief to know if cache is needed + bool _isLonely; //! @brief All sounds path const std::map _soundPath; //! SoundIndex diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 9f9e48d8..688b7d07 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -81,7 +81,7 @@ namespace BBM {SoundComponent::JUMP, "assets/sounds/jump.wav"}, {SoundComponent::MOVE, "assets/sounds/move.ogg"}, {SoundComponent::BOMB, "assets/sounds/bomb_drop.ogg"}, - {SoundComponent::DEATH, "assets/sounds/death.ogg"} + //{SoundComponent::DEATH, "assets/sounds/death.ogg"} }; scene->addEntity("player") .addComponent()