]> git.mxchange.org Git - flightgear.git/commitdiff
Sound Manager: support subsystem reinit
authorThorstenB <brehmt@gmail.com>
Fri, 21 Sep 2012 13:32:31 +0000 (15:32 +0200)
committerThorstenB <brehmt@gmail.com>
Fri, 21 Sep 2012 13:33:13 +0000 (15:33 +0200)
instead of using property listener.
Also moved run-time init to standard init phase.

src/Sound/soundmanager.cxx
src/Sound/soundmanager.hxx

index 6d3908b3cd43e6572f6ad58a111fa33b3138addc..16db632894620a25639eaf75f02ba8f5e6941d72 100644 (file)
@@ -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<const char *>(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 <const char*>devices = get_available_devices();
     for (unsigned int i=0; i<devices.size(); i++) {
         SGPropertyNode *p = fgGetNode("/sim/sound/devices/device", i, true);
@@ -110,21 +118,10 @@ void FGSoundManager::runtime_init()
 // Actual sound update is triggered by the subsystem manager.
 void FGSoundManager::update(double dt)
 {
-    if (!_is_initialized) {
-        if (_sound_working->getBoolValue()) {
-            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);
     }
 }
 
index 244b7b162726a456361be0675f3d901ab43e011d..d43e49478169993fa58e7a29da65312bdcf07a6e 100644 (file)
@@ -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) {}