]> git.mxchange.org Git - flightgear.git/blobdiff - src/Controls/controls.hxx
- adjusted for no-value constructor for FGPanel
[flightgear.git] / src / Controls / controls.hxx
index ea859bb9913bcd1a46fa747f2259a5da8121e723..ba2a92d5bae1d8dbd2f1cdd5f514e6b3ea9e00a8 100644 (file)
 #ifndef _CONTROLS_HXX
 #define _CONTROLS_HXX
 
-#include <Main/options.hxx>
+#include <simgear/misc/props.hxx>
+
+#include <Main/fgfs.hxx>
+#include <Main/globals.hxx>
 
 #ifndef __cplusplus                                                          
 # error This library requires C++
@@ -33,7 +36,8 @@
 
 // Define a structure containing the control parameters
 
-class FGControls {
+class FGControls : public FGSubsystem
+{
 
 public:
 
@@ -57,8 +61,12 @@ private:
     double rudder;
     double flaps;
     double throttle[MAX_ENGINES];
-    double trimmed_throttle[MAX_ENGINES];
+    double mixture[MAX_ENGINES];
+    double prop_advance[MAX_ENGINES];
     double brake[MAX_WHEELS];
+    bool throttle_idle;
+
+    SGPropertyNode * auto_coordination;
 
     inline void CLAMP(double *x, double min, double max ) {
        if ( *x < min ) { *x = min; }
@@ -70,6 +78,12 @@ public:
     FGControls();
     ~FGControls();
 
+    // Implementation of FGSubsystem.
+    void init ();
+    void bind ();
+    void unbind ();
+    void update ();
+
     // Reset function
     void reset_all(void);
        
@@ -80,10 +94,11 @@ public:
     inline double get_rudder() const { return rudder; }
     inline double get_flaps() const { return flaps; }
     inline double get_throttle(int engine) const { return throttle[engine]; }
-    inline double get_brake(int wheel) const { return brake[wheel]; }
-    inline double get_trimmed_throttle(int engine) const {
-       return trimmed_throttle[engine];
+    inline double get_mixture(int engine) const { return mixture[engine]; }
+    inline double get_prop_advance(int engine) const {
+       return prop_advance[engine];
     }
+    inline double get_brake(int wheel) const { return brake[wheel]; }
 
     // Update functions
     inline void set_aileron( double pos ) {
@@ -91,8 +106,7 @@ public:
        CLAMP( &aileron, -1.0, 1.0 );
                        
        // check for autocoordination
-       if ( current_options.get_auto_coordination() == 
-            fgOPTIONS::FG_AUTO_COORD_ENABLED ) 
+       if ( auto_coordination->getBoolValue() ) 
        {
            set_rudder( aileron / 2.0 );
        }
@@ -102,8 +116,7 @@ public:
        CLAMP( &aileron, -1.0, 1.0 );
                        
        // check for autocoordination
-       if ( current_options.get_auto_coordination() == 
-            fgOPTIONS::FG_AUTO_COORD_ENABLED ) 
+       if ( auto_coordination->getBoolValue() ) 
        {
            set_rudder( aileron / 2.0 );
        }
@@ -133,10 +146,16 @@ public:
        CLAMP( &rudder, -1.0, 1.0 );
     }
     inline void set_flaps( double pos ) {
+       if ( flaps != pos ) {
+           globals->get_soundmgr()->play_once( "flaps" );
+       }
        flaps = pos;
        CLAMP( &flaps, 0.0, 1.0 );
     }
     inline void move_flaps( double amt ) {
+       if ( fabs(amt) > 0.0 ) {
+           globals->get_soundmgr()->play_once( "flaps" );
+       }
        flaps += amt;
        CLAMP( &flaps, 0.0, 1.0 );
     }
@@ -153,29 +172,68 @@ public:
            }
        }
     }
-    inline void set_trimmed_throttle( int engine, double pos ) {
+    inline void move_throttle( int engine, double amt ) {
        if ( engine == ALL_ENGINES ) {
            for ( int i = 0; i < MAX_ENGINES; i++ ) {
-               trimmed_throttle[i] = pos;
-               CLAMP( &trimmed_throttle[i], 0.0, 1.0 );
+               throttle[i] += amt;
+               CLAMP( &throttle[i], 0.0, 1.0 );
            }
        } else {
            if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
-               trimmed_throttle[engine] = pos;
-               CLAMP( &trimmed_throttle[engine], 0.0, 1.0 );
+               throttle[engine] += amt;
+               CLAMP( &throttle[engine], 0.0, 1.0 );
            }
        }
     }
-    inline void move_throttle( int engine, double amt ) {
+    inline void set_mixture( int engine, double pos ) {
        if ( engine == ALL_ENGINES ) {
            for ( int i = 0; i < MAX_ENGINES; i++ ) {
-               throttle[i] += amt;
-               CLAMP( &throttle[i], 0.0, 1.0 );
+               mixture[i] = pos;
+               CLAMP( &mixture[i], 0.0, 1.0 );
            }
        } else {
            if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
-               throttle[engine] += amt;
-               CLAMP( &throttle[engine], 0.0, 1.0 );
+               mixture[engine] = pos;
+               CLAMP( &mixture[engine], 0.0, 1.0 );
+           }
+       }
+    }
+    inline void move_mixture( int engine, double amt ) {
+       if ( engine == ALL_ENGINES ) {
+           for ( int i = 0; i < MAX_ENGINES; i++ ) {
+               mixture[i] += amt;
+               CLAMP( &mixture[i], 0.0, 1.0 );
+           }
+       } else {
+           if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
+               mixture[engine] += amt;
+               CLAMP( &mixture[engine], 0.0, 1.0 );
+           }
+       }
+    }
+    inline void set_prop_advance( int engine, double pos ) {
+       if ( engine == ALL_ENGINES ) {
+           for ( int i = 0; i < MAX_ENGINES; i++ ) {
+               prop_advance[i] = pos;
+               CLAMP( &prop_advance[i], 0.0, 1.0 );
+           }
+       } else {
+           if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
+               prop_advance[engine] = pos;
+               CLAMP( &prop_advance[engine], 0.0, 1.0 );
+           }
+       }
+    }
+    inline void move_prop_advance( int engine, double amt ) {
+       if ( engine == ALL_ENGINES ) {
+           for ( int i = 0; i < MAX_ENGINES; i++ ) {
+               prop_advance[i] += amt;
+               CLAMP( &prop_advance[i], 0.0, 1.0 );
+           }
+       } else {
+           if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
+               prop_advance[engine] += amt;
+               CLAMP( &prop_advance[engine], 0.0, 1.0 );
            }
        }
     }