add avionics enable/disable and volume control to the sound fx class.
This commit is contained in:
parent
e657a53b32
commit
c7ef67df80
3 changed files with 17 additions and 24 deletions
|
@ -1260,7 +1260,7 @@ do_play_audio_sample (const SGPropertyNode * arg)
|
||||||
static FGSampleQueue *queue = 0;
|
static FGSampleQueue *queue = 0;
|
||||||
if ( !queue ) {
|
if ( !queue ) {
|
||||||
SGSoundMgr *smgr = globals->get_soundmgr();
|
SGSoundMgr *smgr = globals->get_soundmgr();
|
||||||
queue = new FGSampleQueue(smgr, "queue");
|
queue = new FGSampleQueue(smgr, "chatter");
|
||||||
queue->tie_to_listener();
|
queue->tie_to_listener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,18 +39,16 @@
|
||||||
#include <simgear/sound/xmlsound.hxx>
|
#include <simgear/sound/xmlsound.hxx>
|
||||||
|
|
||||||
FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) :
|
FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) :
|
||||||
last_enabled( true ),
|
|
||||||
last_volume( 0.0 ),
|
|
||||||
_enabled( fgGetNode("/sim/sound/effects/enabled", true) ),
|
_enabled( fgGetNode("/sim/sound/effects/enabled", true) ),
|
||||||
_volume( fgGetNode("/sim/sound/effects/volume", true) )
|
_volume( fgGetNode("/sim/sound/effects/volume", true) ),
|
||||||
|
_avionics_enabled( fgGetNode("/sim/sound/avionics/enabled", true) ),
|
||||||
|
_avionics_volume( fgGetNode("/sim/sound/avionics/volume", true) )
|
||||||
{
|
{
|
||||||
SGSampleGroup::_smgr = smgr;
|
SGSampleGroup::_smgr = smgr;
|
||||||
SGSampleGroup::_refname = refname;
|
SGSampleGroup::_refname = refname;
|
||||||
SGSampleGroup::_smgr->add(this, refname);
|
SGSampleGroup::_smgr->add(this, refname);
|
||||||
_avionics = _smgr->find("avionics", true);
|
_avionics = _smgr->find("avionics", true);
|
||||||
_avionics->tie_to_listener();
|
_avionics->tie_to_listener();
|
||||||
_enabled->setBoolValue(true);
|
|
||||||
_volume->setFloatValue(1.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,22 +116,16 @@ FGFX::reinit()
|
||||||
void
|
void
|
||||||
FGFX::update (double dt)
|
FGFX::update (double dt)
|
||||||
{
|
{
|
||||||
bool new_enabled = _enabled->getBoolValue();
|
if ( _avionics_enabled->getBoolValue() )
|
||||||
if ( new_enabled != last_enabled ) {
|
_avionics->resume(); // no-op if already in resumed state
|
||||||
if ( new_enabled ) {
|
else
|
||||||
resume();
|
_avionics->suspend();
|
||||||
} else {
|
_avionics->set_volume( _avionics_volume->getDoubleValue() );
|
||||||
suspend();
|
|
||||||
}
|
|
||||||
last_enabled = new_enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( new_enabled ) {
|
|
||||||
double volume = _volume->getDoubleValue();
|
if ( _enabled->getBoolValue() ) {
|
||||||
if ( volume != last_volume ) {
|
set_volume( _volume->getDoubleValue() );
|
||||||
set_volume( volume );
|
resume();
|
||||||
last_volume = volume;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update sound effects if not paused
|
// update sound effects if not paused
|
||||||
for ( unsigned int i = 0; i < _sound.size(); i++ ) {
|
for ( unsigned int i = 0; i < _sound.size(); i++ ) {
|
||||||
|
@ -142,6 +134,8 @@ FGFX::update (double dt)
|
||||||
|
|
||||||
SGSampleGroup::update(dt);
|
SGSampleGroup::update(dt);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
suspend();
|
||||||
}
|
}
|
||||||
|
|
||||||
// end of fg_fx.cxx
|
// end of fg_fx.cxx
|
||||||
|
|
|
@ -60,11 +60,10 @@ private:
|
||||||
SGSharedPtr<SGSampleGroup> _avionics;
|
SGSharedPtr<SGSampleGroup> _avionics;
|
||||||
std::vector<SGXmlSound *> _sound;
|
std::vector<SGXmlSound *> _sound;
|
||||||
|
|
||||||
bool last_enabled;
|
|
||||||
double last_volume;
|
|
||||||
|
|
||||||
SGPropertyNode_ptr _enabled;
|
SGPropertyNode_ptr _enabled;
|
||||||
SGPropertyNode_ptr _volume;
|
SGPropertyNode_ptr _volume;
|
||||||
|
SGPropertyNode_ptr _avionics_enabled;
|
||||||
|
SGPropertyNode_ptr _avionics_volume;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue