Revision: 2500
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2500&view=rev
Author:   ulteq
Date:     2012-05-05 22:07:39 +0000 (Sat, 05 May 2012)
Log Message:
-----------
-Codechange: Removed deprecated code

Modified Paths:
--------------
    trunk/source/main/audio/Sound.cpp
    trunk/source/main/audio/Sound.h
    trunk/source/main/audio/SoundManager.cpp
    trunk/source/main/audio/SoundManager.h
    trunk/source/main/audio/SoundScriptManager.cpp
    trunk/source/main/audio/SoundScriptManager.h

Modified: trunk/source/main/audio/Sound.cpp
===================================================================
--- trunk/source/main/audio/Sound.cpp   2012-05-04 21:27:12 UTC (rev 2499)
+++ trunk/source/main/audio/Sound.cpp   2012-05-05 22:07:39 UTC (rev 2500)
@@ -17,7 +17,6 @@
 You should have received a copy of the GNU General Public License
 along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
 */
-
 #ifdef USE_OPENAL
 
 #include "Sound.h"
@@ -30,27 +29,27 @@
        , soundManager(soundManager)
        , sourceIndex(sourceIndex)
        , audibility(0.0f)
-       , enabled(true)
        , gain(0.0f)
-       , hardware_index(-1)
-       , loop(false)
        , pitch(1.0f)
        , position(Vector3::ZERO)
-       , should_play(false)
        , velocity(Vector3::ZERO)
+       , enabled(true)
+       , loop(false)
+       , should_play(false)
+       , hardware_index(-1)
 {
 }
 
 void Sound::computeAudibility(Vector3 pos)
 {
-       // Disable sound?
+       // disable sound?
        if (!enabled)
        {
                audibility = 0.0f;
                return;
        }
 
-       // First check if the sound is finished!
+       // first check if the sound is finished!
        if (!loop && should_play && hardware_index != -1)
        {
                int value = 0;
@@ -61,7 +60,7 @@
                }
        }
        
-       // Should it play at all?
+       // should it play at all?
        if (!should_play || gain == 0.0f)
        {
                audibility = 0.0f;

Modified: trunk/source/main/audio/Sound.h
===================================================================
--- trunk/source/main/audio/Sound.h     2012-05-04 21:27:12 UTC (rev 2499)
+++ trunk/source/main/audio/Sound.h     2012-05-05 22:07:39 UTC (rev 2500)
@@ -17,14 +17,12 @@
 You should have received a copy of the GNU General Public License
 along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
 */
-
-#pragma once
-
 #ifdef USE_OPENAL
 #ifndef __Sound_H_
 #define __Sound_H_
 
 #include "RoRPrerequisites.h"
+
 #include <AL/al.h>
 
 class Sound
@@ -58,7 +56,7 @@
        bool enabled;
        bool should_play;
 
-       // This value is changed dynamically, depending on whether the input is 
played or not.
+       // this value is changed dynamically, depending on whether the input is 
played or not.
        int hardware_index;
        ALuint buffer;
        
@@ -66,7 +64,7 @@
        Ogre::Vector3 velocity;
 
        SoundManager* soundManager;
-       // Must not be changed during the lifetime of this object
+       // must not be changed during the lifetime of this object
        int sourceIndex;
 };
 

Modified: trunk/source/main/audio/SoundManager.cpp
===================================================================
--- trunk/source/main/audio/SoundManager.cpp    2012-05-04 21:27:12 UTC (rev 
2499)
+++ trunk/source/main/audio/SoundManager.cpp    2012-05-05 22:07:39 UTC (rev 
2500)
@@ -17,7 +17,6 @@
 You should have received a copy of the GNU General Public License
 along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
 */
-
 #ifdef USE_OPENAL
 
 #include "Sound.h"
@@ -36,81 +35,73 @@
 const float SoundManager::REFERENCE_DISTANCE = 7.5f;
 
 SoundManager::SoundManager() :
-         m_sound_device(NULL)
-       , m_sound_context(NULL)
+         m_audio_buffers_in_use_count(0)
        , m_audio_sources_in_use_count(0)
-       , m_audio_buffers_in_use_count(0)
-       , m_hardware_sources_num(0)
        , m_hardware_sources_in_use_count(0)
-       , master_volume(1.0f)
+       , m_hardware_sources_num(0)
+       , m_sound_context(NULL)
+       , m_sound_device(NULL)
 {
-       String soundRenderer = SSETTING("3D Sound renderer", "Default");
-       if (soundRenderer == "No sound") return;
+       String sound_renderer = SSETTING("3D Sound renderer", "Default");
+       master_volume = FSETTING("Sound Volume", 100.0f) / 100.0f;
 
-       char str[256] = {};
-       if (soundRenderer != "Default")
+       if (sound_renderer == "No sound") return;
+
+       for (int i=0; i < MAX_HARDWARE_SOURCES; i++)
        {
-               sprintf(str, "DirectSound Software on %s", 
soundRenderer.c_str());
+               m_hardware_sources_map[i] = -1;
        }
 
-       LOG("Opening Device: '"+String(str)+"'");
+       LOG("Opening Device: 'Default'");
 
-       master_volume = FSETTING("Sound Volume", 100.0f) / 100.0f;
-
-       for (int i=0; i<MAX_HARDWARE_SOURCES; i++) m_hardware_sources_map[i]=-1;
-
-       // We loop alcOpenDevice() because there is a potential race condition 
with the asynchronous DSound enumeration callback
-       for (int i=0; i<100; i++)
+       // we loop alcOpenDevice() because there is a potential race condition 
with the asynchronous DSound enumeration callback
+       for (int i=0; i < 100  && !m_sound_device; i++)
        {
-               m_sound_device=alcOpenDevice(str);
-               if (m_sound_device)
-                       break;
-               else
-               {
-                       ALint error=alGetError();
-                       if (error != ALC_INVALID_VALUE) {LOG("Could not create 
OpenAL device, error code: "+TOSTRING(error));return;}
-               }
+               m_sound_device = alcOpenDevice(NULL); // TODO: Find a proper 
way to open a non default device
        }
+
        if (!m_sound_device)
        {
-               // Last ditch attempt with the default sound device, in case 
the user has a messed-up config file
-               m_sound_device=alcOpenDevice("");
-               if (!m_sound_device) {LOG("Could not create OpenAL device after 
many tries.");return;}
-               else LOG("Warning: invalid sound device configuration, I will 
use the default sound source. Run configurator!");
+               ALint error = alGetError();
+               LOG("SoundManager: Could not create OpenAL device, error code: 
"+TOSTRING(error));
+               return;
        }
-       m_sound_context=alcCreateContext(m_sound_device, NULL);
+
+       m_sound_context = alcCreateContext(m_sound_device, NULL);
+
        if (!m_sound_context)
        {
-               ALint error;
-               error=alGetError();
-               LOG("Could not create OpenAL context, error code: 
"+TOSTRING(error));
+               ALint error= alGetError();
+               LOG("SoundManager: Could not create OpenAL context, error code: 
" + TOSTRING(error));
                alcCloseDevice(m_sound_device);
-               m_sound_device=NULL;
+               m_sound_device = NULL;
                return;
        }
+
        alcMakeContextCurrent(m_sound_context);
-       // Generate the AL sources
-       for (m_hardware_sources_num=0; 
m_hardware_sources_num<MAX_HARDWARE_SOURCES; m_hardware_sources_num++)
+
+       // generate the AL sources
+       for (m_hardware_sources_num=0; m_hardware_sources_num < 
MAX_HARDWARE_SOURCES; m_hardware_sources_num++)
        {
                alGetError();
                alGenSources(1, &m_hardware_sources[m_hardware_sources_num]);
-               if (alGetError() != AL_NO_ERROR)
-                       break;
+               if (alGetError() != AL_NO_ERROR) break;
                alSourcef(m_hardware_sources[m_hardware_sources_num], 
AL_REFERENCE_DISTANCE, REFERENCE_DISTANCE);
                alSourcef(m_hardware_sources[m_hardware_sources_num], 
AL_ROLLOFF_FACTOR, ROLLOFF_FACTOR);
                alSourcef(m_hardware_sources[m_hardware_sources_num], 
AL_MAX_DISTANCE, MAX_DISTANCE);
        }
+
        alDopplerFactor(1.0f);
        alDopplerVelocity(343.0f);
 }
 
 SoundManager::~SoundManager()
 {
-       // Delete the sources and buffers
+       // delete the sources and buffers
        alDeleteSources(MAX_HARDWARE_SOURCES, m_hardware_sources);
     alDeleteBuffers(MAX_AUDIO_BUFFERS, m_audio_buffers);
 
-       // Destroy the sound context and device
+       // destroy the sound context and device
     m_sound_context = alcGetCurrentContext();
     m_sound_device  = alcGetContextsDevice(m_sound_context);
     alcMakeContextCurrent(NULL);
@@ -129,11 +120,11 @@
        recomputeAllSources();
        
        float orientation[6];
-       //dir
+       // direction
        orientation[0] = direction.x;
        orientation[1] = direction.y;
        orientation[2] = direction.z;
-       //up
+       // up
        orientation[3] = up.x;
        orientation[4] = up.y;
        orientation[5] = up.z;
@@ -144,40 +135,39 @@
 }
 
 bool compareByAudibility(std::pair<int, float> a, std::pair<int, float> b)
-{              
+{
        return a.second > b.second;
 }
 
-// Called when the camera moves
+// called when the camera moves
 void SoundManager::recomputeAllSources()
 {
-       
        if (!m_sound_device) return;
-       // Mutex is supposed to be already taken
-       for (int i=0; i<m_audio_sources_in_use_count; i++)
+
+       for (int i=0; i < m_audio_sources_in_use_count; i++)
        {
                m_audio_sources[i]->computeAudibility(camera_position);
                m_audio_sources_most_audible[i].first = i;
                m_audio_sources_most_audible[i].second = 
m_audio_sources[i]->audibility;
        }
-       // Sort first 'num_hardware_sources' sources by audibility
-       // See: https://en.wikipedia.org/wiki/Selection_algorithm
-       if ((m_audio_sources_in_use_count-1) > m_hardware_sources_num)
+       // sort first 'num_hardware_sources' sources by audibility
+       // see: https://en.wikipedia.org/wiki/Selection_algorithm
+       if ((m_audio_sources_in_use_count - 1) > m_hardware_sources_num)
        {
                std::nth_element(m_audio_sources_most_audible, 
m_audio_sources_most_audible+m_hardware_sources_num, 
m_audio_sources_most_audible+m_audio_sources_in_use_count-1, 
compareByAudibility);
        }
-       // Retire out of range sources first
-       for (int i=0; i<m_audio_sources_in_use_count; i++)
+       // retire out of range sources first
+       for (int i=0; i < m_audio_sources_in_use_count; i++)
        {
                if 
(m_audio_sources[m_audio_sources_most_audible[i].first]->hardware_index != -1 
&& (i >= m_hardware_sources_num || m_audio_sources_most_audible[i].second == 0))
                        retire(m_audio_sources_most_audible[i].first);
        }
-       // Assign new sources
-       for (int i=0; i<std::min(m_audio_sources_in_use_count, 
m_hardware_sources_num); i++)
+       // assign new sources
+       for (int i=0; i < std::min(m_audio_sources_in_use_count, 
m_hardware_sources_num); i++)
        {
                if 
(m_audio_sources[m_audio_sources_most_audible[i].first]->hardware_index == -1 
&& m_audio_sources_most_audible[i].second > 0)
                {
-                       for (int j=0; j<m_hardware_sources_num; j++)
+                       for (int j=0; j < m_hardware_sources_num; j++)
                        {
                                if (m_hardware_sources_map[j] == -1)
                                {
@@ -192,70 +182,69 @@
 void SoundManager::recomputeSource(int source_index, int reason, float vfl, 
Vector3 *vvec)
 {
        if (!m_sound_device) return;
-
        m_audio_sources[source_index]->computeAudibility(camera_position);
 
        if (m_audio_sources[source_index]->audibility == 0.0f)
        {
                if (m_audio_sources[source_index]->hardware_index != -1)
                {
-                       // Retire the source if it is currently assigned
+                       // retire the source if it is currently assigned
                        retire(source_index);
                }
-       }
-       else
+       } else
        {
-               // This is a potentially audible m_audio_sources[source_index]
+               // this is a potentially audible m_audio_sources[source_index]
                if (m_audio_sources[source_index]->hardware_index != -1)
                {
                        // m_audio_sources[source_index] already playing
-                       // Update the AL settings
+                       // update the AL settings
                        switch (reason)
                        {
-                               case Sound::REASON_PLAY: 
alSourcePlay(m_hardware_sources[m_audio_sources[source_index]->hardware_index]);break;
-                               case Sound::REASON_STOP: 
alSourceStop(m_hardware_sources[m_audio_sources[source_index]->hardware_index]);break;
-                               case Sound::REASON_GAIN: 
alSourcef(m_hardware_sources[m_audio_sources[source_index]->hardware_index], 
AL_GAIN, vfl*master_volume);break;
-                               case Sound::REASON_LOOP: 
alSourcei(m_hardware_sources[m_audio_sources[source_index]->hardware_index], 
AL_LOOPING, (vfl>0.5)?AL_TRUE:AL_FALSE);break;
-                               case Sound::REASON_PTCH: 
alSourcef(m_hardware_sources[m_audio_sources[source_index]->hardware_index], 
AL_PITCH, vfl);break;
-                               case Sound::REASON_POSN: 
alSource3f(m_hardware_sources[m_audio_sources[source_index]->hardware_index], 
AL_POSITION, vvec->x,vvec->y,vvec->z);break;
-                               case Sound::REASON_VLCT: 
alSource3f(m_hardware_sources[m_audio_sources[source_index]->hardware_index], 
AL_VELOCITY, vvec->x,vvec->y,vvec->z);break;
+                               case Sound::REASON_PLAY: 
alSourcePlay(m_hardware_sources[m_audio_sources[source_index]->hardware_index]);
 break;
+                               case Sound::REASON_STOP: 
alSourceStop(m_hardware_sources[m_audio_sources[source_index]->hardware_index]);
 break;
+                               case Sound::REASON_GAIN: 
alSourcef(m_hardware_sources[m_audio_sources[source_index]->hardware_index], 
AL_GAIN, vfl * master_volume); break;
+                               case Sound::REASON_LOOP: 
alSourcei(m_hardware_sources[m_audio_sources[source_index]->hardware_index], 
AL_LOOPING, (vfl > 0.5) ? AL_TRUE : AL_FALSE); break;
+                               case Sound::REASON_PTCH: 
alSourcef(m_hardware_sources[m_audio_sources[source_index]->hardware_index], 
AL_PITCH, vfl); break;
+                               case Sound::REASON_POSN: 
alSource3f(m_hardware_sources[m_audio_sources[source_index]->hardware_index], 
AL_POSITION, vvec->x, vvec->y, vvec->z); break;
+                               case Sound::REASON_VLCT: 
alSource3f(m_hardware_sources[m_audio_sources[source_index]->hardware_index], 
AL_VELOCITY, vvec->x, vvec->y, vvec->z); break;
                                default: break;
                        }
                } else
                {
-                       // Try to make it play by the hardware
-                       // Check if there is one free 
m_audio_sources[source_index] in the pool
+                       // try to make it play by the hardware
+                       // check if there is one free 
m_audio_sources[source_index] in the pool
                        if (m_hardware_sources_in_use_count < 
m_hardware_sources_num)
                        {
-                               for (int i=0; i<m_hardware_sources_num; i++)
+                               for (int i=0; i < m_hardware_sources_num; i++)
                                {
                                        if (m_hardware_sources_map[i] == -1)
                                        {
-                                               assign(source_index, i);break;
+                                               assign(source_index, i);
+                                               break;
                                        }
                                }
                        } else
                        {
-                               // Now, compute who is the faintest
-                               // Note: we know the table 
m_hardware_sources_map is full!
+                               // now, compute who is the faintest
+                               // note: we know the table 
m_hardware_sources_map is full!
                                float fv = 1.0f;
                                int al_faintest = 0;
-                               for (int i=0; i<m_hardware_sources_num; i++)
+                               for (int i=0; i < m_hardware_sources_num; i++)
                                {
                                        if (m_hardware_sources_map[i] >= 0 && 
m_audio_sources[m_hardware_sources_map[i]]->audibility < fv)
                                        {
-                                               
fv=m_audio_sources[m_hardware_sources_map[i]]->audibility;
-                                               al_faintest=i;
+                                               fv = 
m_audio_sources[m_hardware_sources_map[i]]->audibility;
+                                               al_faintest = i;
                                        }
                                }
-                               // Find if the the faintest 
m_audio_sources[source_index] is louder or not
+                               // check to ensure that the sound is louder 
than the faintest sound currently playing
                                if (fv < 
m_audio_sources[source_index]->audibility)
                                {
-                                       // This new 
m_audio_sources[source_index] is louder than the faintest!
+                                       // this new 
m_audio_sources[source_index] is louder than the faintest!
                                        
retire(m_hardware_sources_map[al_faintest]);
                                        assign(source_index, al_faintest);
                                }
-                               // Else this m_audio_sources[source_index] is 
too faint, we don't play it!
+                               // else this m_audio_sources[source_index] is 
too faint, we don't play it!
                        }
                }
        }
@@ -264,11 +253,10 @@
 void SoundManager::assign(int source_index, int hardware_index)
 {
        if (!m_sound_device) return;
-
        m_audio_sources[source_index]->hardware_index = hardware_index;
        m_hardware_sources_map[hardware_index] = source_index;
 
-       // The hardware source is supposed to be stopped!
+       // the hardware source is supposed to be stopped!
        alSourcei(m_hardware_sources[hardware_index], AL_BUFFER, 
m_audio_sources[source_index]->buffer);
        alSourcef(m_hardware_sources[hardware_index], AL_GAIN, 
m_audio_sources[source_index]->gain*master_volume);
        alSourcei(m_hardware_sources[hardware_index], AL_LOOPING, 
(m_audio_sources[source_index]->loop)?AL_TRUE:AL_FALSE);
@@ -285,7 +273,6 @@
 void SoundManager::retire(int source_index)
 {
        if (!m_sound_device) return;
-
        if (m_audio_sources[source_index]->hardware_index == -1) return;
        
alSourceStop(m_hardware_sources[m_audio_sources[source_index]->hardware_index]);
        m_hardware_sources_map[m_audio_sources[source_index]->hardware_index] = 
-1;
@@ -296,18 +283,21 @@
 void SoundManager::pauseAllSounds()
 {
        if (!m_sound_device) return;
+       // no mutex needed
        alListenerf(AL_GAIN, 0.0f);
 }
 
 void SoundManager::resumeAllSounds()
 {
        if (!m_sound_device) return;
+       // no mutex needed
        alListenerf(AL_GAIN, master_volume);
 }
 
 void SoundManager::setMasterVolume(float v)
 {
        if (!m_sound_device) return;
+       // no mutex needed
        master_volume = v;
        alListenerf(AL_GAIN, master_volume);
 }
@@ -322,10 +312,10 @@
                return NULL;
        }
 
-       ALuint buffer=0;
+       ALuint buffer = 0;
 
-       // Is the file already loaded?
-       for (int i=0; i<m_audio_buffers_in_use_count; i++)
+       // is the file already loaded?
+       for (int i=0; i < m_audio_buffers_in_use_count; i++)
        {
                if (filename == m_audio_buffer_file_name[i])
                {
@@ -336,13 +326,13 @@
 
        if (!buffer)
        {
-               // Load the file
+               // load the file
                alGenBuffers(1, &m_audio_buffers[m_audio_buffers_in_use_count]);
                if (loadWAVFile(filename, 
m_audio_buffers[m_audio_buffers_in_use_count]))
                {
-                       // There was an error!
+                       // there was an error!
                        alDeleteBuffers(1, 
&m_audio_buffers[m_audio_buffers_in_use_count]);
-                       
m_audio_buffer_file_name[m_audio_buffers_in_use_count]="";
+                       m_audio_buffer_file_name[m_audio_buffers_in_use_count] 
= "";
                        return NULL;
                }
                buffer = m_audio_buffers[m_audio_buffers_in_use_count];
@@ -359,59 +349,59 @@
        if (!m_sound_device) return true;
        LOG("Loading WAV file "+filename);
        
-       // Create the Stream
+       // create the Stream
        ResourceGroupManager *rgm=ResourceGroupManager::getSingletonPtr();
        String group=rgm->findGroupContainingResource(filename);
        DataStreamPtr stream=rgm->openResource(filename, group);
 
-       // Load RIFF/WAVE
+       // load RIFF/WAVE
        char magic[5];
        magic[4]=0;
        unsigned int   lbuf; // uint32_t
        unsigned short sbuf; // uint16_t
 
-       // Check magic
+       // check magic
        if (stream->read(magic, 4) != 4) {LOG("Could not read file 
"+filename);return true;}
        if (String(magic) != String("RIFF")) {LOG("Invalid WAV file (no RIFF): 
"+filename);return true;}
-       // Skip 4 bytes (magic)
+       // skip 4 bytes (magic)
        stream->skip(4);
-       // Check file format
+       // check file format
        if (stream->read(magic, 4) != 4) {LOG("Could not read file 
"+filename);return true;}
        if (String(magic) != String("WAVE")) {LOG("Invalid WAV file (no WAVE): 
"+filename);return true;}
-       // Check 'fmt ' sub chunk (1)
+       // check 'fmt ' sub chunk (1)
        if (stream->read(magic, 4) != 4) {LOG("Could not read file 
"+filename);return true;}
        if (String(magic) != String("fmt ")) {LOG("Invalid WAV file (no fmt): 
"+filename);return true;}
-       // Read (1)'s size
+       // read (1)'s size
        if (stream->read(&lbuf, 4) != 4) {LOG("Could not read file 
"+filename);return true;}
        unsigned long subChunk1Size=lbuf;
        if (subChunk1Size<16) {LOG("Invalid WAV file (invalid subChunk1Size): 
"+filename);return true;}
-       // Check PCM audio format
+       // check PCM audio format
        if (stream->read(&sbuf, 2) != 2) {LOG("Could not read file 
"+filename);return true;}
        unsigned short audioFormat=sbuf;
        if (audioFormat != 1) {LOG("Invalid WAV file (invalid audioformat 
"+TOSTRING(audioFormat)+"): "+filename);return true;}
-       // Read number of channels
+       // read number of channels
        if (stream->read(&sbuf, 2) != 2) {LOG("Could not read file 
"+filename);return true;}
        unsigned short channels=sbuf;
-       // Read frequency (sample rate)
+       // read frequency (sample rate)
        if (stream->read(&lbuf, 4) != 4) {LOG("Could not read file 
"+filename);return true;}
        unsigned long freq=lbuf;
-       // Skip 6 bytes (Byte rate (4), Block align (2))
+       // skip 6 bytes (Byte rate (4), Block align (2))
        stream->skip(6);
-       // Read bits per sample
+       // read bits per sample
        if (stream->read(&sbuf, 2) != 2) {LOG("Could not read file 
"+filename);return true;}
        unsigned short bps=sbuf;
-       // Check 'data' sub chunk (2)
+       // check 'data' sub chunk (2)
        if (stream->read(magic, 4) != 4) {LOG("Could not read file 
"+filename);return true;}
        if (String(magic) != String("data") && String(magic) != String("fact")) 
{LOG("Invalid WAV file (no data/fact): "+filename);return true;}
-       // Fact is an option section we don't need to worry about
+       // fact is an option section we don't need to worry about
        if (String(magic)==String("fact"))
        {
                stream->skip(8);
-               // Now we shoudl hit the data chunk
+               // now we should hit the data chunk
                if (stream->read(magic, 4) != 4) {LOG("Could not read file 
"+filename);return true;}
                if (String(magic) != String("data")) {LOG("Invalid WAV file (no 
data): "+filename);return true;}
        }
-       // The next four bytes are the remaining size of the file
+       // the next four bytes are the remaining size of the file
        if (stream->read(&lbuf, 4) != 4) {LOG("Could not read file 
"+filename);return true;}
        
        unsigned long dataSize=lbuf;
@@ -433,7 +423,7 @@
 
        if (channels != 1) LOG("Invalid WAV file: the file needs to be mono, 
and nothing else. Will try to continue anyways ...");
 
-       //okay, creating buffer
+       // ok, creating buffer
        void* bdata=malloc(dataSize);
        if (!bdata) {LOG("Memory error reading file "+filename);return true;}
        if (stream->read(bdata, dataSize) != dataSize) {LOG("Could not read 
file "+filename);return true;}
@@ -445,7 +435,7 @@
        error=alGetError();
 
        free(bdata);
-       // Stream will be closed by itself
+       // stream will be closed by itself
 
        if (error != AL_NO_ERROR) {LOG("OpenAL error while loading buffer for 
"+filename+" : "+TOSTRING(error));return true;}
 

Modified: trunk/source/main/audio/SoundManager.h
===================================================================
--- trunk/source/main/audio/SoundManager.h      2012-05-04 21:27:12 UTC (rev 
2499)
+++ trunk/source/main/audio/SoundManager.h      2012-05-05 22:07:39 UTC (rev 
2500)
@@ -17,14 +17,12 @@
 You should have received a copy of the GNU General Public License
 along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
 */
-
-#pragma once
-
 #ifdef USE_OPENAL
 #ifndef __SoundManager_H_
 #define __SoundManager_H_
 
 #include "RoRPrerequisites.h"
+
 #include "Ogre.h"
 #include <AL/al.h>
 #include <AL/alc.h>
@@ -64,19 +62,19 @@
 
        bool loadWAVFile(Ogre::String filename, ALuint buffer);
 
-       // Active audio sources (hardware sources)
-       int    m_hardware_sources_num;                       // Total number of 
available hardware sources < MAX_HARDWARE_SOURCES
+       // active audio sources (hardware sources)
+       int    m_hardware_sources_num;                       // total number of 
available hardware sources < MAX_HARDWARE_SOURCES
        int    m_hardware_sources_in_use_count;
-       int    m_hardware_sources_map[MAX_HARDWARE_SOURCES]; // Stores the 
hardware index for each source. -1 = unmapped
-       ALuint m_hardware_sources[MAX_HARDWARE_SOURCES];     // This buffer 
contains valid AL handles up to m_hardware_sources_num
+       int    m_hardware_sources_map[MAX_HARDWARE_SOURCES]; // stores the 
hardware index for each source. -1 = unmapped
+       ALuint m_hardware_sources[MAX_HARDWARE_SOURCES];     // this buffer 
contains valid AL handles up to m_hardware_sources_num
 
-       // Audio sources
+       // audio sources
        int    m_audio_sources_in_use_count;
        Sound* m_audio_sources[MAX_AUDIO_BUFFERS];
-       // Helper for calculating the most audible sources
+       // helper for calculating the most audible sources
        std::pair<int, float> m_audio_sources_most_audible[MAX_AUDIO_BUFFERS];
        
-       // Audio buffers: Array of AL buffers and filenames
+       // audio buffers: Array of AL buffers and filenames
        int          m_audio_buffers_in_use_count;
        ALuint       m_audio_buffers[MAX_AUDIO_BUFFERS];
        Ogre::String m_audio_buffer_file_name[MAX_AUDIO_BUFFERS];

Modified: trunk/source/main/audio/SoundScriptManager.cpp
===================================================================
--- trunk/source/main/audio/SoundScriptManager.cpp      2012-05-04 21:27:12 UTC 
(rev 2499)
+++ trunk/source/main/audio/SoundScriptManager.cpp      2012-05-05 22:07:39 UTC 
(rev 2500)
@@ -17,14 +17,14 @@
 You should have received a copy of the GNU General Public License
 along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
 */
-
 #ifdef USE_OPENAL
 
+#include "SoundScriptManager.h"
+
 #include "Beam.h"
 #include "Settings.h"
 #include "Sound.h"
 #include "SoundManager.h"
-#include "SoundScriptManager.h"
 
 // some gcc fixes
 #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
@@ -70,8 +70,8 @@
        // reset all states
        statemap.clear();
 
-       sm = new SoundManager(); // we can give a device name if we want here
-       LOG("SoundScriptManager: Sound Manager started with 
"+TOSTRING(sm->getNumHardwareSources())+" sources");
+       soundManager = new SoundManager(); // we can give a device name if we 
want here
+       LOG("SoundScriptManager: Sound Manager started with " + 
TOSTRING(soundManager->getNumHardwareSources())+" sources");
        mScriptPatterns.push_back("*.soundscript");
        ResourceGroupManager::getSingleton()._registerScriptLoader(this);
 
@@ -227,9 +227,9 @@
                }
        }
 
-       for (int i=0; i<free_pitches[mod]; i++)
+       for (int i=0; i < free_pitches[mod]; i++)
        {
-               SoundScriptInstance* inst=pitches[mod+i*SS_MAX_MOD];
+               SoundScriptInstance* inst = pitches[mod + i * SS_MAX_MOD];
                if (!inst) continue;
                if (inst->truck == truck && inst->soundLinkType == linkType && 
inst->soundLinkItemId == linkItemID)
                {
@@ -244,7 +244,7 @@
 void SoundScriptManager::setCamera(Vector3 position, Vector3 direction, 
Vector3 up, Vector3 velocity)
 {
        if (soundsDisabled) return;
-       sm->setCamera(position, direction, up, velocity);
+       soundManager->setCamera(position, direction, up, velocity);
 }
 
 const StringVector& SoundScriptManager::getScriptPatterns(void) const
@@ -279,8 +279,6 @@
        {
                if (it->second && it->second->groupname == groupname)
                {
-                       delete(it->second);
-                       it->second = 0;
                        templates.erase(it++);
                } else
                {
@@ -338,7 +336,7 @@
                return NULL; // reached limit!
        }
 
-       SoundScriptInstance* inst = new SoundScriptInstance(truck, templ, sm, 
templ->filename+"-"+TOSTRING(truck)+"-"+TOSTRING(instance_counter), 
soundLinkType, soundLinkItemId);
+       SoundScriptInstance* inst = new SoundScriptInstance(truck, templ, 
soundManager, 
templ->filename+"-"+TOSTRING(truck)+"-"+TOSTRING(instance_counter), 
soundLinkType, soundLinkItemId);
        instance_counter++;
 
        // register to lookup tables
@@ -441,9 +439,9 @@
 void SoundScriptManager::soundEnable(bool state)
 {
        if (state)
-               sm->resumeAllSounds();
+               soundManager->resumeAllSounds();
        else
-               sm->pauseAllSounds();
+               soundManager->pauseAllSounds();
 }
 
 //=====================================================================

Modified: trunk/source/main/audio/SoundScriptManager.h
===================================================================
--- trunk/source/main/audio/SoundScriptManager.h        2012-05-04 21:27:12 UTC 
(rev 2499)
+++ trunk/source/main/audio/SoundScriptManager.h        2012-05-05 22:07:39 UTC 
(rev 2500)
@@ -17,13 +17,12 @@
 You should have received a copy of the GNU General Public License
 along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
 */
-
 #ifdef USE_OPENAL
-
 #ifndef __SoundScriptManager_H_
 #define __SoundScriptManager_H_
 
 #include "RoRPrerequisites.h"
+
 #include "BeamData.h" // for MAX_TRUCKS
 #include "OgreScriptLoader.h"
 #include "Singleton.h"
@@ -304,9 +303,8 @@
        // soundLinks, soundItems, trucks, triggers
        std::map <int, std::map <int, std::map <int, std::map <int, bool > > > 
> statemap;
 
-       SoundManager* sm;
+       SoundManager* soundManager;
 };
 
 #endif // __SoundScriptManager_H_
-
 #endif // USE_OPENAL

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Rigsofrods-devel mailing list
Rigsofrods-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to