Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Sound/threaded_sound_wrapper.h')
-rw-r--r--Source/Sound/threaded_sound_wrapper.h151
1 files changed, 74 insertions, 77 deletions
diff --git a/Source/Sound/threaded_sound_wrapper.h b/Source/Sound/threaded_sound_wrapper.h
index d8ee5b8b..f33437dd 100644
--- a/Source/Sound/threaded_sound_wrapper.h
+++ b/Source/Sound/threaded_sound_wrapper.h
@@ -3,7 +3,7 @@
// Developer: Wolfire Games LLC
// Author: Max Danielsson
// Description: Wrapper around the entire sound system, allowing all sound to be run
-// in a separate thread. This is done using a message queue structure and a
+// in a separate thread. This is done using a message queue structure and a
// synchronized data structure for immediate reads.
// License: Read below
//-----------------------------------------------------------------------------
@@ -37,17 +37,14 @@
#include <mutex>
#include <chrono>
-
typedef unsigned long wrapper_sound_handle;
typedef unsigned long real_sound_handle;
class ThreadedSoundMessage {
-
-public:
+ public:
static const unsigned char LOCAL_DATA_SIZE = 64;
- enum Type
- {
+ enum Type {
None,
Initialize,
Dispose,
@@ -84,54 +81,55 @@ public:
InRCreateHandle
};
-private:
+ private:
Type type;
unsigned char local_data[LOCAL_DATA_SIZE];
void Free();
- void *data;
+ void* data;
size_t datalen;
bool has_handle;
wrapper_sound_handle wsh;
bool string_data;
-public:
+
+ public:
void Allocate(size_t size);
ThreadedSoundMessage();
- ThreadedSoundMessage( Type t );
+ ThreadedSoundMessage(Type t);
~ThreadedSoundMessage();
- ThreadedSoundMessage( const ThreadedSoundMessage& tsm );
+ ThreadedSoundMessage(const ThreadedSoundMessage& tsm);
ThreadedSoundMessage& operator=(const ThreadedSoundMessage& tsm);
Type GetType();
- void SetHandle( wrapper_sound_handle _wsh );
+ void SetHandle(wrapper_sound_handle _wsh);
wrapper_sound_handle GetWrapperHandle();
real_sound_handle GetRealHandle();
- //Different ways of storing data in same memory chunk.
- void SetData( const void* mem_ptr, size_t data_len );
- void SetData( const void* mem_ptr, size_t offset, size_t data_len );
- void GetData( void* mem_ptr, size_t max_len );
- void GetData( void* mem_ptr, size_t offset, size_t data_len );
+ // Different ways of storing data in same memory chunk.
+ void SetData(const void* mem_ptr, size_t data_len);
+ void SetData(const void* mem_ptr, size_t offset, size_t data_len);
+ void GetData(void* mem_ptr, size_t max_len);
+ void GetData(void* mem_ptr, size_t offset, size_t data_len);
- void SetStringData( const std::string &str );
- std::string GetStringData( );
+ void SetStringData(const std::string& str);
+ std::string GetStringData();
};
class ThreadedSoundMessageQueue {
std::queue<ThreadedSoundMessage> messages;
std::mutex mutex;
-public:
- void Queue( const ThreadedSoundMessage &ev );
- ThreadedSoundMessage Pop( );
- size_t Count( );
+ public:
+ void Queue(const ThreadedSoundMessage& ev);
+ ThreadedSoundMessage Pop();
+ size_t Count();
};
struct SoundSourceInfo {
@@ -149,11 +147,11 @@ struct SoundDataCopy {
std::vector<AmbientTriangle> ambient_triangles;
- std::map<std::string,float> current_layer_gains;
+ std::map<std::string, float> current_layer_gains;
std::vector<std::string> current_layer_names;
std::vector<SoundSourceInfo> sound_source;
-};
+};
struct SoundInstanceDataCopy {
static const int ID_SIZE = 8;
@@ -169,45 +167,45 @@ struct SoundInstanceDataCopy {
* Class containing data that is used for copies, reads and mapping internal to external handles.
*/
class ThreadedSoundDataBridge {
-
-private:
+ private:
std::mutex mutex;
wrapper_sound_handle handle_counter;
- std::map<wrapper_sound_handle,real_sound_handle> handle_map;
- std::map<wrapper_sound_handle,SoundInstanceDataCopy> data_copy_map;
+ std::map<wrapper_sound_handle, real_sound_handle> handle_map;
+ std::map<wrapper_sound_handle, SoundInstanceDataCopy> data_copy_map;
SoundDataCopy sound_data;
std::vector<std::string> available_devices;
std::string preferred_device;
std::string used_device;
-public:
+
+ public:
ThreadedSoundDataBridge();
wrapper_sound_handle CreateWrapperHandle();
- void SetHandle( wrapper_sound_handle wsh, real_sound_handle rsh );
- void SetIdentifier( wrapper_sound_handle wsh, const char* id );
- void SetValues( wrapper_sound_handle wsh, const char* name, const char* type );
- void SetPosition( wrapper_sound_handle wsh, const vec3& position );
+ void SetHandle(wrapper_sound_handle wsh, real_sound_handle rsh);
+ void SetIdentifier(wrapper_sound_handle wsh, const char* id);
+ void SetValues(wrapper_sound_handle wsh, const char* name, const char* type);
+ void SetPosition(wrapper_sound_handle wsh, const vec3& position);
- void RemoveHandle( wrapper_sound_handle wsh );
- real_sound_handle GetHandle( wrapper_sound_handle wsh );
- bool IsHandleValid( wrapper_sound_handle wsh );
+ void RemoveHandle(wrapper_sound_handle wsh);
+ real_sound_handle GetHandle(wrapper_sound_handle wsh);
+ bool IsHandleValid(wrapper_sound_handle wsh);
- std::map<wrapper_sound_handle,real_sound_handle> GetAllHandles();
- SoundInstanceDataCopy GetHandleData( wrapper_sound_handle wsh );
- //void SetHandleData( wrapper_sound_handle wsh, const SoundInstanceDataCopy &sidc );
+ std::map<wrapper_sound_handle, real_sound_handle> GetAllHandles();
+ SoundInstanceDataCopy GetHandleData(wrapper_sound_handle wsh);
+ // void SetHandleData( wrapper_sound_handle wsh, const SoundInstanceDataCopy &sidc );
SoundDataCopy GetData();
size_t GetSoundHandleCount();
size_t GetSoundInstanceCount();
- void SetData( const SoundDataCopy& dat );
+ void SetData(const SoundDataCopy& dat);
void SetPreferredDevice(const std::string& name);
std::string GetPreferredDevice();
-
+
void SetUsedDevice(const std::string& name);
std::string GetUsedDevice();
@@ -216,21 +214,20 @@ public:
};
class ThreadedSound {
-private:
-
+ private:
std::thread thread;
bool initialized;
-public:
+ public:
ThreadedSound();
~ThreadedSound();
void Initialize(const char* preferred_device);
- //Following is a copy of the Sound interface
+ // Following is a copy of the Sound interface
void Update();
- void UpdateGameTimestep( float timestep );
- void UpdateGameTimescale( float time_scale );
+ void UpdateGameTimestep(float timestep);
+ void UpdateGameTimescale(float time_scale);
void setAirWhoosh(float amount, float pitch = 1.0f);
@@ -238,20 +235,20 @@ public:
unsigned long CreateHandle(const char* ident);
- void Play(const unsigned long &handle, SoundPlayInfo spi);
-
- void PlayGroup(const unsigned long &handle, const SoundGroupPlayInfo& sgpi);
- const vec3 GetPosition(const unsigned long &handle);
+ void Play(const unsigned long& handle, SoundPlayInfo spi);
+
+ void PlayGroup(const unsigned long& handle, const SoundGroupPlayInfo& sgpi);
+ const vec3 GetPosition(const unsigned long& handle);
const std::string GetName(const unsigned long& handle);
const std::string GetType(const unsigned long& handle);
const std::string GetID(const unsigned long& handle);
- void SetPosition(const unsigned long &handle, const vec3 &new_pos);
- void TranslatePosition(const unsigned long& handle, const vec3 &movement);
- void SetVelocity(const unsigned long &handle, const vec3 &new_vel);
- void SetPitch(const unsigned long &handle, float pitch);
- void SetVolume(const unsigned long &handle, float volume);
- void Stop(const unsigned long &handle);
- bool IsHandleValid(const unsigned long &handle);
+ void SetPosition(const unsigned long& handle, const vec3& new_pos);
+ void TranslatePosition(const unsigned long& handle, const vec3& movement);
+ void SetVelocity(const unsigned long& handle, const vec3& new_vel);
+ void SetPitch(const unsigned long& handle, float pitch);
+ void SetVolume(const unsigned long& handle, float volume);
+ void Stop(const unsigned long& handle);
+ bool IsHandleValid(const unsigned long& handle);
void AddMusic(const Path& path);
void RemoveMusic(const Path& path);
@@ -265,41 +262,41 @@ public:
void SetSong(const std::string& string);
const std::string GetSegment() const;
- const std::map<std::string,float> GetLayerGains() const;
+ const std::map<std::string, float> GetLayerGains() const;
const std::vector<std::string> GetLayerNames() const;
- const float GetLayerGain( const std::string& layer ) const;
+ const float GetLayerGain(const std::string& layer) const;
const std::string GetSongName() const;
const std::string GetSongType() const;
const std::string GetNextSongName() const;
const std::string GetNextSongType() const;
- void AddAmbientTriangle(const std::string &path);
+ void AddAmbientTriangle(const std::string& path);
std::vector<AmbientTriangle> GetAmbientTriangles();
void Clear();
- //Clear all sounds that are considered transient (that is sound effects in a level and not music)
- //This is called when a level is unloaded, or loaded. Basically between major state changes.
+ // Clear all sounds that are considered transient (that is sound effects in a level and not music)
+ // This is called when a level is unloaded, or loaded. Basically between major state changes.
void ClearTransient();
- //std::vector<AudioEmitter*> GetActiveSounds();
- //alAudio &getAlAudio();
- //void changeSoundtrack(char *name, char *type)
+ // std::vector<AudioEmitter*> GetActiveSounds();
+ // alAudio &getAlAudio();
+ // void changeSoundtrack(char *name, char *type)
void Dispose();
- void SetMusicVolume( float val );
- void SetMasterVolume( float val );
-
- //void UpdateSoundOcclusion( );
- //void SetSoundOcclusionState( int id, bool occluded );
- void SetOcclusionPosition( const unsigned long &handle, const vec3 &new_pos );
- void LoadSoundFile( const std::string & path );
- //End of Sound interface.
-
+ void SetMusicVolume(float val);
+ void SetMasterVolume(float val);
+
+ // void UpdateSoundOcclusion( );
+ // void SetSoundOcclusionState( int id, bool occluded );
+ void SetOcclusionPosition(const unsigned long& handle, const vec3& new_pos);
+ void LoadSoundFile(const std::string& path);
+ // End of Sound interface.
+
std::vector<SoundSourceInfo> GetCurrentSoundSources();
size_t GetSoundHandleCount();
size_t GetSoundInstanceCount();
- std::map<wrapper_sound_handle,real_sound_handle> GetAllHandles();
+ std::map<wrapper_sound_handle, real_sound_handle> GetAllHandles();
std::string GetPreferredDevice();
std::string GetUsedDevice();