]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/mk_viii.hxx
Give the FGAirport class a sane filename.
[flightgear.git] / src / Instrumentation / mk_viii.hxx
old mode 100755 (executable)
new mode 100644 (file)
index d3d581e..81a3358
@@ -1,4 +1,4 @@
-// mk_viii.cxx -- Honeywell MK VIII EGPWS emulation
+// mk_viii.hxx -- Honeywell MK VIII EGPWS emulation
 //
 // Written by Jean-Yves Lefort, started September 2005.
 //
@@ -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
 #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;
 
-#include "Airports/runways.hxx"
-#include "Airports/simple.hxx"
-#include "Main/globals.hxx"
+class SGSampleGroup;
+
+#include <Airports/runways.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 ////////////////////////////////////////////////////////////////////
@@ -47,50 +55,7 @@ using std::map;
 class MK_VIII : public SGSubsystem
 {
   // keep in sync with Mode6Handler::altitude_callout_definitions[]
-  static const int 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;
-  };
+  static const unsigned n_altitude_callouts = 11;
 
   /////////////////////////////////////////////////////////////////////////////
   // MK_VIII::Parameter ///////////////////////////////////////////////////////
@@ -177,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
     {
@@ -193,6 +156,9 @@ class MK_VIII : public SGSubsystem
       SGPropertyNode_ptr altimeter_serviceable;
       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;
       SGPropertyNode_ptr autopilot_heading_lock;
@@ -215,27 +181,11 @@ class MK_VIII : public SGSubsystem
     } external_properties;
 
     inline PropertiesHandler (MK_VIII *device)
-      : mk(device) {}
+      : FGVoicePlayer::PropertiesHandler(), mk(device) {}
 
-    template <class T>
-    inline void tie (SGPropertyNode *node, const SGRawValue<T> &raw_value)
-    {
-      node->tie(raw_value);
-      tied_properties.push_back(node);
-    }
-
-    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:
@@ -472,6 +422,8 @@ public:
       bool                     alternate_steep_approach;
       bool                     use_internal_gps;
       bool                     localizer_enabled;
+      int                      altitude_source;
+      bool                     use_attitude_indicator;
     } conf;
 
     struct _s_input_feeders
@@ -598,6 +550,7 @@ public:
     void update_egpws_alert_discrete_2 ();
     void update_egpwc_alert_discrete_3 ();
     void update_outputs ();
+    void reposition ();
 
     void update_lamps ();
     void set_lamp (Lamp lamp);
@@ -624,10 +577,11 @@ public:
       typedef deque< Sample<double> > samples_type;
       samples_type             samples;
       double                   value;
+      double                   last_update;
 
     public:
       inline TerrainClearanceFilter ()
-       : value(0) {}
+       : value(0.0), last_update(-1.0) {}
 
       double update (double agl);
       void reset ();
@@ -702,263 +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 (double volume) {}
-       virtual inline void stop () {}
-       virtual bool is_playing () = 0;
-       virtual inline void set_volume (double volume) {}
-      };
-
-      /////////////////////////////////////////////////////////////////////////
-      // MK_VIII::VoicePlayer::Voice::SampleElement ///////////////////////////
-      /////////////////////////////////////////////////////////////////////////
-
-      class SampleElement : public Element
-      {
-       SGSoundSample   *_sample;
-       double          _volume;
-
-      public:
-       inline SampleElement (SGSoundSample *sample, double volume = 1.0)
-         : _sample(sample), _volume(volume) { silence = false; }
-
-        virtual inline void play (double volume) { if (_sample) { 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 (double 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 (double 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)
-       : player(_player), volume(1.0), element(NULL) {}
-
-      ~Voice ();
-
-      inline void append (Element *_element) { elements.push_back(_element); }
-
-      void play ();
-      void stop (bool now);
-      void set_volume (double _volume);
-      void volume_changed ();
-      void update ();
-
-    private:
-      VoicePlayer *player;
-
-      double volume;
-
-      vector<Element *>                        elements;
-      vector<Element *>::iterator      iter;
-
-      inline double get_volume () const { return player->volume * player->speaker.volume * volume; }
-    };
-
-    ///////////////////////////////////////////////////////////////////////////
-    // MK_VIII::VoicePlayer (continued) ///////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-
-    struct
-    {
-      double volume;
-    } conf;
-
-    double 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)
-      : mk(device), speaker(this), voice(NULL), next_voice(NULL) {}
-
-    ~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 (double _volume);
-    void update ();
-
-    inline void bind (SGPropertyNode *node) { speaker.bind(node); }
-
-  public:
-
-    ///////////////////////////////////////////////////////////////////////////
-    // MK_VIII::VoicePlayer::Speaker //////////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-
-    class Speaker
-    {
-      VoicePlayer *player;
-
-      double   pitch;
-      float    position[3];
-      float    orientation[3];
-      float    inner_cone;
-      float    outer_cone;
-      float    outer_gain;
-      float    reference_dist;
-      float    max_dist;
-
-      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));
-      }
+      ~VoicePlayer() {}
+      void init ();
 
-    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; }
-
-      double volume;
-
-      inline Speaker (VoicePlayer *_player)
-       : player(_player),
-         volume(1),
-         pitch(1),
-         inner_cone(360),
-         outer_cone(360),
-         outer_gain(0),
-         reference_dist(3),
-         max_dist(10)
+      struct
       {
-       position[0] = 0; position[1] = 0; position[2] = 0;
-       orientation[0] = 0; orientation[1] = 0; orientation[2] = 0;
-      }
-
-      void bind (SGPropertyNode *node);
-      void update_configuration ();
-    };
-
-  private:
-    ///////////////////////////////////////////////////////////////////////////
-    // MK_VIII::VoicePlayer (continued) ///////////////////////////////////////
-    ///////////////////////////////////////////////////////////////////////////
-
-    MK_VIII *mk;
-
-    Speaker speaker;
-
-    map<string, 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:
@@ -1026,7 +766,7 @@ private:
     State state;
 
     inline SelfTestHandler (MK_VIII *device)
-      : mk(device), state(STATE_NONE), button_pressed(false) {}
+      : mk(device), button_pressed(false), state(STATE_NONE) {}
 
     inline void power_off () { stop(); }
     inline void set_inop () { stop(); }
@@ -1364,7 +1104,7 @@ private:
     } conf;
 
     inline Mode4Handler (MK_VIII *device)
-      : mk(device) {}
+      : mk(device),ab_bias(0.0),ab_expanded_bias(0.0),c_bias(0.0) {}
 
     double get_upper_agl (const EnvelopesConfiguration *c);
     void update ();
@@ -1408,7 +1148,7 @@ private:
 
   public:
     inline Mode5Handler (MK_VIII *device)
-      : mk(device) {}
+      : mk(device), soft_bias(0.0) {}
 
     void update ();
   };
@@ -1460,7 +1200,7 @@ private:
     void power_off ();
     void enter_takeoff ();
     void leave_takeoff ();
-    void set_volume (double volume);
+    void set_volume (float volume);
     bool altitude_callouts_enabled ();
     void update ();
 
@@ -1505,13 +1245,17 @@ private:
     unsigned int get_bank_angle_alerts ();
     void update_bank_angle ();
     
-    class AirportFilter : public FGAirportSearchFilter
+    class AirportFilter : public FGAirport::AirportFilter
     {
     public: 
       AirportFilter(Mode6Handler *s)
         : self(s) {}
         
-      virtual bool pass(FGAirport *a);
+      virtual bool passAirport(FGAirport *a) const;
+      
+      virtual FGPositioned::Type maxType() const {
+        return FGPositioned::AIRPORT;
+      }
       
     private:
       Mode6Handler* self;
@@ -1563,7 +1307,7 @@ private:
                                   double to_heading);
     double get_azimuth_difference (const FGRunway *_runway);
 
-    void select_runway (const FGAirport *airport, FGRunway *_runway);
+    FGRunway* select_runway (const FGAirport *airport);
     void update_runway ();
 
     void get_bias_area_edges (Position *edge,
@@ -1578,14 +1322,13 @@ private:
     bool is_tcf ();
     bool is_rfcf ();
 
-    class AirportFilter : public FGAirportSearchFilter
+    class AirportFilter : public FGAirport::AirportFilter
     {
     public: 
       AirportFilter(MK_VIII *device)
         : mk(device) {}
         
-      virtual bool pass(FGAirport *a);
-      
+      virtual bool passAirport(FGAirport *a) const;
     private:
       MK_VIII* mk;
     };
@@ -1639,4 +1382,8 @@ public:
   virtual void update (double dt);
 };
 
+#ifdef _MSC_VER
+#  pragma warning( pop )
+#endif
+
 #endif // __INSTRUMENTS_MK_VIII_HXX