]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/sample_group.cxx
Add Update the World Magnetic Model to 2015.0
[simgear.git] / simgear / sound / sample_group.cxx
index 33cf2bce4541e13d8caa61deb8fc57aee8948818..70df9aa1b6cbe88ff33e466ec71849ecc37157a3 100644 (file)
@@ -33,7 +33,9 @@
 #include "soundmgr_openal_private.hxx"
 #include "sample_group.hxx"
 
-using std::string;
+#ifdef HAVE_STD_ISNAN
+using std::isnan;
+#endif
 
 bool isNaN(float *v) {
    return (isnan(v[0]) || isnan(v[1]) || isnan(v[2]));
@@ -53,7 +55,8 @@ SGSampleGroup::SGSampleGroup () :
     _samples.clear();
 }
 
-SGSampleGroup::SGSampleGroup ( SGSoundMgr *smgr, const string &refname ) :
+SGSampleGroup::SGSampleGroup ( SGSoundMgr *smgr,
+                               const std::string &refname ):
     _smgr(smgr),
     _refname(refname),
     _active(false), 
@@ -223,8 +226,9 @@ void SGSampleGroup::update( double dt ) {
 }
 
 // add a sound effect, return true if successful
-bool SGSampleGroup::add( SGSharedPtr<SGSoundSample> sound, const string& refname ) {
-
+bool SGSampleGroup::add( SGSharedPtr<SGSoundSample> sound,
+                         const std::string& refname )
+{
     sample_map_iterator sample_it = _samples.find( refname );
     if ( sample_it != _samples.end() ) {
         // sample name already exists
@@ -237,7 +241,7 @@ bool SGSampleGroup::add( SGSharedPtr<SGSoundSample> sound, const string& refname
 
 
 // remove a sound effect, return true if successful
-bool SGSampleGroup::remove( const string &refname ) {
+bool SGSampleGroup::remove( const std::string &refname ) {
 
     sample_map_iterator sample_it = _samples.find( refname );
     if ( sample_it == _samples.end() ) {
@@ -255,7 +259,7 @@ bool SGSampleGroup::remove( const string &refname ) {
 
 
 // return true of the specified sound exists in the sound manager system
-bool SGSampleGroup::exists( const string &refname ) {
+bool SGSampleGroup::exists( const std::string &refname ) {
     sample_map_iterator sample_it = _samples.find( refname );
     if ( sample_it == _samples.end() ) {
         // sample was not found
@@ -268,7 +272,7 @@ bool SGSampleGroup::exists( const string &refname ) {
 
 // return a pointer to the SGSoundSample if the specified sound exists
 // in the sound manager system, otherwise return NULL
-SGSoundSample *SGSampleGroup::find( const string &refname ) {
+SGSoundSample *SGSampleGroup::find( const std::string &refname ) {
     sample_map_iterator sample_it = _samples.find( refname );
     if ( sample_it == _samples.end() ) {
         // sample was not found
@@ -349,7 +353,9 @@ SGSampleGroup::resume ()
 
 
 // tell the scheduler to play the indexed sample in a continuous loop
-bool SGSampleGroup::play( const string &refname, bool looping = false ) {
+bool SGSampleGroup::play( const std::string &refname,
+                          bool looping )
+{
     SGSoundSample *sample = find( refname );
 
     if ( sample == NULL ) {
@@ -362,7 +368,7 @@ bool SGSampleGroup::play( const string &refname, bool looping = false ) {
 
 
 // return true of the specified sound is currently being played
-bool SGSampleGroup::is_playing( const string& refname ) {
+bool SGSampleGroup::is_playing( const std::string& refname ) {
     SGSoundSample *sample = find( refname );
 
     if ( sample == NULL ) {
@@ -373,7 +379,7 @@ bool SGSampleGroup::is_playing( const string& refname ) {
 }
 
 // immediate stop playing the sound
-bool SGSampleGroup::stop( const string& refname ) {
+bool SGSampleGroup::stop( const std::string& refname ) {
     SGSoundSample *sample  = find( refname );
 
     if ( sample == NULL ) {
@@ -395,8 +401,9 @@ void SGSampleGroup::set_volume( float vol )
 
 // set the source position and orientation of all managed sounds
 void SGSampleGroup::update_pos_and_orientation() {
-    SGVec3d position = SGVec3d::fromGeod(_base_pos) - _smgr->get_position();
+
+    SGVec3d base_position = SGVec3d::fromGeod(_base_pos);
+    SGVec3d smgr_position = _smgr->get_position();
     SGQuatd hlOr = SGQuatd::fromLonLat(_base_pos);
     SGQuatd ec2body = hlOr*_orientation;
 
@@ -412,12 +419,14 @@ void SGSampleGroup::update_pos_and_orientation() {
         sample->set_master_volume( _volume );
         sample->set_orientation( _orientation );
         sample->set_rotation( ec2body );
-        sample->set_position( position );
+        sample->set_position(base_position);
         sample->set_velocity( velocity );
 
         // Test if a sample is farther away than max distance, if so
         // stop the sound playback and free it's source.
         if (!_tied_to_listener) {
+            sample->update_pos_and_orientation();
+            SGVec3d position = sample->get_position() - smgr_position;
             float max2 = sample->get_max_dist() * sample->get_max_dist();
             float dist2 = position[0]*position[0]
                           + position[1]*position[1] + position[2]*position[2];
@@ -443,7 +452,7 @@ void SGSampleGroup::update_sample_config( SGSoundSample *sample )
     } else {
         sample->update_pos_and_orientation();
         orientation = sample->get_orientation();
-        position = sample->get_position();
+        position = sample->get_position() - _smgr->get_position();
         velocity = sample->get_velocity();
     }
 
@@ -484,7 +493,7 @@ void SGSampleGroup::update_sample_config( SGSoundSample *sample )
 #endif
 }
 
-bool SGSampleGroup::testForError(void *p, string s)
+bool SGSampleGroup::testForError(void *p, std::string s)
 {
    if (p == NULL) {
       SG_LOG( SG_SOUND, SG_ALERT, "Error (sample group): " << s);
@@ -493,7 +502,7 @@ bool SGSampleGroup::testForError(void *p, string s)
    return false;
 }
 
-bool SGSampleGroup::testForALError(string s)
+bool SGSampleGroup::testForALError(std::string s)
 {
 #ifdef SG_C
     ALenum error = alGetError();