]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/mk_viii.hxx
Replacement code for ATCDCL functions are in ATC/atcutils.[ch]xx. Thanks to Alex...
[flightgear.git] / src / Instrumentation / mk_viii.hxx
index 4969a137d65707948882a1324dd6ccca13521256..7d33b1ca8358c43f31f973a792d289759c13223b 100755 (executable)
 #include <simgear/sound/sample_openal.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
 
-SG_USING_STD(vector);
-SG_USING_STD(deque);
-SG_USING_STD(map);
+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/simple.hxx>
+#include <Main/globals.hxx>
+
+#ifdef _MSC_VER
+#  pragma warning( push )
+#  pragma warning( disable: 4355 )
+#endif
 
 ///////////////////////////////////////////////////////////////////////////////
 // MK_VIII ////////////////////////////////////////////////////////////////////
@@ -47,7 +54,7 @@ SG_USING_STD(map);
 class MK_VIII : public SGSubsystem
 {
   // keep in sync with Mode6Handler::altitude_callout_definitions[]
-  static const int n_altitude_callouts = 11;
+  static const unsigned n_altitude_callouts = 11;
 
   /////////////////////////////////////////////////////////////////////////////
   // MK_VIII::RawValueMethodsData /////////////////////////////////////////////
@@ -68,7 +75,7 @@ class MK_VIII : public SGSubsystem
       if (_getter)
        return (_obj.*_getter)(_data);
       else
-       return SGRawValue<VT>::DefaultValue;
+       return SGRawValue<VT>::DefaultValue();
     }
     virtual bool setValue (VT value)
     {
@@ -181,37 +188,37 @@ class MK_VIII : public SGSubsystem
   {
     MK_VIII *mk;
 
-    vector<SGPropertyNode *> tied_properties;
+    vector<SGPropertyNode_ptr> tied_properties;
 
   public:
     struct
     {
-      SGPropertyNode *ai_caged;
-      SGPropertyNode *ai_roll;
-      SGPropertyNode *ai_serviceable;
-      SGPropertyNode *altimeter_altitude;
-      SGPropertyNode *altimeter_serviceable;
-      SGPropertyNode *altitude;
-      SGPropertyNode *altitude_agl;
-      SGPropertyNode *asi_serviceable;
-      SGPropertyNode *asi_speed;
-      SGPropertyNode *autopilot_heading_lock;
-      SGPropertyNode *flaps;
-      SGPropertyNode *gear_down;
-      SGPropertyNode *latitude;
-      SGPropertyNode *longitude;
-      SGPropertyNode *nav0_cdi_serviceable;
-      SGPropertyNode *nav0_gs_distance;
-      SGPropertyNode *nav0_gs_needle_deflection;
-      SGPropertyNode *nav0_gs_serviceable;
-      SGPropertyNode *nav0_has_gs;
-      SGPropertyNode *nav0_heading_needle_deflection;
-      SGPropertyNode *nav0_in_range;
-      SGPropertyNode *nav0_nav_loc;
-      SGPropertyNode *nav0_serviceable;
-      SGPropertyNode *power;
-      SGPropertyNode *replay_state;
-      SGPropertyNode *vs;
+      SGPropertyNode_ptr ai_caged;
+      SGPropertyNode_ptr ai_roll;
+      SGPropertyNode_ptr ai_serviceable;
+      SGPropertyNode_ptr altimeter_altitude;
+      SGPropertyNode_ptr altimeter_serviceable;
+      SGPropertyNode_ptr altitude;
+      SGPropertyNode_ptr altitude_agl;
+      SGPropertyNode_ptr asi_serviceable;
+      SGPropertyNode_ptr asi_speed;
+      SGPropertyNode_ptr autopilot_heading_lock;
+      SGPropertyNode_ptr flaps;
+      SGPropertyNode_ptr gear_down;
+      SGPropertyNode_ptr latitude;
+      SGPropertyNode_ptr longitude;
+      SGPropertyNode_ptr nav0_cdi_serviceable;
+      SGPropertyNode_ptr nav0_gs_distance;
+      SGPropertyNode_ptr nav0_gs_needle_deflection;
+      SGPropertyNode_ptr nav0_gs_serviceable;
+      SGPropertyNode_ptr nav0_has_gs;
+      SGPropertyNode_ptr nav0_heading_needle_deflection;
+      SGPropertyNode_ptr nav0_in_range;
+      SGPropertyNode_ptr nav0_nav_loc;
+      SGPropertyNode_ptr nav0_serviceable;
+      SGPropertyNode_ptr power;
+      SGPropertyNode_ptr replay_state;
+      SGPropertyNode_ptr vs;
     } external_properties;
 
     inline PropertiesHandler (MK_VIII *device)
@@ -232,10 +239,16 @@ class MK_VIII : public SGSubsystem
       tie(node->getNode(relative_path, true), raw_value);
     }
 
+    PropertiesHandler() {};
+
     void init ();
     void unbind ();
   };
 
+public:
+  PropertiesHandler     properties_handler;
+
+private:
   /////////////////////////////////////////////////////////////////////////////
   // MK_VIII::PowerHandler ////////////////////////////////////////////////////
   /////////////////////////////////////////////////////////////////////////////
@@ -431,6 +444,7 @@ class MK_VIII : public SGSubsystem
   // MK_VIII::IOHandler ///////////////////////////////////////////////////////
   /////////////////////////////////////////////////////////////////////////////
 
+public:
   class IOHandler
   {
   public:
@@ -604,6 +618,8 @@ class MK_VIII : public SGSubsystem
 
     void bind (SGPropertyNode *node);
 
+    MK_VIII *mk;
+
   private:
 
     ///////////////////////////////////////////////////////////////////////////
@@ -612,7 +628,8 @@ class MK_VIII : public SGSubsystem
 
     class TerrainClearanceFilter
     {
-      deque< Sample<double> >  samples;
+      typedef deque< Sample<double> > samples_type;
+      samples_type             samples;
       double                   value;
 
     public:
@@ -627,8 +644,6 @@ class MK_VIII : public SGSubsystem
     // MK_VIII::IOHandler (continued) /////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
 
-    MK_VIII *mk;
-
     TerrainClearanceFilter terrain_clearance_filter;
 
     Lamp       _lamp;
@@ -647,7 +662,8 @@ class MK_VIII : public SGSubsystem
     bool last_landing_gear;
     bool last_real_flaps_down;
 
-    deque< Sample< Parameter<double> > > altitude_samples;
+    typedef deque< Sample< Parameter<double> > > altitude_samples_type;
+    altitude_samples_type altitude_samples;
 
     struct
     {
@@ -678,6 +694,8 @@ class MK_VIII : public SGSubsystem
                     const char *name,
                     int *output);
 
+  public:
+
     bool get_discrete_input (bool *ptr) const;
     void set_discrete_input (bool *ptr, bool value);
 
@@ -717,10 +735,10 @@ class MK_VIII : public SGSubsystem
       public:
        bool silence;
 
-       virtual inline void play (double volume) {}
+       virtual inline void play (float volume) {}
        virtual inline void stop () {}
        virtual bool is_playing () = 0;
-       virtual inline void set_volume (double volume) {}
+       virtual inline void set_volume (float volume) {}
       };
 
       /////////////////////////////////////////////////////////////////////////
@@ -729,17 +747,17 @@ class MK_VIII : public SGSubsystem
 
       class SampleElement : public Element
       {
-       SGSoundSample   *_sample;
-       double          _volume;
+       SGSharedPtr<SGSoundSample>      _sample;
+       float                           _volume;
 
       public:
-       inline SampleElement (SGSoundSample *sample, double volume = 1.0)
+       inline SampleElement (SGSharedPtr<SGSoundSample> sample, float volume = 1.0)
          : _sample(sample), _volume(volume) { silence = false; }
 
-       virtual inline void play (double volume) { set_volume(volume); _sample->play_once(); }
-       virtual inline void stop () { _sample->stop(); }
-       virtual inline bool is_playing () { return _sample->is_playing(); }
-       virtual inline void set_volume (double volume) { _sample->set_volume(volume * _volume); }
+        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); }
       };
 
       /////////////////////////////////////////////////////////////////////////
@@ -755,7 +773,7 @@ class MK_VIII : public SGSubsystem
        inline SilenceElement (double duration)
          : _duration(duration) { silence = true; }
 
-       virtual inline void play (double volume) { start_time = globals->get_sim_time_sec(); }
+       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; }
       };
 
@@ -766,7 +784,7 @@ class MK_VIII : public SGSubsystem
       Element *element;
 
       inline Voice (VoicePlayer *_player)
-       : player(_player), volume(1.0), element(NULL) {}
+        : element(NULL), player(_player), volume(1.0) {}
 
       ~Voice ();
 
@@ -774,19 +792,19 @@ class MK_VIII : public SGSubsystem
 
       void play ();
       void stop (bool now);
-      void set_volume (double _volume);
+      void set_volume (float _volume);
       void volume_changed ();
       void update ();
 
     private:
       VoicePlayer *player;
 
-      double volume;
+      float volume;
 
       vector<Element *>                        elements;
       vector<Element *>::iterator      iter;
 
-      inline double get_volume () const { return player->volume * player->speaker.volume * volume; }
+      inline float get_volume () const { return player->volume * player->speaker.volume * volume; }
     };
 
     ///////////////////////////////////////////////////////////////////////////
@@ -795,10 +813,10 @@ class MK_VIII : public SGSubsystem
 
     struct
     {
-      double volume;
+      float volume;
     } conf;
 
-    double volume;
+    float volume;
 
     Voice *voice;
     Voice *next_voice;
@@ -836,7 +854,7 @@ class MK_VIII : public SGSubsystem
     } voices;
 
     inline VoicePlayer (MK_VIII *device)
-      : mk(device), speaker(this), voice(NULL), next_voice(NULL) {}
+      : voice(NULL), next_voice(NULL),  mk(device), speaker(this) {}
 
     ~VoicePlayer ();
 
@@ -855,12 +873,12 @@ class MK_VIII : public SGSubsystem
     };
     void stop (unsigned int flags = 0);
 
-    void set_volume (double _volume);
+    void set_volume (float _volume);
     void update ();
 
     inline void bind (SGPropertyNode *node) { speaker.bind(node); }
 
-  private:
+  public:
 
     ///////////////////////////////////////////////////////////////////////////
     // MK_VIII::VoicePlayer::Speaker //////////////////////////////////////////
@@ -871,13 +889,6 @@ class MK_VIII : public SGSubsystem
       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)
@@ -890,42 +901,37 @@ class MK_VIII : public SGSubsystem
            &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; }
 
-    public:
-      double volume;
+      float 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)
+         volume(1)
       {
-       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;
 
+    SGSharedPtr<SGSampleGroup> _sgr;
     Speaker speaker;
 
-    map<string, SGSoundSample *>       samples;
+    map< string, SGSharedPtr<SGSoundSample> >  samples;
     vector<Voice *>                    _voices;
 
     bool looped;
@@ -949,6 +955,7 @@ class MK_VIII : public SGSubsystem
     inline void make_voice (Voice **voice, T1 e1, T2 e2, T3 e3, T4 e4) { make_voice(voice, e1, e2, e3); append(*voice, e4); }
   };
 
+private:
   /////////////////////////////////////////////////////////////////////////////
   // MK_VIII::SelfTestHandler /////////////////////////////////////////////////
   /////////////////////////////////////////////////////////////////////////////
@@ -1013,7 +1020,7 @@ class MK_VIII : public SGSubsystem
     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(); }
@@ -1447,7 +1454,7 @@ class MK_VIII : public SGSubsystem
     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 ();
 
@@ -1491,6 +1498,22 @@ class MK_VIII : public SGSubsystem
     bool is_high_bank_angle ();
     unsigned int get_bank_angle_alerts ();
     void update_bank_angle ();
+    
+    class AirportFilter : public FGAirport::AirportFilter
+    {
+    public: 
+      AirportFilter(Mode6Handler *s)
+        : self(s) {}
+        
+      virtual bool passAirport(FGAirport *a) const;
+      
+      virtual FGPositioned::Type maxType() const {
+        return FGPositioned::AIRPORT;
+      }
+      
+    private:
+      Mode6Handler* self;
+    };
   };
 
   /////////////////////////////////////////////////////////////////////////////
@@ -1538,8 +1561,7 @@ class MK_VIII : public SGSubsystem
                                   double to_heading);
     double get_azimuth_difference (const FGRunway *_runway);
 
-    void select_runway (const FGAirport *airport, FGRunway *_runway);
-    bool test_airport (const FGAirport *airport);
+    FGRunway* select_runway (const FGAirport *airport);
     void update_runway ();
 
     void get_bias_area_edges (Position *edge,
@@ -1554,6 +1576,16 @@ class MK_VIII : public SGSubsystem
     bool is_tcf ();
     bool is_rfcf ();
 
+    class AirportFilter : public FGAirport::AirportFilter
+    {
+    public: 
+      AirportFilter(MK_VIII *device)
+        : mk(device) {}
+        
+      virtual bool passAirport(FGAirport *a) const;
+    private:
+      MK_VIII* mk;
+    };
   public:
     struct
     {
@@ -1573,7 +1605,6 @@ class MK_VIII : public SGSubsystem
   string       name;
   int          num;
 
-  PropertiesHandler    properties_handler;
   PowerHandler         power_handler;
   SystemHandler                system_handler;
   ConfigurationModule  configuration_module;
@@ -1605,4 +1636,8 @@ public:
   virtual void update (double dt);
 };
 
+#ifdef _MSC_VER
+#  pragma warning( pop )
+#endif
+
 #endif // __INSTRUMENTS_MK_VIII_HXX