Add the Sound Manager before any other subsystem that uses it. This makes sure the SoundMgr is available at construction time which makes the code much cleaner. Call the update_last() after any other class
This commit is contained in:
parent
86f462933d
commit
446b200edc
9 changed files with 60 additions and 64 deletions
|
@ -29,6 +29,8 @@ using std::string;
|
||||||
|
|
||||||
#include "AIPlane.hxx"
|
#include "AIPlane.hxx"
|
||||||
|
|
||||||
|
SGSampleGroup *FGAIPlane::_sgr = 0;
|
||||||
|
|
||||||
FGAIPlane::FGAIPlane() {
|
FGAIPlane::FGAIPlane() {
|
||||||
leg = LEG_UNKNOWN;
|
leg = LEG_UNKNOWN;
|
||||||
tuned_station = NULL;
|
tuned_station = NULL;
|
||||||
|
@ -47,18 +49,18 @@ FGAIPlane::FGAIPlane() {
|
||||||
_trackSet = false;
|
_trackSet = false;
|
||||||
_tgtRoll = 0.0;
|
_tgtRoll = 0.0;
|
||||||
_rollSuspended = false;
|
_rollSuspended = false;
|
||||||
_sgr = 0;
|
|
||||||
|
if ( !_sgr ) {
|
||||||
|
SGSoundMgr *smgr;
|
||||||
|
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||||
|
_sgr = smgr->find("atc", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FGAIPlane::~FGAIPlane() {
|
FGAIPlane::~FGAIPlane() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIPlane::Update(double dt) {
|
void FGAIPlane::Update(double dt) {
|
||||||
if (!_sgr) {
|
|
||||||
SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
|
||||||
if (smgr) _sgr = smgr->find("atc", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(_pending) {
|
if(_pending) {
|
||||||
if(tuned_station) {
|
if(tuned_station) {
|
||||||
if(tuned_station->GetFreqClear()) {
|
if(tuned_station->GetFreqClear()) {
|
||||||
|
|
|
@ -160,7 +160,7 @@ private:
|
||||||
double _tgtRoll;
|
double _tgtRoll;
|
||||||
bool _rollSuspended; // Set true when a derived class has suspended AIPlane's roll control
|
bool _rollSuspended; // Set true when a derived class has suspended AIPlane's roll control
|
||||||
|
|
||||||
SGSampleGroup *_sgr;
|
static SGSampleGroup *_sgr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _FG_AI_PLANE_HXX
|
#endif // _FG_AI_PLANE_HXX
|
||||||
|
|
|
@ -56,6 +56,9 @@ FGATC::FGATC() :
|
||||||
_counter(0.0),
|
_counter(0.0),
|
||||||
_max_count(5.0)
|
_max_count(5.0)
|
||||||
{
|
{
|
||||||
|
SGSoundMgr *smgr;
|
||||||
|
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||||
|
_sgr = smgr->find("atc", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
FGATC::~FGATC() {
|
FGATC::~FGATC() {
|
||||||
|
@ -238,11 +241,6 @@ void FGATC::Render(string& msg, const float volume,
|
||||||
new SGSoundSample((unsigned char*) buf.c_str(), buf.length(), 8000);
|
new SGSoundSample((unsigned char*) buf.c_str(), buf.length(), 8000);
|
||||||
// TODO - at the moment the volume can't be changed
|
// TODO - at the moment the volume can't be changed
|
||||||
// after the transmission has started.
|
// after the transmission has started.
|
||||||
if (!_sgr) {
|
|
||||||
SGSoundMgr *smgr;
|
|
||||||
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
|
||||||
_sgr = smgr->find("atc", true);
|
|
||||||
}
|
|
||||||
simple->set_volume(volume);
|
simple->set_volume(volume);
|
||||||
_sgr->add(simple, refname);
|
_sgr->add(simple, refname);
|
||||||
_sgr->play(refname, repeating);
|
_sgr->play(refname, repeating);
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
#include <simgear/misc/interpolator.hxx>
|
#include <simgear/misc/interpolator.hxx>
|
||||||
#include <simgear/scene/material/matlib.hxx>
|
#include <simgear/scene/material/matlib.hxx>
|
||||||
#include <simgear/scene/model/particles.hxx>
|
#include <simgear/scene/model/particles.hxx>
|
||||||
|
#include <simgear/sound/soundmgr_openal.hxx>
|
||||||
#include <simgear/timing/sg_time.hxx>
|
#include <simgear/timing/sg_time.hxx>
|
||||||
#include <simgear/timing/lowleveltime.h>
|
#include <simgear/timing/lowleveltime.h>
|
||||||
|
|
||||||
|
@ -103,9 +104,6 @@
|
||||||
#include <Scenery/scenery.hxx>
|
#include <Scenery/scenery.hxx>
|
||||||
#include <Scenery/tilemgr.hxx>
|
#include <Scenery/tilemgr.hxx>
|
||||||
#include <Scripting/NasalSys.hxx>
|
#include <Scripting/NasalSys.hxx>
|
||||||
#include <Sound/fg_fx.hxx>
|
|
||||||
#include <Sound/beacon.hxx>
|
|
||||||
#include <Sound/morse.hxx>
|
|
||||||
#include <Sound/voice.hxx>
|
#include <Sound/voice.hxx>
|
||||||
#include <Systems/system_mgr.hxx>
|
#include <Systems/system_mgr.hxx>
|
||||||
#include <Time/light.hxx>
|
#include <Time/light.hxx>
|
||||||
|
@ -135,8 +133,6 @@
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
class Sound;
|
|
||||||
class SGSoundMgr;
|
|
||||||
extern const char *default_root;
|
extern const char *default_root;
|
||||||
float init_volume;
|
float init_volume;
|
||||||
|
|
||||||
|
@ -1668,18 +1664,6 @@ bool fgInitSubsystems() {
|
||||||
globals->add_subsystem("replay", new FGReplay);
|
globals->add_subsystem("replay", new FGReplay);
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Add Sound Manager.
|
|
||||||
// Put the sound manager last so it can use the CPU while the GPU
|
|
||||||
// is processing the scenery (doubled the frame-rate for me) -EMH-
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
#ifdef ENABLE_AUDIO_SUPPORT
|
|
||||||
init_volume = fgGetFloat("/sim/sound/volume");
|
|
||||||
fgSetFloat("/sim/sound/volume", 0.0f);
|
|
||||||
|
|
||||||
globals->add_subsystem("soundmgr", new SGSoundMgr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Bind and initialize subsystems.
|
// Bind and initialize subsystems.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -221,7 +221,6 @@ setFreeze (bool f)
|
||||||
{
|
{
|
||||||
frozen = f;
|
frozen = f;
|
||||||
|
|
||||||
#if 0
|
|
||||||
// Stop sound on a pause
|
// Stop sound on a pause
|
||||||
SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||||
if ( smgr != NULL ) {
|
if ( smgr != NULL ) {
|
||||||
|
@ -231,7 +230,6 @@ setFreeze (bool f)
|
||||||
smgr->resume();
|
smgr->resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -478,14 +478,24 @@ static void fgMainLoop( void ) {
|
||||||
// update the view angle as late as possible, but before sound calculations
|
// update the view angle as late as possible, but before sound calculations
|
||||||
globals->get_viewmgr()->update(real_delta_time_sec);
|
globals->get_viewmgr()->update(real_delta_time_sec);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Update the sound manager last so it can use the CPU while the GPU
|
||||||
|
// is processing the scenery (doubled the frame-rate for me) -EMH-
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
#ifdef ENABLE_AUDIO_SUPPORT
|
||||||
|
static SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||||
|
smgr->update_late(delta_time_sec);
|
||||||
|
#endif
|
||||||
|
|
||||||
// END Tile Manager udpates
|
// END Tile Manager udpates
|
||||||
|
|
||||||
if (!scenery_loaded && globals->get_tile_mgr()->isSceneryLoaded()
|
if (!scenery_loaded && globals->get_tile_mgr()->isSceneryLoaded()
|
||||||
&& cur_fdm_state->get_inited()) {
|
&& cur_fdm_state->get_inited()) {
|
||||||
fgSetBool("sim/sceneryloaded",true);
|
fgSetBool("sim/sceneryloaded",true);
|
||||||
fgSetFloat("/sim/sound/volume", init_volume);
|
fgSetFloat("/sim/sound/volume", init_volume);
|
||||||
SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
#ifdef ENABLE_AUDIO_SUPPORT
|
||||||
smgr->set_volume(init_volume);
|
smgr->set_volume(init_volume);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
fgRequestRedraw();
|
fgRequestRedraw();
|
||||||
|
@ -623,6 +633,16 @@ static void fgIdleFunction ( void ) {
|
||||||
|
|
||||||
} else if ( idle_state == 5 ) {
|
} else if ( idle_state == 5 ) {
|
||||||
idle_state++;
|
idle_state++;
|
||||||
|
#ifdef ENABLE_AUDIO_SUPPORT
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Add the Sound Manager before any other subsystem that uses it.
|
||||||
|
// This makes sure the SoundMgr is available at construction time.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
init_volume = fgGetFloat("/sim/sound/volume");
|
||||||
|
fgSetFloat("/sim/sound/volume", 0.0f);
|
||||||
|
globals->add_subsystem("soundmgr", new SGSoundMgr);
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Initialize the 3D aircraft model subsystem (has a dependency on
|
// Initialize the 3D aircraft model subsystem (has a dependency on
|
||||||
// the scenery subsystem.)
|
// the scenery subsystem.)
|
||||||
|
|
|
@ -43,6 +43,7 @@ FGViewMgr::FGViewMgr( void ) :
|
||||||
config_list(fgGetNode("/sim", true)->getChildren("view")),
|
config_list(fgGetNode("/sim", true)->getChildren("view")),
|
||||||
current(0)
|
current(0)
|
||||||
{
|
{
|
||||||
|
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
@ -296,15 +297,10 @@ FGViewMgr::update (double dt)
|
||||||
abs_viewer_position = loop_view->getViewPosition();
|
abs_viewer_position = loop_view->getViewPosition();
|
||||||
|
|
||||||
// update audio listener values
|
// update audio listener values
|
||||||
static SGSoundMgr *smgr = 0;
|
// set the viewer posotion in Cartesian coordinates in meters
|
||||||
if (!smgr) smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
smgr->set_position(abs_viewer_position);
|
||||||
if (smgr) {
|
smgr->set_orientation(loop_view->getViewOrientation());
|
||||||
// set the viewer posotion in Cartesian coordinates in meters
|
smgr->set_velocity(SGVec3f(0,0,0)); // TODO: in meters per second
|
||||||
smgr->set_position(abs_viewer_position);
|
|
||||||
smgr->set_orientation(loop_view->getViewOrientation());
|
|
||||||
//TODO: should be in meters per second
|
|
||||||
// smr->set_veloicty(SGVec3f(0,0,0));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
// forward decls
|
// forward decls
|
||||||
class FGViewer;
|
class FGViewer;
|
||||||
|
class SGSoundMgr;
|
||||||
typedef SGSharedPtr<FGViewer> FGViewerPtr;
|
typedef SGSharedPtr<FGViewer> FGViewerPtr;
|
||||||
|
|
||||||
// Define a structure containing view information
|
// Define a structure containing view information
|
||||||
|
@ -124,6 +125,8 @@ private:
|
||||||
|
|
||||||
int current;
|
int current;
|
||||||
|
|
||||||
|
SGSoundMgr *smgr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,10 @@ FGAircraftModel::FGAircraftModel ()
|
||||||
_speed_east(0),
|
_speed_east(0),
|
||||||
_speed_up(0)
|
_speed_up(0)
|
||||||
{
|
{
|
||||||
|
SGSoundMgr *smgr;
|
||||||
|
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||||
|
_fx = new FGFX(smgr, "fx");
|
||||||
|
_fx->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
FGAircraftModel::~FGAircraftModel ()
|
FGAircraftModel::~FGAircraftModel ()
|
||||||
|
@ -119,33 +123,24 @@ FGAircraftModel::update (double dt)
|
||||||
_heading->getDoubleValue());
|
_heading->getDoubleValue());
|
||||||
_aircraft->update();
|
_aircraft->update();
|
||||||
|
|
||||||
if ( !_fx) {
|
// update model's sample group values
|
||||||
SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
// Get the Cartesian coordinates in meters
|
||||||
if (smgr) {
|
SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition());
|
||||||
_fx = new FGFX(smgr, "fx");
|
_fx->set_position( pos );
|
||||||
_fx->init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_fx) {
|
SGQuatd orient_m = SGQuatd::fromLonLat(_aircraft->getPosition());
|
||||||
// Get the Cartesian coordinates in meters
|
orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
|
||||||
SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition());
|
_pitch->getDoubleValue(),
|
||||||
_fx->set_position( pos );
|
_roll->getDoubleValue());
|
||||||
|
SGVec3d orient = orient_m.rotateBack(SGVec3d::e1());
|
||||||
SGQuatd orient_m = SGQuatd::fromLonLat(_aircraft->getPosition());
|
_fx->set_orientation( toVec3f(orient) );
|
||||||
orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
|
|
||||||
_pitch->getDoubleValue(),
|
|
||||||
_roll->getDoubleValue());
|
|
||||||
SGVec3d orient = orient_m.rotateBack(SGVec3d::e1());
|
|
||||||
_fx->set_orientation( toVec3f(orient) );
|
|
||||||
|
|
||||||
SGVec3f vel = SGVec3f( _speed_north->getFloatValue(),
|
SGVec3f vel = SGVec3f( _speed_north->getFloatValue(),
|
||||||
_speed_east->getFloatValue(),
|
_speed_east->getFloatValue(),
|
||||||
_speed_up->getFloatValue());
|
_speed_up->getFloatValue());
|
||||||
// TODO: rotate to properly align with the model orientation
|
// TODO: rotate to properly align with the model orientation
|
||||||
|
|
||||||
_fx->set_velocity( vel*SG_FEET_TO_METER );
|
_fx->set_velocity( vel*SG_FEET_TO_METER );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue