1
0
Fork 0

Sound Manager: support subsystem reinit

instead of using property listener.
Also moved run-time init to standard init phase.
This commit is contained in:
ThorstenB 2012-09-21 15:32:31 +02:00
parent 05e9172220
commit 9d08cfc24a
2 changed files with 41 additions and 45 deletions

View file

@ -37,7 +37,7 @@ public:
virtual void valueChanged (SGPropertyNode * node); virtual void valueChanged (SGPropertyNode * node);
private: private:
FGSoundManager * _wrapper; FGSoundManager* _wrapper;
}; };
void Listener::valueChanged(SGPropertyNode * node) 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() 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_working = fgGetNode("/sim/sound/working");
_sound_enabled = fgGetNode("/sim/sound/enabled"); _sound_enabled = fgGetNode("/sim/sound/enabled");
_volume = fgGetNode("/sim/sound/volume"); _volume = fgGetNode("/sim/sound/volume");
_device_name = fgGetNode("/sim/sound/device-name");
// we intentionally do _not_ call SGSoundMgr::bind here, we'll do this later reinit();
}
void FGSoundManager::reinit()
{
_is_initialized = false;
if (_is_initialized && !_sound_working->getBoolValue())
{
// shutdown sound support
stop();
return;
}
if (!_sound_working->getBoolValue())
{
return;
}
update_device_list();
select_device(_device_name->getStringValue());
SGSoundMgr::reinit();
_is_initialized = true;
activate(fgGetBool("sim/sceneryloaded", true));
} }
void FGSoundManager::activate(bool State) void FGSoundManager::activate(bool State)
{ {
if (_is_initialized && if (_is_initialized)
fgGetBool("/sim/sound/working"))
{ {
if (State) if (State)
{
SGSoundMgr::activate(); 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(); std::vector <const char*>devices = get_available_devices();
for (unsigned int i=0; i<devices.size(); i++) { for (unsigned int i=0; i<devices.size(); i++) {
SGPropertyNode *p = fgGetNode("/sim/sound/devices/device", i, true); 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. // Actual sound update is triggered by the subsystem manager.
void FGSoundManager::update(double dt) void FGSoundManager::update(double dt)
{ {
if (!_is_initialized) { if (_is_initialized && _sound_working->getBoolValue() && _sound_enabled->getBoolValue())
if (_sound_working->getBoolValue()) { {
runtime_init(); set_volume(_volume->getFloatValue());
_is_initialized = true; SGSoundMgr::update(dt);
}
} 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);
}
} }
} }

View file

@ -39,26 +39,25 @@ public:
~FGSoundManager(); ~FGSoundManager();
void init(void); void init(void);
void bind(void);
void update(double dt); void update(double dt);
void reinit(void);
void runtime_init(void);
void activate(bool State); void activate(bool State);
void update_device_list();
static void setNewSoundDevice(const char *device);
private: private:
bool _is_initialized; bool _is_initialized;
SGPropertyNode_ptr _sound_working, _sound_enabled, _volume; SGPropertyNode_ptr _sound_working, _sound_enabled, _volume, _device_name;
Listener* _listener; Listener* _listener;
}; };
#else #else
#include "Main/fg_props.hxx"
// provide a dummy sound class // provide a dummy sound class
class FGSoundManager : public SGSubsystem class FGSoundManager : public SGSubsystem
{ {
public: public:
FGSoundManager() {} FGSoundManager() { fgSetBool("/sim/sound/working", false);}
~FGSoundManager() {} ~FGSoundManager() {}
void update(double dt) {} void update(double dt) {}