19#ifndef HEADER_SFX_MANAGER_HPP
20#define HEADER_SFX_MANAGER_HPP
22#include "utils/can_be_deleted.hpp"
23#include "utils/leak_check.hpp"
24#include "utils/no_copy.hpp"
25#include "utils/synchronised.hpp"
26#include "utils/vec3.hpp"
28#include <condition_variable>
39 typedef unsigned int ALuint;
86 SFX_MUSIC_SWITCH_FAST,
87 SFX_MUSIC_SET_TMP_VOLUME,
89 SFX_MUSIC_DEFAULT_VOLUME,
177 const Vec3 ¶meter)
223 uint64_t m_last_update_time;
259 const std::string &path=std::string(
""),
260 const bool load =
true);
262 const std::string &filename,
267 const bool load =
true);
270 const bool add_to_SFX_list=
true,
271 const bool owns_buffer=
false);
273 const bool addToSFXList=
true);
286 static bool checkError(
const std::string &context);
287 static const std::string getErrorString(
int err);
307 SFXBuffer* getBuffer(
const std::string &name);
A simple class that a adds a function to wait with a timeout for a class to be ready to be deleted.
Definition: can_be_deleted.hpp:38
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
The base class for sound effects.
Definition: sfx_base.hpp:43
The buffer (data) for one kind of sound effects.
Definition: sfx_buffer.hpp:44
Data structure for the queue, which stores a sfx and the command to execute for it.
Definition: sfx_manager.hpp:118
Vec3 m_parameter
Optional parameter for commands that need more input.
Definition: sfx_manager.hpp:135
SFXCommand(SFXCommands command, SFXBase *base, float f, const Vec3 ¶meter)
Store a float and vec3 parameter.
Definition: sfx_manager.hpp:176
SFXCommands m_command
The command to execute.
Definition: sfx_manager.hpp:132
SFXBase * m_sfx
The sound effect for which the command should be executed.
Definition: sfx_manager.hpp:123
SFXCommand(SFXCommands command, MusicInformation *mi, float f)
Constructor for music information commands that take a floating point parameter (which is stored in t...
Definition: sfx_manager.hpp:152
MusicInformation * m_music_information
Stores music information for music commands.
Definition: sfx_manager.hpp:129
SFXCommand(SFXCommands command, MusicInformation *mi)
Constructor for music information commands.
Definition: sfx_manager.hpp:144
SFXBuffer * m_buffer
The sound buffer to play (null = no change)
Definition: sfx_manager.hpp:126
Manager of all sound effects.
Definition: sfx_manager.hpp:55
float m_master_gain
Master gain value, taken from the user config value.
Definition: sfx_manager.hpp:216
void reallyPositionListenerNow()
Sets the position and orientation of the listener.
Definition: sfx_manager.cpp:1059
static bool checkError(const std::string &context)
Returns whether or not an openal error has occurred.
Definition: sfx_manager.cpp:961
Synchronised< std::vector< SFXBase * > > m_all_sfx
The actual instances (sound sources)
Definition: sfx_manager.hpp:203
void update()
Make sure that the sfx thread is started at least once per frame.
Definition: sfx_manager.cpp:807
void dump()
Prints the list of currently loaded sounds to stdout.
virtual ~SFXManager()
Destructor, frees all sound effects.
Definition: sfx_manager.cpp:111
SFXBase * createSoundSource(SFXBuffer *info, const bool add_to_SFX_list=true, const bool owns_buffer=false)
Creates a new SFX object.
Definition: sfx_manager.cpp:697
void reallyPauseAllNow()
Pauses all looping SFXs.
Definition: sfx_manager.cpp:916
void reallyUpdateNow(SFXCommand *current)
Updates the status of all playing sfx (to test if they are finished).
Definition: sfx_manager.cpp:828
static void create()
Static function to create the singleton sfx manager.
Definition: sfx_manager.cpp:59
Synchronised< std::map< std::string, SFXBase * > > m_quick_sounds
To play non-positional sounds without having to create a new object for each.
Definition: sfx_manager.hpp:210
CustomSFX
Entries for custom SFX sounds.
Definition: sfx_manager.hpp:99
@ CUSTOM_NAME
Introduction (e.g. "I'm Tux!")
Definition: sfx_manager.hpp:107
@ CUSTOM_PASS
Played when passing another kart.
Definition: sfx_manager.hpp:105
@ CUSTOM_ZIPPER
Played when kart hits zipper.
Definition: sfx_manager.hpp:106
@ CUSTOM_EXPLODE
Played when struck by bowling ball or dynamite.
Definition: sfx_manager.hpp:103
@ CUSTOM_GOO
Played when driving through goo.
Definition: sfx_manager.hpp:104
@ CUSTOM_ATTACH
Played when something is attached to kart (Uh-Oh)
Definition: sfx_manager.hpp:108
@ CUSTOM_SHOOT
Played when weapon is used.
Definition: sfx_manager.hpp:109
@ CUSTOM_WIN
Played when racer wins.
Definition: sfx_manager.hpp:102
@ CUSTOM_CRASH
Played when colliding with another kart.
Definition: sfx_manager.hpp:101
@ CUSTOM_HORN
Replaces default horn.
Definition: sfx_manager.hpp:100
Vec3 m_listener_up
Up vector of the listener.
Definition: sfx_manager.hpp:195
void resumeAll()
Resumes all paused SFXs.
Definition: sfx_manager.cpp:930
SFXManager()
Initialises the SFX manager and loads the sfx from a config file.
Definition: sfx_manager.cpp:77
void queue(SFXCommands command, SFXBase *sfx=NULL)
Adds a sound effect command to the queue of the sfx manager.
Definition: sfx_manager.cpp:166
SFXCommands
The various commands to be executed by the sfx manager thread for each sfx.
Definition: sfx_manager.hpp:65
Vec3 getListenerPos() const
Returns the current position of the listener.
Definition: sfx_manager.hpp:303
void loadSfx()
Loads all sounds specified in the sound config file.
Definition: sfx_manager.cpp:556
void toggleSound(const bool newValue)
Called when sound was muted/unmuted.
Definition: sfx_manager.cpp:501
void pauseAll()
Pauses all looping SFXs.
Definition: sfx_manager.cpp:905
SFXBuffer * loadSingleSfx(const XMLNode *node, const std::string &path=std::string(""), const bool load=true)
Loads a single sfx from the XML specification.
Definition: sfx_manager.cpp:650
static SFXManager * m_sfx_manager
Singleton pointer.
Definition: sfx_manager.hpp:58
bool sfxAllowed()
Returns if sfx can be played.
Definition: sfx_manager.cpp:543
void stopThread()
Puts a NULL request into the queue, which will trigger the thread to exit.
Definition: sfx_manager.cpp:322
std::map< std::string, SFXBuffer * > m_all_sfx_types
The buffers and info for all sound effects.
Definition: sfx_manager.hpp:200
Vec3 m_listener_front
The direction the listener is facing.
Definition: sfx_manager.hpp:192
static void mainLoop(void *obj)
This loops runs in a different threads, and starts sfx to be played.
Definition: sfx_manager.cpp:344
Synchronised< std::vector< SFXCommand * > > m_sfx_commands
The list of sound effects to be played in the next update.
Definition: sfx_manager.hpp:206
void reallyResumeAllNow()
Resumes all paused SFXs.
Definition: sfx_manager.cpp:940
SFXBuffer * addSingleSfx(const std::string &sfx_name, const std::string &filename, bool positional, float rolloff, float max_dist, float gain, const bool load=true)
Introduces a mechanism by which one can load sound effects beyond the basic enumerated types.
Definition: sfx_manager.cpp:617
void queueCommand(SFXCommand *command)
Enqueues a command to the sfx queue threadsafe.
Definition: sfx_manager.cpp:286
std::condition_variable m_condition_variable
A conditional variable to wake up the main loop.
Definition: sfx_manager.hpp:226
SFXBase * quickSound(const std::string &soundName)
Positional sound is cool, but creating a new object just to play a simple menu sound is not.
Definition: sfx_manager.cpp:1094
void deleteSFX(SFXBase *sfx)
Delete a sound effect object, and removes it from the internal list of all SFXs.
Definition: sfx_manager.cpp:875
bool m_initialized
If the sfx manager has been initialised.
Definition: sfx_manager.hpp:213
void setMasterSFXVolume(float gain)
Sets the master volume for all sound effects.
Definition: sfx_manager.cpp:984
void positionListener(const Vec3 &position, const Vec3 &front, const Vec3 &up)
Sets the position and orientation of the listener.
Definition: sfx_manager.cpp:1043
static SFXManager * get()
Static function to get the singleton sfx manager.
Definition: sfx_manager.hpp:250
static void destroy()
Static function to delete the singleton sfx manager.
Definition: sfx_manager.cpp:68
Synchronised< Vec3 > m_listener_position
The position of the listener.
Definition: sfx_manager.hpp:189
void deleteSFXMapping(const std::string &name)
This function removes a sfx buffer info entry from the mapping, and frees the openal buffer.
Definition: sfx_manager.cpp:785
std::thread m_thread
Thread id of the thread running in this object.
Definition: sfx_manager.hpp:220
bool soundExist(const std::string &name)
Returns true if a sfx with the given name exists.
Definition: sfx_manager.cpp:775
A variable that is automatically synchronised using pthreads mutex.
Definition: synchronised.hpp:28
TYPE getAtomic() const
Returns a copy of this variable.
Definition: synchronised.hpp:68
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
utility class used to parse XML files
Definition: xml_node.hpp:48