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"
|
||||
|
||||
SGSampleGroup *FGAIPlane::_sgr = 0;
|
||||
|
||||
FGAIPlane::FGAIPlane() {
|
||||
leg = LEG_UNKNOWN;
|
||||
tuned_station = NULL;
|
||||
|
@ -47,18 +49,18 @@ FGAIPlane::FGAIPlane() {
|
|||
_trackSet = false;
|
||||
_tgtRoll = 0.0;
|
||||
_rollSuspended = false;
|
||||
_sgr = 0;
|
||||
|
||||
if ( !_sgr ) {
|
||||
SGSoundMgr *smgr;
|
||||
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||
_sgr = smgr->find("atc", true);
|
||||
}
|
||||
}
|
||||
|
||||
FGAIPlane::~FGAIPlane() {
|
||||
}
|
||||
|
||||
void FGAIPlane::Update(double dt) {
|
||||
if (!_sgr) {
|
||||
SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||
if (smgr) _sgr = smgr->find("atc", true);
|
||||
}
|
||||
|
||||
if(_pending) {
|
||||
if(tuned_station) {
|
||||
if(tuned_station->GetFreqClear()) {
|
||||
|
|
|
@ -160,7 +160,7 @@ private:
|
|||
double _tgtRoll;
|
||||
bool _rollSuspended; // Set true when a derived class has suspended AIPlane's roll control
|
||||
|
||||
SGSampleGroup *_sgr;
|
||||
static SGSampleGroup *_sgr;
|
||||
};
|
||||
|
||||
#endif // _FG_AI_PLANE_HXX
|
||||
|
|
|
@ -56,6 +56,9 @@ FGATC::FGATC() :
|
|||
_counter(0.0),
|
||||
_max_count(5.0)
|
||||
{
|
||||
SGSoundMgr *smgr;
|
||||
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||
_sgr = smgr->find("atc", true);
|
||||
}
|
||||
|
||||
FGATC::~FGATC() {
|
||||
|
@ -238,11 +241,6 @@ void FGATC::Render(string& msg, const float volume,
|
|||
new SGSoundSample((unsigned char*) buf.c_str(), buf.length(), 8000);
|
||||
// TODO - at the moment the volume can't be changed
|
||||
// after the transmission has started.
|
||||
if (!_sgr) {
|
||||
SGSoundMgr *smgr;
|
||||
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||
_sgr = smgr->find("atc", true);
|
||||
}
|
||||
simple->set_volume(volume);
|
||||
_sgr->add(simple, refname);
|
||||
_sgr->play(refname, repeating);
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
#include <simgear/misc/interpolator.hxx>
|
||||
#include <simgear/scene/material/matlib.hxx>
|
||||
#include <simgear/scene/model/particles.hxx>
|
||||
#include <simgear/sound/soundmgr_openal.hxx>
|
||||
#include <simgear/timing/sg_time.hxx>
|
||||
#include <simgear/timing/lowleveltime.h>
|
||||
|
||||
|
@ -103,9 +104,6 @@
|
|||
#include <Scenery/scenery.hxx>
|
||||
#include <Scenery/tilemgr.hxx>
|
||||
#include <Scripting/NasalSys.hxx>
|
||||
#include <Sound/fg_fx.hxx>
|
||||
#include <Sound/beacon.hxx>
|
||||
#include <Sound/morse.hxx>
|
||||
#include <Sound/voice.hxx>
|
||||
#include <Systems/system_mgr.hxx>
|
||||
#include <Time/light.hxx>
|
||||
|
@ -135,8 +133,6 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
class Sound;
|
||||
class SGSoundMgr;
|
||||
extern const char *default_root;
|
||||
float init_volume;
|
||||
|
||||
|
@ -1668,18 +1664,6 @@ bool fgInitSubsystems() {
|
|||
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.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -221,7 +221,6 @@ setFreeze (bool f)
|
|||
{
|
||||
frozen = f;
|
||||
|
||||
#if 0
|
||||
// Stop sound on a pause
|
||||
SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||
if ( smgr != NULL ) {
|
||||
|
@ -231,7 +230,6 @@ setFreeze (bool f)
|
|||
smgr->resume();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -478,14 +478,24 @@ static void fgMainLoop( void ) {
|
|||
// update the view angle as late as possible, but before sound calculations
|
||||
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
|
||||
|
||||
if (!scenery_loaded && globals->get_tile_mgr()->isSceneryLoaded()
|
||||
&& cur_fdm_state->get_inited()) {
|
||||
fgSetBool("sim/sceneryloaded",true);
|
||||
fgSetFloat("/sim/sound/volume", init_volume);
|
||||
SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||
#ifdef ENABLE_AUDIO_SUPPORT
|
||||
smgr->set_volume(init_volume);
|
||||
#endif
|
||||
}
|
||||
|
||||
fgRequestRedraw();
|
||||
|
@ -623,6 +633,16 @@ static void fgIdleFunction ( void ) {
|
|||
|
||||
} else if ( idle_state == 5 ) {
|
||||
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
|
||||
// the scenery subsystem.)
|
||||
|
|
|
@ -43,6 +43,7 @@ FGViewMgr::FGViewMgr( void ) :
|
|||
config_list(fgGetNode("/sim", true)->getChildren("view")),
|
||||
current(0)
|
||||
{
|
||||
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||
}
|
||||
|
||||
// Destructor
|
||||
|
@ -296,15 +297,10 @@ FGViewMgr::update (double dt)
|
|||
abs_viewer_position = loop_view->getViewPosition();
|
||||
|
||||
// update audio listener values
|
||||
static SGSoundMgr *smgr = 0;
|
||||
if (!smgr) smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||
if (smgr) {
|
||||
// set the viewer posotion in Cartesian coordinates in meters
|
||||
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));
|
||||
}
|
||||
// set the viewer posotion in Cartesian coordinates in meters
|
||||
smgr->set_position(abs_viewer_position);
|
||||
smgr->set_orientation(loop_view->getViewOrientation());
|
||||
smgr->set_velocity(SGVec3f(0,0,0)); // TODO: in meters per second
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
// forward decls
|
||||
class FGViewer;
|
||||
class SGSoundMgr;
|
||||
typedef SGSharedPtr<FGViewer> FGViewerPtr;
|
||||
|
||||
// Define a structure containing view information
|
||||
|
@ -124,6 +125,8 @@ private:
|
|||
|
||||
int current;
|
||||
|
||||
SGSoundMgr *smgr;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -47,6 +47,10 @@ FGAircraftModel::FGAircraftModel ()
|
|||
_speed_east(0),
|
||||
_speed_up(0)
|
||||
{
|
||||
SGSoundMgr *smgr;
|
||||
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||
_fx = new FGFX(smgr, "fx");
|
||||
_fx->init();
|
||||
}
|
||||
|
||||
FGAircraftModel::~FGAircraftModel ()
|
||||
|
@ -119,33 +123,24 @@ FGAircraftModel::update (double dt)
|
|||
_heading->getDoubleValue());
|
||||
_aircraft->update();
|
||||
|
||||
if ( !_fx) {
|
||||
SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
|
||||
if (smgr) {
|
||||
_fx = new FGFX(smgr, "fx");
|
||||
_fx->init();
|
||||
}
|
||||
}
|
||||
// update model's sample group values
|
||||
// Get the Cartesian coordinates in meters
|
||||
SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition());
|
||||
_fx->set_position( pos );
|
||||
|
||||
if (_fx) {
|
||||
// Get the Cartesian coordinates in meters
|
||||
SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition());
|
||||
_fx->set_position( pos );
|
||||
|
||||
SGQuatd orient_m = SGQuatd::fromLonLat(_aircraft->getPosition());
|
||||
orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
|
||||
_pitch->getDoubleValue(),
|
||||
_roll->getDoubleValue());
|
||||
SGVec3d orient = orient_m.rotateBack(SGVec3d::e1());
|
||||
_fx->set_orientation( toVec3f(orient) );
|
||||
SGQuatd orient_m = SGQuatd::fromLonLat(_aircraft->getPosition());
|
||||
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(),
|
||||
_speed_east->getFloatValue(),
|
||||
_speed_up->getFloatValue());
|
||||
SGVec3f vel = SGVec3f( _speed_north->getFloatValue(),
|
||||
_speed_east->getFloatValue(),
|
||||
_speed_up->getFloatValue());
|
||||
// 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