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::MockAudioManager Class Reference

Mock music and sound effects manager for testing purposes.

#include <MockAudioManager.hpp>

Inheritance diagram for rd::MockAudioManager:
rd::AudioManager

Public Member Functions

bool isPlaying (const std::string &id) const
 Whether the sound with the given id is being played or not.
 
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 ~MockAudioManager ()
 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 = "MOCK"
 String that identifies this manager.
 
static const int AUDIO_DURATION = 30
 Default duration (s)
 
static const int UPDATE_PERIOD = 100
 Thread update period (ms)
 
- 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

 MockAudioManager ()
 Constructor. More...
 
 MockAudioManager (const MockAudioManager &)
 
MockAudioManageroperator= (const MockAudioManager &)
 
void run ()
 Method called periodically from the PeriodicThread class. It simply calls the update() method.
 

Private Attributes

std::mutex durations_mutex
 Dictionary for sound durations:
 
std::map< std::string, int > durations
 
std::mutex loop_times_mutex
 Dictionary for loop times.
 
std::map< std::string, int > loop_times
 
bool stopped
 

Static Private Attributes

static MockAudioManageruniqueInstance = 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

◆ MockAudioManager()

rd::MockAudioManager::MockAudioManager ( )
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::MockAudioManager::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::MockAudioManager::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::MockAudioManager::RegisterManager ( )
static

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

◆ start()

bool rd::MockAudioManager::start ( )
virtual

This function is supposed to be called after AudioManager configuration.

Implements rd::AudioManager.

◆ stopMusic()

bool rd::MockAudioManager::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: