Robot Devastation
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
rd::SDLAudioManager Class Reference

Music and sound effects manager using SDL libraries.

#include <SDLAudioManager.hpp>

Inheritance diagram for rd::SDLAudioManager:
rd::AudioManager

Public Member Functions

bool load (const std::string &music_filepath, const std::string &id, const int &type)
 Loads an audio file, assigning it a string as identifier. More...
 
bool play (const std::string &id, int loop)
 Plays a music/sound effect file previously loaded. More...
 
bool stopMusic ()
 Stops the music being played currently. More...
 
virtual bool start ()
 Start the AudioManager. More...
 
virtual bool stop ()
 Stops the AudioManager.
 
virtual bool isStopped () const
 True if the manager is not active.
 
virtual ~SDLAudioManager ()
 Destructor. Used to reset the local static reference after destroying this manager.
 
- Public Member Functions inherited from rd::AudioManager
virtual bool configure (const std::string &parameter, const std::string &value)
 Configures a parameter with a value.
 

Static Public Member Functions

static bool RegisterManager ()
 Register this manager in the AudioManager registry so that can be used. More...
 
- Static Public Member Functions inherited from rd::AudioManager
static AudioManagergetAudioManager ()
 Get a reference to the AudioManager. More...
 
static AudioManagergetAudioManager (const std::string &id)
 Get a reference to the AudioManager. More...
 
static bool destroyAudioManager ()
 Deallocate all the registered AudioManager.
 

Static Public Attributes

static const std::string id = "SDL"
 String that identifies this manager.
 
- Static Public Attributes inherited from rd::AudioManager
static const int MUSIC = 0
 Identifier for music tracks.
 
static const int FX = 1
 Identifier for sound effect tracks.
 

Private Member Functions

 SDLAudioManager ()
 Constructor. More...
 
 SDLAudioManager (const SDLAudioManager &)
 
SDLAudioManageroperator= (const SDLAudioManager &)
 

Private Attributes

std::map< std::string, Mix_Chunk * > fx_sounds
 Dictionary for the sound effects.
 
std::map< std::string, Mix_Music * > music_sounds
 Dictionary for the music tracks.
 
bool stopped
 

Static Private Attributes

static SDLAudioManageruniqueInstance = NULL
 Stores the unique instance of the AudioManager.
 

Additional Inherited Members

- Static Protected Member Functions inherited from rd::AudioManager
static bool Register (AudioManager *manager, const std::string &id)
 This function allows subclasses to install their unique instances in the singleton register to be selected later by the user.
 

Constructor & Destructor Documentation

◆ SDLAudioManager()

rd::SDLAudioManager::SDLAudioManager ( )
private

Constructor for this class is private, since the singleton can only be instantiated once, and the instantiation is done at the RegisterManager() method

Member Function Documentation

◆ load()

bool rd::SDLAudioManager::load ( const std::string &  music_filepath,
const std::string &  id,
const int &  type 
)
virtual
Parameters
music_filepathPath to the file to be loaded
idString that will identify the audio loaded
typeCan take a value of MUSIC or FX depending if the audio is to be loaded as game music or sound effect
Returns
True if sound was loaded successfully, false otherwise

Implements rd::AudioManager.

◆ play()

bool rd::SDLAudioManager::play ( const std::string &  id,
int  loop 
)
virtual
Parameters
idString that identifies the music / sound effect track
loopNumber of times the music is played. -1 means play the music forever.
Returns
True if sound was played successfully, false otherwise

Implements rd::AudioManager.

◆ RegisterManager()

bool rd::SDLAudioManager::RegisterManager ( )
static

It ensures that only one manager of this type is created (unique instance).

◆ start()

bool rd::SDLAudioManager::start ( )
virtual

This function is supposed to be called after AudioManager configuration.

Implements rd::AudioManager.

◆ stopMusic()

bool rd::SDLAudioManager::stopMusic ( )
virtual
Returns
False if the music could not be stopped

Implements rd::AudioManager.


The documentation for this class was generated from the following files: