From: ThorstenB Date: Fri, 21 Sep 2012 13:32:31 +0000 (+0200) Subject: Sound Manager: support subsystem reinit X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9d08cfc24a121c364f55c9d2f519c63b53c0c032;p=flightgear.git Sound Manager: support subsystem reinit instead of using property listener. Also moved run-time init to standard init phase. --- diff --git a/src/Sound/soundmanager.cxx b/src/Sound/soundmanager.cxx index 6d3908b3c..16db63289 100644 --- a/src/Sound/soundmanager.cxx +++ b/src/Sound/soundmanager.cxx @@ -37,7 +37,7 @@ public: virtual void valueChanged (SGPropertyNode * node); private: - FGSoundManager * _wrapper; + FGSoundManager* _wrapper; }; void Listener::valueChanged(SGPropertyNode * node) @@ -57,46 +57,54 @@ FGSoundManager::~FGSoundManager() { } - -void FGSoundManager::setNewSoundDevice(const char *device) -{ - SGSoundMgr *smgr = globals->get_soundmgr(); - smgr->suspend(); - smgr->stop(); - smgr->init(device); - smgr->resume(); -} - void FGSoundManager::init() -{ - globals->get_props()->tie("/sim/sound/devices/name", - SGRawValueFunctions(0, FGSoundManager::setNewSoundDevice), false); -} - -void FGSoundManager::bind() { _sound_working = fgGetNode("/sim/sound/working"); _sound_enabled = fgGetNode("/sim/sound/enabled"); _volume = fgGetNode("/sim/sound/volume"); + _device_name = fgGetNode("/sim/sound/device-name"); + + reinit(); +} + +void FGSoundManager::reinit() +{ + _is_initialized = false; + + if (_is_initialized && !_sound_working->getBoolValue()) + { + // shutdown sound support + stop(); + return; + } + + if (!_sound_working->getBoolValue()) + { + return; + } - // we intentionally do _not_ call SGSoundMgr::bind here, we'll do this later + update_device_list(); + + select_device(_device_name->getStringValue()); + SGSoundMgr::reinit(); + _is_initialized = true; + + activate(fgGetBool("sim/sceneryloaded", true)); } void FGSoundManager::activate(bool State) { - if (_is_initialized && - fgGetBool("/sim/sound/working")) + if (_is_initialized) { if (State) + { SGSoundMgr::activate(); + } } } -void FGSoundManager::runtime_init() +void FGSoundManager::update_device_list() { - SGSoundMgr::bind(); - SGSoundMgr::init(fgGetString("/sim/sound/device-name", NULL)); - std::vector devices = get_available_devices(); for (unsigned int i=0; igetBoolValue()) { - runtime_init(); - _is_initialized = true; - } - } else { - if (!_sound_working->getBoolValue()) { // request to reinit - SGSoundMgr::reinit(); - _sound_working->setBoolValue(true); - } - - if (_sound_enabled->getBoolValue()) { - set_volume(_volume->getFloatValue()); - SGSoundMgr::update(dt); - } + if (_is_initialized && _sound_working->getBoolValue() && _sound_enabled->getBoolValue()) + { + set_volume(_volume->getFloatValue()); + SGSoundMgr::update(dt); } } diff --git a/src/Sound/soundmanager.hxx b/src/Sound/soundmanager.hxx index 244b7b162..d43e49478 100644 --- a/src/Sound/soundmanager.hxx +++ b/src/Sound/soundmanager.hxx @@ -39,26 +39,25 @@ public: ~FGSoundManager(); void init(void); - void bind(void); void update(double dt); + void reinit(void); - void runtime_init(void); void activate(bool State); - - static void setNewSoundDevice(const char *device); + void update_device_list(); private: bool _is_initialized; - SGPropertyNode_ptr _sound_working, _sound_enabled, _volume; + SGPropertyNode_ptr _sound_working, _sound_enabled, _volume, _device_name; Listener* _listener; }; #else +#include "Main/fg_props.hxx" // provide a dummy sound class class FGSoundManager : public SGSubsystem { public: - FGSoundManager() {} + FGSoundManager() { fgSetBool("/sim/sound/working", false);} ~FGSoundManager() {} void update(double dt) {}