From 8b649b06c441dc67c7ceb3d21be41f6e5fa5a074 Mon Sep 17 00:00:00 2001 From: jmt Date: Fri, 18 Sep 2009 16:50:08 +0000 Subject: [PATCH 01/11] Header clean-ups in viewer/view-mgr. --- src/Main/fg_props.hxx | 2 -- src/Main/viewer.hxx | 7 +------ src/Main/viewmgr.cxx | 16 +++++++++++----- src/Main/viewmgr.hxx | 21 +++++++-------------- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/Main/fg_props.hxx b/src/Main/fg_props.hxx index 8516c93c9..7651d65f9 100644 --- a/src/Main/fg_props.hxx +++ b/src/Main/fg_props.hxx @@ -10,8 +10,6 @@ #include #include - -#include
//////////////////////////////////////////////////////////////////////// // Property management. diff --git a/src/Main/viewer.hxx b/src/Main/viewer.hxx index 50d567439..965e8569a 100644 --- a/src/Main/viewer.hxx +++ b/src/Main/viewer.hxx @@ -25,12 +25,7 @@ #ifndef _VIEWER_HXX -#define _VIEWER_HXX - - -#ifndef __cplusplus -# error This library requires C++ -#endif +#define _VIEWER_HXX namespace flightgear { diff --git a/src/Main/viewmgr.cxx b/src/Main/viewmgr.cxx index 950eace83..fd6f25fd9 100644 --- a/src/Main/viewmgr.cxx +++ b/src/Main/viewmgr.cxx @@ -25,14 +25,14 @@ # include "config.h" #endif +#include "viewmgr.hxx" + #include // strcmp #include - #include - -#include "viewmgr.hxx" - +#include
+#include
// Constructor FGViewMgr::FGViewMgr( void ) : @@ -341,7 +341,13 @@ FGViewMgr::copyToCurrent() get_current_view()->getInternal()); } - +void +FGViewMgr::add_view( FGViewer * v ) +{ + views.push_back(v); + v->init(); +} + double FGViewMgr::getViewHeadingOffset_deg () const { diff --git a/src/Main/viewmgr.hxx b/src/Main/viewmgr.hxx index ea4470fbb..c6476a15b 100644 --- a/src/Main/viewmgr.hxx +++ b/src/Main/viewmgr.hxx @@ -28,16 +28,11 @@ #include #include +#include -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "fg_props.hxx" -#include "viewer.hxx" - -using std::vector; - +// forward decls +class FGViewer; +typedef SGSharedPtr FGViewerPtr; // Define a structure containing view information class FGViewMgr : public SGSubsystem @@ -98,10 +93,8 @@ public: // setters inline void clear() { views.clear(); } inline void set_view( const int v ) { current = v; } - inline void add_view( FGViewer * v ) { - views.push_back(v); - v->init(); - } + void add_view( FGViewer * v ); + // copies current offset settings to current-view path... void copyToCurrent (); @@ -150,7 +143,7 @@ private: SGPropertyNode_ptr view_number; vector config_list; - typedef vector > viewer_list; + typedef std::vector viewer_list; viewer_list views; SGVec3d abs_viewer_position; From 3c62011f03329cbb307cc4372ac430c05629e20d Mon Sep 17 00:00:00 2001 From: jmt Date: Fri, 18 Sep 2009 17:17:06 +0000 Subject: [PATCH 02/11] Drat, this is really needed. Yuck, yuck, yuck. --- src/Main/fg_props.hxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Main/fg_props.hxx b/src/Main/fg_props.hxx index 7651d65f9..41772ff35 100644 --- a/src/Main/fg_props.hxx +++ b/src/Main/fg_props.hxx @@ -10,7 +10,9 @@ #include #include - + +#include
+ //////////////////////////////////////////////////////////////////////// // Property management. //////////////////////////////////////////////////////////////////////// From 05626756e7a39f7fc2172fe915f3ef97f0be82b8 Mon Sep 17 00:00:00 2001 From: jmt Date: Fri, 18 Sep 2009 17:27:16 +0000 Subject: [PATCH 03/11] Put back an unfortunate include, until ViewMgr can be fixed to not inline FGViewer destructor calls. --- src/Main/viewmgr.hxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Main/viewmgr.hxx b/src/Main/viewmgr.hxx index c6476a15b..8053a1a9d 100644 --- a/src/Main/viewmgr.hxx +++ b/src/Main/viewmgr.hxx @@ -30,6 +30,8 @@ #include #include +#include
// FIXME - remove inlines here. + // forward decls class FGViewer; typedef SGSharedPtr FGViewerPtr; From 3c84e07a258e371d837d4bc92e0dfd43644bd0e9 Mon Sep 17 00:00:00 2001 From: jmt Date: Sat, 19 Sep 2009 08:03:17 +0000 Subject: [PATCH 04/11] FGFX clean-ups, conversion of one more sgVec user. --- src/Sound/fg_fx.cxx | 101 ++++++++++++++------------------------------ src/Sound/fg_fx.hxx | 17 ++++---- 2 files changed, 39 insertions(+), 79 deletions(-) diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index caff002e2..0a5dabb60 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -29,11 +29,14 @@ # include #endif +#include "fg_fx.hxx" + #include #include #include #include #include +#include #include
@@ -41,17 +44,14 @@ #include #include
-#include "fg_fx.hxx" - - FGFX::FGFX () : + last_visitor_pos(SGVec3d::zeros()), + last_model_pos(SGVec3d::zeros()), last_pause( true ), last_volume( 0.0 ), _pause( fgGetNode("/sim/sound/pause") ), _volume( fgGetNode("/sim/sound/volume") ) { - sgdSetVec3(last_visitor_pos, 0, 0, 0); - sgdSetVec3(last_model_pos, 0, 0, 0); } FGFX::~FGFX () @@ -200,7 +200,7 @@ FGFX::play_message( SGSoundSample *_sample ) _samplequeue.push( _sample ); } void -FGFX::play_message( const string path, const string fname, double volume ) +FGFX::play_message( const std::string& path, const std::string& fname, double volume ) { if (globals->get_soundmgr()->is_working() == true) { SGSoundSample *sample; @@ -237,87 +237,50 @@ FGFX::update_pos_and_orientation(SGSoundMgr *smgr, double dt) // are finally calculated in a left hand system and openal // lives in a right hand system. Therefore we need to pass // the down vector to get correct stereo sound.) - SGVec3d sgv_up, sgv_at; - sgVec3 up, at; - - sgv_up + SGVec3d sgv_up = model_or.rotateBack(surf_or.rotateBack(view_or.rotate(SGVec3d(0,1,0)))); - sgSetVec3(up, sgv_up[0], sgv_up[1], sgv_up[2]); - sgv_at + SGVec3d sgv_at = model_or.rotateBack(surf_or.rotateBack(view_or.rotate(SGVec3d(0,0,1)))); - sgSetVec3(at, sgv_at[0], sgv_at[1], sgv_at[2]); // get the location data for the primary FDM (now hardcoded to ac model)... // EMH: to add multiple sound sources this should be replaced SGVec3d absolute_view_pos = SGVec3d::fromGeod(model->getPosition()); // calculate speed of visitor and model - sgVec3 listener_vel, model_vel; - SGVec3d SGV3d_help; - sgdVec3 sgdv3_help; - sgdVec3 sgdv3_null = {0, 0, 0}; + SGVec3d moved = last_visitor_pos - observer->get_view_pos(); + last_visitor_pos = observer->get_view_pos(); + SGVec3f listener_vel(model_or.rotateBack(surf_or.rotateBack(moved))); + + moved = last_model_pos - absolute_view_pos; + last_model_pos = absolute_view_pos; + SGVec3f model_vel(model_or.rotateBack(surf_or.rotateBack(moved))); - - sgdSubVec3(sgdv3_help, - last_visitor_pos, (double *)&observer->get_view_pos()); - sgdAddVec3(last_visitor_pos, - sgdv3_null, (double *)&observer->get_view_pos()); - - SGV3d_help = model_or.rotateBack( - surf_or.rotateBack( - SGVec3d(sgdv3_help[0], sgdv3_help[1], sgdv3_help[2]) - )); - sgSetVec3(listener_vel, SGV3d_help[0], SGV3d_help[1], SGV3d_help[2]); - - sgdSubVec3(sgdv3_help, last_model_pos, absolute_view_pos.data()); - sgdAddVec3(last_model_pos, sgdv3_null, absolute_view_pos.data()); - - SGV3d_help = model_or.rotateBack( - surf_or.rotateBack( - SGVec3d(sgdv3_help[0], sgdv3_help[1], sgdv3_help[2]) - )); - sgSetVec3( model_vel, SGV3d_help[0], SGV3d_help[1], SGV3d_help[2]); - if (dt > 0) { - sgScaleVec3( model_vel, 1 / dt ); - sgScaleVec3( listener_vel, 1 / dt ); + model_vel /= dt; + listener_vel /= dt; } // checking, if the listener pos has moved suddenly - if (sgLengthVec3(listener_vel) > 1000) - { + if (length(listener_vel) > 1000) { // check if the relative speed model vs listener has moved suddenly, too - sgVec3 delta_vel; - sgSubVec3(delta_vel, listener_vel, model_vel); - if (sgLengthVec3(delta_vel) > 1000) + SGVec3f delta_vel = listener_vel - model_vel; + if (length(delta_vel) > 1000) // a sane value - sgSetVec3(listener_vel, model_vel[0], model_vel[1], model_vel[2]); + smgr->set_listener_vel(model_vel.data()); else - smgr->set_listener_vel(listener_vel); + smgr->set_listener_vel(listener_vel.data()); + } else { + smgr->set_listener_vel( listener_vel.data()); } - else - smgr->set_listener_vel( listener_vel ); - + // set positional offset for sources - sgdVec3 dsource_pos_offset; - sgdSubVec3( dsource_pos_offset, - (double*) &observer->get_view_pos(), - absolute_view_pos.data() ); - SGVec3d sgv_dsource_pos_offset; - sgv_dsource_pos_offset = model_or.rotateBack( - surf_or.rotateBack( - SGVec3d(dsource_pos_offset[0], - dsource_pos_offset[1], - dsource_pos_offset[2]) + SGVec3d dsource_pos_offset = observer->get_view_pos() - absolute_view_pos; + dsource_pos_offset = model_or.rotateBack(surf_or.rotateBack( + dsource_pos_offset )); - sgVec3 source_pos_offset; - sgSetVec3(source_pos_offset, - sgv_dsource_pos_offset[0], - sgv_dsource_pos_offset[1], - sgv_dsource_pos_offset[2]); - smgr->set_source_pos_all( source_pos_offset ); - smgr->set_source_vel_all( model_vel ); + smgr->set_source_pos_all( SGVec3f(dsource_pos_offset).data() ); + smgr->set_source_vel_all(model_vel.data() ); float orient[6]; for (int i = 0; i < 3; i++) { @@ -327,9 +290,7 @@ FGFX::update_pos_and_orientation(SGSoundMgr *smgr, double dt) smgr->set_listener_orientation( orient ); // The listener is always positioned at the origin. - sgVec3 listener_pos; - sgSetVec3( listener_pos, 0.0, 0.0, 0.0 ); - smgr->set_listener_pos( listener_pos ); + smgr->set_listener_pos( SGVec3f::zeros().data() ); } // end of fg_fx.cxx diff --git a/src/Sound/fg_fx.hxx b/src/Sound/fg_fx.hxx index 864a898bb..e04506e72 100644 --- a/src/Sound/fg_fx.hxx +++ b/src/Sound/fg_fx.hxx @@ -29,13 +29,12 @@ #include #include -#include #include - -using std::queue; -using std::vector; +#include class SGXmlSound; +class SGSoundSample; +class SGSoundMgr; /** * Generator for FlightGear sound effects. @@ -72,16 +71,16 @@ public: * in order. */ void play_message( SGSoundSample *_sample ); - void play_message( const string path, const string fname, double volume ); + void play_message( const std::string& path, const std::string& fname, double volume ); private: void update_pos_and_orientation(SGSoundMgr *smgr, double dt); - sgdVec3 last_visitor_pos; - sgdVec3 last_model_pos; + SGVec3d last_visitor_pos; + SGVec3d last_model_pos; - vector _sound; - queue _samplequeue; + std::vector _sound; + std::queue _samplequeue; bool last_pause; double last_volume; From 0c8c8380b1037ca52725e4703cf87ffb6aee77eb Mon Sep 17 00:00:00 2001 From: jmt Date: Sat, 19 Sep 2009 18:41:55 +0000 Subject: [PATCH 05/11] Break viewmgr.hxx dependency on on viewer.hxx. --- src/Cockpit/cockpit.cxx | 1 + src/Cockpit/hud.cxx | 1 + src/Cockpit/hud_ladr.cxx | 2 +- src/Cockpit/hud_rwy.cxx | 1 + src/Cockpit/panel.cxx | 1 + src/Instrumentation/HUD/HUD.cxx | 1 + src/Main/fg_commands.cxx | 1 + src/Main/main.cxx | 2 +- src/Main/options.cxx | 2 +- src/Main/renderer.cxx | 1 + src/Main/viewmgr.cxx | 58 +++++++++++++++++++++++++++++++++ src/Main/viewmgr.hxx | 49 +++++++--------------------- 12 files changed, 79 insertions(+), 41 deletions(-) diff --git a/src/Cockpit/cockpit.cxx b/src/Cockpit/cockpit.cxx index 4e7651f7c..0414a0f6a 100644 --- a/src/Cockpit/cockpit.cxx +++ b/src/Cockpit/cockpit.cxx @@ -44,6 +44,7 @@ #include
#include
#include
+#include
#include #include diff --git a/src/Cockpit/hud.cxx b/src/Cockpit/hud.cxx index f9b9f3a97..6673184e4 100644 --- a/src/Cockpit/hud.cxx +++ b/src/Cockpit/hud.cxx @@ -48,6 +48,7 @@ #include
#include #include +#include
#include "hud.hxx" diff --git a/src/Cockpit/hud_ladr.cxx b/src/Cockpit/hud_ladr.cxx index e2306b427..38def8d9d 100644 --- a/src/Cockpit/hud_ladr.cxx +++ b/src/Cockpit/hud_ladr.cxx @@ -6,7 +6,7 @@ #include "hud.hxx" #include "panel.hxx" - +#include
// FIXME extern float get_roll(void); diff --git a/src/Cockpit/hud_rwy.cxx b/src/Cockpit/hud_rwy.cxx index d4b56356b..2bc15bcd1 100644 --- a/src/Cockpit/hud_rwy.cxx +++ b/src/Cockpit/hud_rwy.cxx @@ -31,6 +31,7 @@ #include #include #include +#include
#include diff --git a/src/Cockpit/panel.cxx b/src/Cockpit/panel.cxx index cd68b342a..43711d529 100644 --- a/src/Cockpit/panel.cxx +++ b/src/Cockpit/panel.cxx @@ -55,6 +55,7 @@ #include
#include