From: James Turner Date: Tue, 25 Sep 2012 08:17:00 +0000 (+0100) Subject: Make the view-manager and sound-manager independent. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4456f42e673330238a341e9be079e0d57222dbf9;p=flightgear.git Make the view-manager and sound-manager independent. Use properties to pass current-view information to the sound-manager, so there is no hard-coded dependency between the subsystems. --- diff --git a/src/Sound/soundmanager.cxx b/src/Sound/soundmanager.cxx index 16db63289..2a41ade13 100644 --- a/src/Sound/soundmanager.cxx +++ b/src/Sound/soundmanager.cxx @@ -64,6 +64,15 @@ void FGSoundManager::init() _volume = fgGetNode("/sim/sound/volume"); _device_name = fgGetNode("/sim/sound/device-name"); + _currentView = fgGetNode("sim/current-view"); + _viewPosLon = fgGetNode("sim/current-view/viewer-lon-deg"); + _viewPosLat = fgGetNode("sim/current-view/viewer-lat-deg"); + _viewPosElev = fgGetNode("sim/current-view/viewer-elev-ft"); + + _velocityNorthFPS = fgGetNode("velocities/speed-north-fps", true); + _velocityEastFPS = fgGetNode("velocities/speed-east-fps", true); + _velocityDownFPS = fgGetNode("velocities/speed-down-fps", true); + reinit(); } @@ -113,6 +122,15 @@ void FGSoundManager::update_device_list() devices.clear(); } +bool FGSoundManager::stationary() const +{ + // this is an ugly hack to decide if the *viewer* is stationary, + // since we don't model the viewer velocity directly. + return (_currentView->getDoubleValue("x-offset-m") == 0.0) && + (_currentView->getDoubleValue("y-offset-m") == 0.0) && + (_currentView->getDoubleValue("z-offset-m") == 0.0); +} + // Update sound manager and propagate property values, // since the sound manager doesn't read any properties itself. // Actual sound update is triggered by the subsystem manager. @@ -120,6 +138,29 @@ void FGSoundManager::update(double dt) { if (_is_initialized && _sound_working->getBoolValue() && _sound_enabled->getBoolValue()) { + SGGeod viewPosGeod(SGGeod::fromDegFt(_viewPosLon->getDoubleValue(), + _viewPosLat->getDoubleValue(), + _viewPosElev->getDoubleValue())); + SGVec3d cartPos = SGVec3d::fromGeod(viewPosGeod); + + set_position(cartPos, viewPosGeod); + + SGQuatd viewOrientation; + for (int i=0; i<4; ++i) { + viewOrientation[i] = _currentView->getChild("raw-orientation", i, true)->getDoubleValue(); + } + + set_orientation( viewOrientation ); + + SGVec3d velocity(SGVec3d::zeros()); + if (!stationary()) { + velocity = SGVec3d(_velocityNorthFPS->getDoubleValue(), + _velocityEastFPS->getDoubleValue(), + _velocityDownFPS->getDoubleValue() ); + } + + set_velocity( velocity ); + set_volume(_volume->getFloatValue()); SGSoundMgr::update(dt); } diff --git a/src/Sound/soundmanager.hxx b/src/Sound/soundmanager.hxx index d43e49478..e9edbd7d3 100644 --- a/src/Sound/soundmanager.hxx +++ b/src/Sound/soundmanager.hxx @@ -46,8 +46,13 @@ public: void update_device_list(); private: + bool stationary() const; + bool _is_initialized; SGPropertyNode_ptr _sound_working, _sound_enabled, _volume, _device_name; + SGPropertyNode_ptr _currentView; + SGPropertyNode_ptr _viewPosLon, _viewPosLat, _viewPosElev; + SGPropertyNode_ptr _velocityNorthFPS, _velocityEastFPS, _velocityDownFPS; Listener* _listener; }; #else diff --git a/src/Viewer/viewer.cxx b/src/Viewer/viewer.cxx index 98e5fe24f..2d6521822 100644 --- a/src/Viewer/viewer.cxx +++ b/src/Viewer/viewer.cxx @@ -27,6 +27,8 @@ # include "config.h" #endif +#include "viewer.hxx" + #include #include @@ -37,11 +39,6 @@ #include
#include
-#include -#include - -#include "viewer.hxx" - #include "CameraGroup.hxx" using namespace flightgear; diff --git a/src/Viewer/viewmgr.cxx b/src/Viewer/viewmgr.cxx index 76a1eb3df..91657fa1c 100644 --- a/src/Viewer/viewmgr.cxx +++ b/src/Viewer/viewmgr.cxx @@ -30,7 +30,6 @@ #include // strcmp #include -#include #include
#include "viewer.hxx" @@ -44,8 +43,7 @@ FGViewMgr::FGViewMgr( void ) : abs_viewer_position(SGVec3d::zeros()), current(0), current_view_orientation(SGQuatd::zeros()), - current_view_or_offset(SGQuatd::zeros()), - smgr(globals->get_soundmgr()) + current_view_or_offset(SGQuatd::zeros()) { } @@ -179,11 +177,7 @@ FGViewMgr::bind() void FGViewMgr::do_bind() -{ - velocityNorthFPS = fgGetNode("velocities/speed-north-fps", true); - velocityEastFPS = fgGetNode("velocities/speed-east-fps", true); - velocityDownFPS = fgGetNode("velocities/speed-down-fps", true); - +{ // these are bound to the current view properties _tiedProperties.setRoot(fgGetNode("/sim/current-view", true)); _tiedProperties.Tie("heading-offset-deg", this, @@ -240,6 +234,11 @@ FGViewMgr::do_bind() _tiedProperties.Tie(n->getNode("viewer-y-m", true),SGRawValuePointer(&abs_viewer_position[1])); _tiedProperties.Tie(n->getNode("viewer-z-m", true),SGRawValuePointer(&abs_viewer_position[2])); + _tiedProperties.Tie("viewer-lon-deg", this, &FGViewMgr::getViewLon_deg); + _tiedProperties.Tie("viewer-lat-deg", this, &FGViewMgr::getViewLat_deg); + _tiedProperties.Tie("viewer-elev-ft", this, &FGViewMgr::getViewElev_ft); + + _tiedProperties.Tie("debug/orientation-w", this, &FGViewMgr::getCurrentViewOrientation_w); _tiedProperties.Tie("debug/orientation-x", this, @@ -277,8 +276,8 @@ FGViewMgr::unbind () void FGViewMgr::update (double dt) { - FGViewer *loop_view = (FGViewer *)get_current_view(); - if (loop_view == 0) return; + FGViewer* currentView = (FGViewer *)get_current_view(); + if (!currentView) return; SGPropertyNode *n = config_list[current]; double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg; @@ -293,15 +292,15 @@ FGViewMgr::update (double dt) pitch_deg = fgGetDouble(n->getStringValue("config/eye-pitch-deg-path")); heading_deg = fgGetDouble(n->getStringValue("config/eye-heading-deg-path")); - loop_view->setPosition(lon_deg, lat_deg, alt_ft); - loop_view->setOrientation(roll_deg, pitch_deg, heading_deg); + currentView->setPosition(lon_deg, lat_deg, alt_ft); + currentView->setOrientation(roll_deg, pitch_deg, heading_deg); } else { // force recalc in viewer - loop_view->set_dirty(); + currentView->set_dirty(); } // if lookat (type 1) then get target data... - if (loop_view->getType() == FG_LOOKAT) { + if (currentView->getType() == FG_LOOKAT) { if (!n->getBoolValue("config/from-model")) { lon_deg = fgGetDouble(n->getStringValue("config/target-lon-deg-path")); lat_deg = fgGetDouble(n->getStringValue("config/target-lat-deg-path")); @@ -310,10 +309,10 @@ FGViewMgr::update (double dt) pitch_deg = fgGetDouble(n->getStringValue("config/target-pitch-deg-path")); heading_deg = fgGetDouble(n->getStringValue("config/target-heading-deg-path")); - loop_view->setTargetPosition(lon_deg, lat_deg, alt_ft); - loop_view->setTargetOrientation(roll_deg, pitch_deg, heading_deg); + currentView->setTargetPosition(lon_deg, lat_deg, alt_ft); + currentView->setTargetOrientation(roll_deg, pitch_deg, heading_deg); } else { - loop_view->set_dirty(); + currentView->set_dirty(); } } @@ -325,27 +324,19 @@ FGViewMgr::update (double dt) setViewTargetYOffset_m(fgGetDouble("/sim/current-view/target-y-offset-m")); setViewTargetZOffset_m(fgGetDouble("/sim/current-view/target-z-offset-m")); - current_view_orientation = loop_view->getViewOrientation(); - current_view_or_offset = loop_view->getViewOrientationOffset(); + current_view_orientation = currentView->getViewOrientation(); + current_view_or_offset = currentView->getViewOrientationOffset(); // Update the current view do_axes(); - loop_view->update(dt); - abs_viewer_position = loop_view->getViewPosition(); - - // update audio listener values - // set the viewer position in Cartesian coordinates in meters - smgr->set_position( abs_viewer_position, loop_view->getPosition() ); - smgr->set_orientation( current_view_orientation ); - - // get the model velocity - SGVec3d velocity = SGVec3d::zeros(); - if ( !stationary() ) { - velocity = SGVec3d( velocityNorthFPS->getDoubleValue(), - velocityEastFPS->getDoubleValue(), - velocityDownFPS->getDoubleValue() ); + currentView->update(dt); + abs_viewer_position = currentView->getViewPosition(); + + // expose the raw (OpenGL) orientation to the proeprty tree, + // for the sound-manager + for (int i=0; i<4; ++i) { + _tiedProperties.getRoot()->getChild("raw-orientation", i, true)->setDoubleValue(current_view_orientation[i]); } - smgr->set_velocity( velocity ); } void @@ -619,20 +610,6 @@ FGViewMgr::setViewZOffset_m (double z) } } -bool -FGViewMgr::stationary () const -{ - const FGViewer * view = get_current_view(); - if (view != 0) { - if (((FGViewer *)view)->getXOffset_m() == 0.0 && - ((FGViewer *)view)->getYOffset_m() == 0.0 && - ((FGViewer *)view)->getZOffset_m() == 0.0) - return true; - } - - return false; -} - double FGViewMgr::getViewTargetXOffset_m () const { @@ -785,6 +762,28 @@ FGViewMgr::setViewAxisLat (double axis) axis_lat = axis; } +double +FGViewMgr::getViewLon_deg() const +{ + const FGViewer* view = get_current_view(); + return (view != NULL) ? view->getPosition().getLongitudeDeg() : 0.0; +} + +double +FGViewMgr::getViewLat_deg() const +{ + const FGViewer* view = get_current_view(); + return (view != NULL) ? view->getPosition().getLatitudeDeg() : 0.0; +} + +double +FGViewMgr::getViewElev_ft() const +{ + const FGViewer* view = get_current_view(); + return (view != NULL) ? view->getPosition().getElevationFt() : 0.0; +} + + // reference frame orientation. // This is the view orientation you get when you have no // view offset, i.e. the offset operator is the identity. diff --git a/src/Viewer/viewmgr.hxx b/src/Viewer/viewmgr.hxx index a53b880e5..587ac9f28 100644 --- a/src/Viewer/viewmgr.hxx +++ b/src/Viewer/viewmgr.hxx @@ -34,7 +34,6 @@ // forward decls class FGViewer; -class SGSoundMgr; typedef SGSharedPtr FGViewerPtr; // Define a structure containing view information @@ -119,6 +118,10 @@ private: int getView () const; void setView (int newview); + double getViewLon_deg() const; + double getViewLat_deg() const; + double getViewElev_ft() const; + // quaternion accessors, for debugging: double getCurrentViewOrientation_w() const; double getCurrentViewOrientation_x() const; @@ -133,8 +136,6 @@ private: double getCurrentViewFrame_y() const; double getCurrentViewFrame_z() const; - bool stationary () const; - // copies current offset settings to current-view path... void copyToCurrent (); @@ -147,10 +148,6 @@ private: int current; SGQuatd current_view_orientation, current_view_or_offset; - - SGSoundMgr *smgr; - - SGPropertyNode_ptr velocityNorthFPS, velocityEastFPS, velocityDownFPS; }; // This takes the conventional aviation XYZ body system