]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/mk_viii.hxx
Fix flight-plan course and distance computations.
[flightgear.git] / src / Instrumentation / mk_viii.hxx
old mode 100755 (executable)
new mode 100644 (file)
index 517ee49..6529fba
@@ -16,7 +16,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
 
 
 #ifndef __INSTRUMENTS_MK_VIII_HXX
@@ -29,9 +29,8 @@
 #include <map>
 
 #include <simgear/props/props.hxx>
-#include <simgear/sound/sample_openal.hxx>
+#include <simgear/props/tiedpropertylist.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
-
 using std::vector;
 using std::deque;
 using std::map;
@@ -39,14 +38,16 @@ using std::map;
 class SGSampleGroup;
 
 #include <Airports/runways.hxx>
-#include <Airports/simple.hxx>
+#include <Airports/airport.hxx>
 #include <Main/globals.hxx>
+#include <Sound/voiceplayer.hxx>
 
 #ifdef _MSC_VER
 #  pragma warning( push )
 #  pragma warning( disable: 4355 )
 #endif
 
+
 ///////////////////////////////////////////////////////////////////////////////
 // MK_VIII ////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
@@ -56,49 +57,6 @@ class MK_VIII : public SGSubsystem
   // keep in sync with Mode6Handler::altitude_callout_definitions[]
   static const unsigned n_altitude_callouts = 11;
 
-  /////////////////////////////////////////////////////////////////////////////
-  // MK_VIII::RawValueMethodsData /////////////////////////////////////////////
-  /////////////////////////////////////////////////////////////////////////////
-
-  template <class C, class VT, class DT>
-  class RawValueMethodsData : public SGRawValue<VT>
-  {
-  public:
-    typedef VT (C::*getter_t) (DT) const;
-    typedef void (C::*setter_t) (DT, VT);
-
-    RawValueMethodsData (C &obj, DT data, getter_t getter = 0, setter_t setter = 0)
-      : _obj(obj), _data(data), _getter(getter), _setter(setter) {}
-
-    virtual VT getValue () const
-    {
-      if (_getter)
-       return (_obj.*_getter)(_data);
-      else
-       return SGRawValue<VT>::DefaultValue();
-    }
-    virtual bool setValue (VT value)
-    {
-      if (_setter)
-       {
-         (_obj.*_setter)(_data, value);
-         return true;
-       }
-      else
-       return false;
-    }
-    virtual SGRawValue<VT> *clone () const 
-    {
-      return new RawValueMethodsData<C,VT,DT>(_obj, _data, _getter, _setter);
-    }
-
-  private:
-    C          &_obj;
-    DT         _data;
-    getter_t   _getter;
-    setter_t   _setter;
-  };
-
   /////////////////////////////////////////////////////////////////////////////
   // MK_VIII::Parameter ///////////////////////////////////////////////////////
   /////////////////////////////////////////////////////////////////////////////
@@ -184,12 +142,10 @@ class MK_VIII : public SGSubsystem
   // MK_VIII::PropertiesHandler ///////////////////////////////////////////////
   /////////////////////////////////////////////////////////////////////////////
 
-  class PropertiesHandler
+  class PropertiesHandler : public FGVoicePlayer::PropertiesHandler
   {
     MK_VIII *mk;
 
-    vector<SGPropertyNode_ptr> tied_properties;
-
   public:
     struct
     {
@@ -201,6 +157,7 @@ class MK_VIII : public SGSubsystem
       SGPropertyNode_ptr altitude;
       SGPropertyNode_ptr altitude_agl;
       SGPropertyNode_ptr altitude_gear_agl;
+      SGPropertyNode_ptr altitude_radar_agl;
       SGPropertyNode_ptr orientation_roll;
       SGPropertyNode_ptr asi_serviceable;
       SGPropertyNode_ptr asi_speed;
@@ -224,27 +181,11 @@ class MK_VIII : public SGSubsystem
     } external_properties;
 
     inline PropertiesHandler (MK_VIII *device)
-      : mk(device) {}
-
-    template <class T>
-    inline void tie (SGPropertyNode *node, const SGRawValue<T> &raw_value)
-    {
-      node->tie(raw_value);
-      tied_properties.push_back(node);
-    }
+      : FGVoicePlayer::PropertiesHandler(), mk(device) {}
 
-    template <class T>
-    inline void tie (SGPropertyNode *node,
-                    const char *relative_path,
-                    const SGRawValue<T> &raw_value)
-    {
-      tie(node->getNode(relative_path, true), raw_value);
-    }
-
-    PropertiesHandler() {};
+    PropertiesHandler() : FGVoicePlayer::PropertiesHandler() {}
 
     void init ();
-    void unbind ();
   };
 
 public:
@@ -481,7 +422,7 @@ public:
       bool                     alternate_steep_approach;
       bool                     use_internal_gps;
       bool                     localizer_enabled;
-      bool                     use_gear_altitude;
+      int                      altitude_source;
       bool                     use_attitude_indicator;
     } conf;
 
@@ -715,250 +656,49 @@ public:
 
     bool *get_lamp_output (Lamp lamp);
   };
-
-  /////////////////////////////////////////////////////////////////////////////
-  // MK_VIII::VoicePlayer /////////////////////////////////////////////////////
-  /////////////////////////////////////////////////////////////////////////////
-
-  class VoicePlayer
+  
+  class VoicePlayer : public FGVoicePlayer
   {
   public:
+      VoicePlayer (MK_VIII *device) :
+          FGVoicePlayer(&device->properties_handler, "mk-viii")
+      {}
 
-    ///////////////////////////////////////////////////////////////////////////
-    // MK_VIII::VoicePlayer::Voice ////////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-
-    class Voice
-    {
-    public:
-
-      /////////////////////////////////////////////////////////////////////////
-      // MK_VIII::VoicePlayer::Voice::Element ////////////////////////////////////////
-      /////////////////////////////////////////////////////////////////////////
-
-      class Element
-      {
-      public:
-       bool silence;
-
-       virtual inline void play (float volume) {}
-       virtual inline void stop () {}
-       virtual bool is_playing () = 0;
-       virtual inline void set_volume (float volume) {}
-      };
-
-      /////////////////////////////////////////////////////////////////////////
-      // MK_VIII::VoicePlayer::Voice::SampleElement ///////////////////////////
-      /////////////////////////////////////////////////////////////////////////
-
-      class SampleElement : public Element
-      {
-       SGSharedPtr<SGSoundSample>      _sample;
-       float                           _volume;
-
-      public:
-       inline SampleElement (SGSharedPtr<SGSoundSample> sample, float volume = 1.0)
-         : _sample(sample), _volume(volume) { silence = false; }
-
-        virtual inline void play (float volume) { if (_sample && (volume > 0.05)) { set_volume(volume); _sample->play_once(); } }
-       virtual inline void stop () { if (_sample) _sample->stop(); }
-        virtual inline bool is_playing () { return _sample ? _sample->is_playing() : false; }
-       virtual inline void set_volume (float volume) { if (_sample) _sample->set_volume(volume * _volume); }
-      };
-
-      /////////////////////////////////////////////////////////////////////////
-      // MK_VIII::VoicePlayer::Voice::SilenceElement //////////////////////////
-      /////////////////////////////////////////////////////////////////////////
-
-      class SilenceElement : public Element
-      {
-       double _duration;
-       double start_time;
-
-      public:
-       inline SilenceElement (double duration)
-         : _duration(duration) { silence = true; }
-
-       virtual inline void play (float volume) { start_time = globals->get_sim_time_sec(); }
-       virtual inline bool is_playing () { return globals->get_sim_time_sec() - start_time < _duration; }
-      };
-
-      /////////////////////////////////////////////////////////////////////////
-      // MK_VIII::VoicePlayer::Voice (continued) //////////////////////////////
-      /////////////////////////////////////////////////////////////////////////
-
-      Element *element;
-
-      inline Voice (VoicePlayer *_player)
-        : element(NULL), player(_player), volume(1.0) {}
-
-      ~Voice ();
-
-      inline void append (Element *_element) { elements.push_back(_element); }
-
-      void play ();
-      void stop (bool now);
-      void set_volume (float _volume);
-      void volume_changed ();
-      void update ();
-
-    private:
-      VoicePlayer *player;
-
-      float volume;
-
-      vector<Element *>                        elements;
-      vector<Element *>::iterator      iter;
-
-      inline float get_volume () const { return player->volume * player->speaker.volume * volume; }
-    };
-
-    ///////////////////////////////////////////////////////////////////////////
-    // MK_VIII::VoicePlayer (continued) ///////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-
-    struct
-    {
-      float volume;
-    } conf;
-
-    float volume;
-
-    Voice *voice;
-    Voice *next_voice;
-
-    struct
-    {
-      Voice *application_data_base_failed;
-      Voice *bank_angle;
-      Voice *bank_angle_bank_angle;
-      Voice *bank_angle_bank_angle_3;
-      Voice *bank_angle_inop;
-      Voice *bank_angle_pause_bank_angle;
-      Voice *bank_angle_pause_bank_angle_3;
-      Voice *callouts_inop;
-      Voice *configuration_type_invalid;
-      Voice *dont_sink;
-      Voice *dont_sink_pause_dont_sink;
-      Voice *five_hundred_above;
-      Voice *glideslope;
-      Voice *glideslope_inop;
-      Voice *gpws_inop;
-      Voice *hard_glideslope;
-      Voice *minimums;
-      Voice *minimums_minimums;
-      Voice *pull_up;
-      Voice *sink_rate;
-      Voice *sink_rate_pause_sink_rate;
-      Voice *soft_glideslope;
-      Voice *terrain;
-      Voice *terrain_pause_terrain;
-      Voice *too_low_flaps;
-      Voice *too_low_gear;
-      Voice *too_low_terrain;
-      Voice *altitude_callouts[n_altitude_callouts];
-    } voices;
-
-    inline VoicePlayer (MK_VIII *device)
-      : voice(NULL), next_voice(NULL),  mk(device), speaker(this) {}
-
-    ~VoicePlayer ();
-
-    void init ();
-
-    enum
-    {
-      PLAY_NOW         = 1 << 0,
-      PLAY_LOOPED      = 1 << 1
-    };
-    void play (Voice *_voice, unsigned int flags = 0);
-
-    enum
-    {
-      STOP_NOW         = 1 << 0
-    };
-    void stop (unsigned int flags = 0);
-
-    void set_volume (float _volume);
-    void update ();
-
-    inline void bind (SGPropertyNode *node) { speaker.bind(node); }
-
-  public:
-
-    ///////////////////////////////////////////////////////////////////////////
-    // MK_VIII::VoicePlayer::Speaker //////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-
-    class Speaker
-    {
-      VoicePlayer *player;
-
-      double   pitch;
-
-      template <class T>
-      inline void tie (SGPropertyNode *node, const char *name, T *ptr)
-      {
-       player->mk->properties_handler.tie
-         (node, (string("speaker/") + name).c_str(),
-          RawValueMethodsData<MK_VIII::VoicePlayer::Speaker,T,T*>
-          (*this, ptr,
-           &MK_VIII::VoicePlayer::Speaker::get_property,
-           &MK_VIII::VoicePlayer::Speaker::set_property));
-      }
-
-    public:
-      template <class T>
-      inline void set_property (T *ptr, T value) { *ptr = value; update_configuration(); }
-
-      template <class T>
-      inline T get_property (T *ptr) const { return *ptr; }
-
-      float volume;
+      ~VoicePlayer() {}
+      void init ();
 
-      inline Speaker (VoicePlayer *_player)
-       : player(_player),
-         pitch(1),
-         volume(1)
+      struct
       {
-      }
-
-      void bind (SGPropertyNode *node);
-      void update_configuration ();
-    };
-
-  private:
-    ///////////////////////////////////////////////////////////////////////////
-    // MK_VIII::VoicePlayer (continued) ///////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-
-    MK_VIII *mk;
-
-    SGSharedPtr<SGSampleGroup> _sgr;
-    Speaker speaker;
-
-    map< string, SGSharedPtr<SGSoundSample> >  samples;
-    vector<Voice *>                    _voices;
-
-    bool looped;
-    bool next_looped;
-
-    SGSoundSample *get_sample (const char *name);
-
-    inline void append (Voice *voice, Voice::Element *element) { voice->append(element); }
-    inline void append (Voice *voice, const char *sample_name) { voice->append(new Voice::SampleElement(get_sample(sample_name))); }
-    inline void append (Voice *voice, double silence) { voice->append(new Voice::SilenceElement(silence)); }
-
-    inline void make_voice (Voice **voice) { *voice = new Voice(this); _voices.push_back(*voice); }
-
-    template <class T1>
-    inline void make_voice (Voice **voice, T1 e1) { make_voice(voice); append(*voice, e1); }
-    template <class T1, class T2>
-    inline void make_voice (Voice **voice, T1 e1, T2 e2) { make_voice(voice, e1); append(*voice, e2); }
-    template <class T1, class T2, class T3>
-    inline void make_voice (Voice **voice, T1 e1, T2 e2, T3 e3) { make_voice(voice, e1, e2); append(*voice, e3); }
-    template <class T1, class T2, class T3, class T4>
-    inline void make_voice (Voice **voice, T1 e1, T2 e2, T3 e3, T4 e4) { make_voice(voice, e1, e2, e3); append(*voice, e4); }
+        Voice *application_data_base_failed;
+        Voice *bank_angle;
+        Voice *bank_angle_bank_angle;
+        Voice *bank_angle_bank_angle_3;
+        Voice *bank_angle_inop;
+        Voice *bank_angle_pause_bank_angle;
+        Voice *bank_angle_pause_bank_angle_3;
+        Voice *callouts_inop;
+        Voice *configuration_type_invalid;
+        Voice *dont_sink;
+        Voice *dont_sink_pause_dont_sink;
+        Voice *five_hundred_above;
+        Voice *glideslope;
+        Voice *glideslope_inop;
+        Voice *gpws_inop;
+        Voice *hard_glideslope;
+        Voice *minimums;
+        Voice *minimums_minimums;
+        Voice *pull_up;
+        Voice *sink_rate;
+        Voice *sink_rate_pause_sink_rate;
+        Voice *soft_glideslope;
+        Voice *terrain;
+        Voice *terrain_pause_terrain;
+        Voice *too_low_flaps;
+        Voice *too_low_gear;
+        Voice *too_low_terrain;
+        Voice *altitude_callouts[n_altitude_callouts];
+      } voices;
+      
   };
 
 private:
@@ -1530,13 +1270,7 @@ private:
   {
     typedef struct
     {
-      double latitude;         // latitude in degrees
-      double longitude;                // longitude in degrees
-    } Position;
-
-    typedef struct
-    {
-      Position position;       // position of threshold
+      SGGeod   position;       // position of threshold
       double   heading;        // runway heading
     } RunwayEdge;
 
@@ -1549,33 +1283,20 @@ private:
 
     struct
     {
-      Position         center;         // center point
+      SGGeod           center;         // center point
       double           elevation;      // elevation in feet
       double           half_length;    // runway half length, in nautical miles
-      RunwayEdge       edges[2];       // runway threshold and end
-      Position         bias_area[4];   // vertices of the bias area
+      double            half_width_m;   // runway half width, in meters
+      RunwayEdge       edge;           // runway threshold
+      SGVec3d          bias_points[2]; // vertices of the bias area
     } runway;
 
     double bias;
     double *reference;
     double initial_value;
 
-    double get_azimuth_difference (double from_lat,
-                                  double from_lon,
-                                  double to_lat,
-                                  double to_lon,
-                                  double to_heading);
-    double get_azimuth_difference (const FGRunway *_runway);
-
-    FGRunway* select_runway (const FGAirport *airport);
     void update_runway ();
 
-    void get_bias_area_edges (Position *edge,
-                             double reciprocal,
-                             double half_width_m,
-                             Position *bias_edge1,
-                             Position *bias_edge2);
-
     bool is_inside_edge_triangle (RunwayEdge *edge);
     bool is_inside_bias_area ();
 
@@ -1608,7 +1329,7 @@ private:
   // MK_VIII (continued) //////////////////////////////////////////////////////
   /////////////////////////////////////////////////////////////////////////////
 
-  string       name;
+  std::string  name;
   int          num;
 
   PowerHandler         power_handler;