mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-27 08:13:18 +00:00
add cache system for audio material
This commit is contained in:
@@ -8,57 +8,50 @@
|
||||
#include "Audio/Music.hpp"
|
||||
#include <raylib.h>
|
||||
|
||||
RAY::Cache<::Music> RAY::Audio::Music::_musicsCache(LoadMusicStream, UnloadMusicStream);
|
||||
|
||||
RAY::Audio::Music::Music(const std::string &path):
|
||||
_music(LoadMusicStream(path.c_str()))
|
||||
_music(this->_musicsCache.fetch(path.c_str()))
|
||||
{
|
||||
}
|
||||
|
||||
RAY::Audio::Music::Music()
|
||||
{
|
||||
}
|
||||
|
||||
RAY::Audio::Music::~Music()
|
||||
{
|
||||
UnloadMusicStream(_music);
|
||||
}
|
||||
|
||||
bool RAY::Audio::Music::isPlaying(void)
|
||||
{
|
||||
return IsMusicStreamPlaying(_music);
|
||||
return IsMusicStreamPlaying(*_music);
|
||||
}
|
||||
|
||||
RAY::Audio::Music &RAY::Audio::Music::play(void)
|
||||
{
|
||||
PlayMusicStream(_music);
|
||||
PlayMusicStream(*_music);
|
||||
return *this;
|
||||
}
|
||||
|
||||
RAY::Audio::Music &RAY::Audio::Music::stop(void)
|
||||
{
|
||||
StopMusicStream(_music);
|
||||
StopMusicStream(*_music);
|
||||
return *this;
|
||||
}
|
||||
|
||||
RAY::Audio::Music &RAY::Audio::Music::pause(void)
|
||||
{
|
||||
PauseMusicStream(_music);
|
||||
PauseMusicStream(*_music);
|
||||
return *this;
|
||||
}
|
||||
|
||||
RAY::Audio::Music &RAY::Audio::Music::resume(void)
|
||||
{
|
||||
ResumeMusicStream(_music);
|
||||
ResumeMusicStream(*_music);
|
||||
return *this;
|
||||
}
|
||||
|
||||
RAY::Audio::Music &RAY::Audio::Music::setVolume(float volume)
|
||||
{
|
||||
SetMusicVolume(_music, volume);
|
||||
SetMusicVolume(*_music, volume);
|
||||
return *this;
|
||||
}
|
||||
|
||||
RAY::Audio::Music &RAY::Audio::Music::setPitch(float pitch)
|
||||
{
|
||||
SetMusicPitch(_music, pitch);
|
||||
SetMusicPitch(*_music, pitch);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
#define MUSIC_HPP_
|
||||
|
||||
#include "Audio/IAudio.hpp"
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
#include "Utils/Cache.hpp"
|
||||
|
||||
namespace RAY::Audio
|
||||
{
|
||||
@@ -22,11 +21,8 @@ namespace RAY::Audio
|
||||
//! @brief Load Music stream from file
|
||||
Music(const std::string &path);
|
||||
|
||||
//! @brief Default constructor
|
||||
Music();
|
||||
|
||||
//! @brief Default destructor
|
||||
~Music();
|
||||
~Music() = default;
|
||||
|
||||
//! @brief A copy constructor constructor
|
||||
Music(const Music &Music) = default;
|
||||
@@ -56,7 +52,9 @@ namespace RAY::Audio
|
||||
Music &setPitch(float pitch) override;
|
||||
|
||||
private:
|
||||
::Music _music;
|
||||
std::shared_ptr<::Music> _music;
|
||||
|
||||
static RAY::Cache<::Music> _musicsCache;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,58 +7,51 @@
|
||||
|
||||
#include "Audio/Sound.hpp"
|
||||
|
||||
RAY::Cache<::Sound> RAY::Audio::Sound::_soundsCache(LoadSound, UnloadSound);
|
||||
|
||||
RAY::Audio::Sound::Sound(const std::string &path):
|
||||
_sound(LoadSound(path.c_str()))
|
||||
_sound(_soundsCache.fetch(path.c_str()))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RAY::Audio::Sound::Sound()
|
||||
{
|
||||
}
|
||||
|
||||
RAY::Audio::Sound::~Sound()
|
||||
{
|
||||
UnloadSound(_sound);
|
||||
}
|
||||
|
||||
bool RAY::Audio::Sound::isPlaying(void)
|
||||
{
|
||||
return IsSoundPlaying(_sound);
|
||||
return IsSoundPlaying(*_sound);
|
||||
}
|
||||
|
||||
RAY::Audio::Sound &RAY::Audio::Sound::play(void)
|
||||
{
|
||||
PlaySound(_sound);
|
||||
PlaySound(*_sound);
|
||||
return *this;
|
||||
}
|
||||
|
||||
RAY::Audio::Sound &RAY::Audio::Sound::stop(void)
|
||||
{
|
||||
StopSound(_sound);
|
||||
StopSound(*_sound);
|
||||
return *this;
|
||||
}
|
||||
|
||||
RAY::Audio::Sound &RAY::Audio::Sound::pause(void)
|
||||
{
|
||||
PauseSound(_sound);
|
||||
PauseSound(*_sound);
|
||||
return *this;
|
||||
}
|
||||
|
||||
RAY::Audio::Sound &RAY::Audio::Sound::resume(void)
|
||||
{
|
||||
ResumeSound(_sound);
|
||||
ResumeSound(*_sound);
|
||||
return *this;
|
||||
}
|
||||
|
||||
RAY::Audio::Sound &RAY::Audio::Sound::setVolume(float volume)
|
||||
{
|
||||
SetSoundVolume(_sound, volume);
|
||||
SetSoundVolume(*_sound, volume);
|
||||
return *this;
|
||||
}
|
||||
|
||||
RAY::Audio::Sound &RAY::Audio::Sound::setPitch(float pitch)
|
||||
{
|
||||
SetSoundPitch(_sound, pitch);
|
||||
SetSoundPitch(*_sound, pitch);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#define SOUND_HPP_
|
||||
|
||||
#include "Audio/IAudio.hpp"
|
||||
|
||||
#include "Utils/Cache.hpp"
|
||||
#include <raylib.h>
|
||||
|
||||
|
||||
@@ -22,11 +22,8 @@ namespace RAY::Audio
|
||||
//! @brief Load Sound stream from file
|
||||
Sound(const std::string &path);
|
||||
|
||||
//! @brief Default constructor
|
||||
Sound();
|
||||
|
||||
//! @brief Default destructor
|
||||
~Sound();
|
||||
~Sound() = default;
|
||||
|
||||
//! @brief A copy constructor constructor
|
||||
Sound(const Sound &sound) = default;
|
||||
@@ -56,7 +53,9 @@ namespace RAY::Audio
|
||||
Sound &setPitch(float pitch) override;
|
||||
|
||||
private:
|
||||
::Sound _sound;
|
||||
std::shared_ptr<::Sound> _sound;
|
||||
|
||||
static RAY::Cache<::Sound> _soundsCache;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
#include <raylib.h>
|
||||
|
||||
namespace RAY {
|
||||
//! @brief A templated class used to cache ressources, indexed with a string
|
||||
|
||||
Reference in New Issue
Block a user