From 3f3d3b2c6f177260a90117ca497046cd72ff8c20 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 14 May 2004 15:51:43 +0000 Subject: [PATCH] Better support for pausing/unpausing sound. Add support for controlling global volume of FlightGear. --- src/Sound/fg_fx.cxx | 29 +++++++++++++++++++++++++---- src/Sound/fg_fx.hxx | 3 +++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index 6b1a16eb3..4db24d88e 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -39,7 +39,9 @@ #include "fg_fx.hxx" -FGFX::FGFX () +FGFX::FGFX () : + last_pause( true ), + last_volume( 0.0 ) { } @@ -51,7 +53,7 @@ FGFX::~FGFX () void FGFX::init() { - SGPropertyNode * node = fgGetNode("/sim/sound", true); + SGPropertyNode *node = fgGetNode("/sim/sound", true); int i; string path_str = node->getStringValue("path"); @@ -105,9 +107,28 @@ FGFX::unbind () void FGFX::update (double dt) { - if (fgGetBool("/sim/sound/audible")) { - for (unsigned int i = 0; i < _sound.size(); i++ ) + // command sound manger + bool pause = fgGetBool("/sim/sound/pause"); + if ( pause != last_pause ) { + if ( pause ) { + globals->get_soundmgr()->pause(); + } else { + globals->get_soundmgr()->resume(); + } + last_pause = pause; + } + + double volume = fgGetDouble("/sim/sound/volume"); + if ( volume != last_volume ) { + globals->get_soundmgr()->set_volume( volume ); + last_volume = volume; + } + + if ( !pause ) { + // update sound effects if not paused + for ( unsigned int i = 0; i < _sound.size(); i++ ) { _sound[i]->update(dt); + } } } diff --git a/src/Sound/fg_fx.hxx b/src/Sound/fg_fx.hxx index 5c43db42d..a5ad0a85b 100644 --- a/src/Sound/fg_fx.hxx +++ b/src/Sound/fg_fx.hxx @@ -53,6 +53,9 @@ private: vector _sound; + bool last_pause; + double last_volume; + };