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,
147 m_music_information = mi;
156 m_music_information = mi;
163 m_parameter.setX(parameter);
170 m_parameter = parameter;
177 const Vec3 ¶meter)
181 m_parameter = parameter;
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);
310 #endif // HEADER_SFX_MANAGER_HPP bool sfxAllowed()
Returns if sfx can be played.
Definition: sfx_manager.cpp:544
MusicInformation * m_music_information
Stores music information for music commands.
Definition: sfx_manager.hpp:129
void toggleSound(const bool newValue)
Called when sound was muted/unmuted.
Definition: sfx_manager.cpp:502
std::map< std::string, SFXBuffer * > m_all_sfx_types
The buffers and info for all sound effects.
Definition: sfx_manager.hpp:200
Data structure for the queue, which stores a sfx and the command to execute for it.
Definition: sfx_manager.hpp:117
void queue(SFXCommands command, SFXBase *sfx=NULL)
Adds a sound effect command to the queue of the sfx manager.
Definition: sfx_manager.cpp:166
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:618
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
A wrapper around bullets btVector3 to include conventient conversion functions (e.g.
Definition: vec3.hpp:34
Vec3 getListenerPos() const
Returns the current position of the listener.
Definition: sfx_manager.hpp:303
static bool checkError(const std::string &context)
Returns whether or not an openal error has occurred.
Definition: sfx_manager.cpp:962
void setMasterSFXVolume(float gain)
Sets the master volume for all sound effects.
Definition: sfx_manager.cpp:985
Introduction (e.g. "I'm Tux!")
Definition: sfx_manager.hpp:107
bool soundExist(const std::string &name)
Returns true if a sfx with the given name exists.
Definition: sfx_manager.cpp:776
std::thread m_thread
Thread id of the thread running in this object.
Definition: sfx_manager.hpp:220
SFXCommands m_command
The command to execute.
Definition: sfx_manager.hpp:132
SFXCommand(SFXCommands command, MusicInformation *mi)
Constructor for music information commands.
Definition: sfx_manager.hpp:144
void pauseAll()
Pauses all looping SFXs.
Definition: sfx_manager.cpp:906
void reallyPositionListenerNow()
Sets the position and orientation of the listener.
Definition: sfx_manager.cpp:1060
SFXManager()
Initialises the SFX manager and loads the sfx from a config file.
Definition: sfx_manager.cpp:77
The buffer (data) for one kind of sound effects.
Definition: sfx_buffer.hpp:43
Synchronised< std::vector< SFXCommand * > > m_sfx_commands
The list of sound effects to be played in the next update.
Definition: sfx_manager.hpp:206
SFXCommand(SFXCommands command, SFXBase *base, float f, const Vec3 ¶meter)
Store a float and vec3 parameter.
Definition: sfx_manager.hpp:176
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:651
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
Played when something is attached to kart (Uh-Oh)
Definition: sfx_manager.hpp:108
void queueCommand(SFXCommand *command)
Enqueues a command to the sfx queue threadsafe.
Definition: sfx_manager.cpp:286
Played when driving through goo.
Definition: sfx_manager.hpp:104
void update()
Make sure that the sfx thread is started at least once per frame.
Definition: sfx_manager.cpp:808
void positionListener(const Vec3 &position, const Vec3 &front, const Vec3 &up)
Sets the position and orientation of the listener.
Definition: sfx_manager.cpp:1044
float m_master_gain
Master gain value, taken from the user config value.
Definition: sfx_manager.hpp:216
Vec3 m_listener_front
The direction the listener is facing.
Definition: sfx_manager.hpp:192
CustomSFX
Entries for custom SFX sounds.
Definition: sfx_manager.hpp:98
Played when passing another kart.
Definition: sfx_manager.hpp:105
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:1095
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:698
Manager of all sound effects.
Definition: sfx_manager.hpp:54
std::condition_variable m_condition_variable
A conditional variable to wake up the main loop.
Definition: sfx_manager.hpp:226
static SFXManager * m_sfx_manager
Singleton pointer.
Definition: sfx_manager.hpp:58
Played when kart hits zipper.
Definition: sfx_manager.hpp:106
TYPE & getData()
Returns a reference to the original data file.
Definition: synchronised.hpp:82
void deleteSFX(SFXBase *sfx)
Delete a sound effect object, and removes it from the internal list of all SFXs.
Definition: sfx_manager.cpp:876
bool m_initialized
If the sfx manager has been initialised.
Definition: sfx_manager.hpp:213
SFXBuffer * m_buffer
The sound buffer to play (null = no change)
Definition: sfx_manager.hpp:126
void reallyUpdateNow(SFXCommand *current)
Updates the status of all playing sfx (to test if they are finished).
Definition: sfx_manager.cpp:829
static void mainLoop(void *obj)
This loops runs in a different threads, and starts sfx to be played.
Definition: sfx_manager.cpp:344
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:25
Vec3 m_listener_up
Up vector of the listener.
Definition: sfx_manager.hpp:195
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 reallyPauseAllNow()
Pauses all looping SFXs.
Definition: sfx_manager.cpp:917
static void create()
Static function to create the singleton sfx manager.
Definition: sfx_manager.cpp:59
void loadSfx()
Loads all sounds specified in the sound config file.
Definition: sfx_manager.cpp:557
void resumeAll()
Resumes all paused SFXs.
Definition: sfx_manager.cpp:931
Synchronised< std::vector< SFXBase * > > m_all_sfx
The actual instances (sound sources)
Definition: sfx_manager.hpp:203
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:37
utility class used to parse XML files
Definition: xml_node.hpp:47
Replaces default horn.
Definition: sfx_manager.hpp:100
virtual ~SFXManager()
Destructor, frees all sound effects.
Definition: sfx_manager.cpp:111
Played when struck by bowling ball or dynamite.
Definition: sfx_manager.hpp:103
void stopThread()
Puts a NULL request into the queue, which will trigger the thread to exit.
Definition: sfx_manager.cpp:322
The base class for sound effects.
Definition: sfx_base.hpp:42
void dump()
Prints the list of currently loaded sounds to stdout.
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:786
void reallyResumeAllNow()
Resumes all paused SFXs.
Definition: sfx_manager.cpp:941
Played when weapon is used.
Definition: sfx_manager.hpp:109
Played when colliding with another kart.
Definition: sfx_manager.hpp:101
SFXBase * m_sfx
The sound effect for which the command should be executed.
Definition: sfx_manager.hpp:123
SFXCommands
The various commands to be executed by the sfx manager thread for each sfx.
Definition: sfx_manager.hpp:64
Played when racer wins.
Definition: sfx_manager.hpp:102
Vec3 m_parameter
Optional parameter for commands that need more input.
Definition: sfx_manager.hpp:135