Merge pull request #135 from AnonymusRaccoon/fix_sound_issue

add cache to sound
This commit is contained in:
Tom AUGIER
2021-06-09 15:06:15 +02:00
committed by GitHub
3 changed files with 11 additions and 5 deletions
+5 -3
View File
@@ -11,10 +11,12 @@ namespace BBM
float SoundComponent::volume = 0.75;
SoundComponent::SoundComponent(WAL::Entity &entity,
const std::map<SoundComponent::SoundIndex, std::string> &soundPath)
const std::map<SoundComponent::SoundIndex, std::string> &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<SoundIndex>(i)] = false;
@@ -22,7 +24,7 @@ namespace BBM
for (auto &soundPath : soundPath)
{
this->_isSoundLoad[soundPath.first] = true;
this->_soundList[soundPath.first] = std::make_unique<RAY::Audio::Sound>(soundPath.second);
this->_soundList[soundPath.first] = std::make_unique<RAY::Audio::Sound>(soundPath.second, this->_isLonely);
}
}
+5 -1
View File
@@ -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<SoundIndex, std::string> &);
explicit SoundComponent(WAL::Entity &entity,
const std::map<SoundIndex, std::string> &,
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<SoundIndex, std::shared_ptr<RAY::Audio::Sound>> _soundList;
//! @brief map to know if sound is loaded
std::map<SoundIndex, bool> _isSoundLoad;
//! @brief to know if cache is needed
bool _isLonely;
//! @brief All sounds path
const std::map<SoundIndex, std::string> _soundPath;
//! SoundIndex
+1 -1
View File
@@ -82,7 +82,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<PositionComponent>()