]> 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 43286b08dba2acee5f81c5f98998dd8acc9e8b18..ba2a92d5bae1d8dbd2f1cdd5f514e6b3ea9e00a8 100644 (file)
 #ifndef _CONTROLS_HXX
 #define _CONTROLS_HXX
 
+#include <simgear/misc/props.hxx>
+
+#include <Main/fgfs.hxx>
+#include <Main/globals.hxx>
 
 #ifndef __cplusplus                                                          
 # error This library requires C++
@@ -32,7 +36,8 @@
 
 // Define a structure containing the control parameters
 
-class FGControls {
+class FGControls : public FGSubsystem
+{
 
 public:
 
@@ -54,14 +59,31 @@ private:
     double elevator;
     double elevator_trim;
     double rudder;
+    double flaps;
     double 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; }
+       if ( *x > max ) { *x = max; }
+    }
+               
 public:
 
     FGControls();
     ~FGControls();
 
+    // Implementation of FGSubsystem.
+    void init ();
+    void bind ();
+    void unbind ();
+    void update ();
+
     // Reset function
     void reset_all(void);
        
@@ -70,62 +92,83 @@ public:
     inline double get_elevator() const { return elevator; }
     inline double get_elevator_trim() const { return elevator_trim; }
     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_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 ) {
        aileron = pos;
-       if ( aileron < -1.0 ) aileron = -1.0;
-       if ( aileron >  1.0 ) aileron =  1.0;
+       CLAMP( &aileron, -1.0, 1.0 );
+                       
+       // check for autocoordination
+       if ( auto_coordination->getBoolValue() ) 
+       {
+           set_rudder( aileron / 2.0 );
+       }
     }
     inline void move_aileron( double amt ) {
        aileron += amt;
-       if ( aileron < -1.0 ) aileron = -1.0;
-       if ( aileron >  1.0 ) aileron =  1.0;
+       CLAMP( &aileron, -1.0, 1.0 );
+                       
+       // check for autocoordination
+       if ( auto_coordination->getBoolValue() ) 
+       {
+           set_rudder( aileron / 2.0 );
+       }
     }
     inline void set_elevator( double pos ) {
        elevator = pos;
-       if ( elevator < -1.0 ) elevator = -1.0;
-       if ( elevator >  1.0 ) elevator =  1.0;
+       CLAMP( &elevator, -1.0, 1.0 );
     }
     inline void move_elevator( double amt ) {
        elevator += amt;
-       if ( elevator < -1.0 ) elevator = -1.0;
-       if ( elevator >  1.0 ) elevator =  1.0;
+       CLAMP( &elevator, -1.0, 1.0 );
     }
     inline void set_elevator_trim( double pos ) {
        elevator_trim = pos;
-       if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
-       if ( elevator_trim >  1.0 ) elevator_trim =  1.0;
+       CLAMP( &elevator_trim, -1.0, 1.0 );
     }
     inline void move_elevator_trim( double amt ) {
        elevator_trim += amt;
-       if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
-       if ( elevator_trim >  1.0 ) elevator_trim =  1.0;
+       CLAMP( &elevator_trim, -1.0, 1.0 );
     }
     inline void set_rudder( double pos ) {
        rudder = pos;
-       if ( rudder < -1.0 ) rudder = -1.0;
-       if ( rudder >  1.0 ) rudder =  1.0;
+       CLAMP( &rudder, -1.0, 1.0 );
     }
     inline void move_rudder( double amt ) {
        rudder += amt;
-       if ( rudder < -1.0 ) rudder = -1.0;
-       if ( rudder >  1.0 ) rudder =  1.0;
+       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 );
     }
     inline void set_throttle( int engine, double pos ) {
        if ( engine == ALL_ENGINES ) {
            for ( int i = 0; i < MAX_ENGINES; i++ ) {
                throttle[i] = pos;
-               if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
-               if ( throttle[i] >  1.0 ) throttle[i] =  1.0;
+               CLAMP( &throttle[i], 0.0, 1.0 );
            }
        } else {
            if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
                throttle[engine] = pos;
-               if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
-               if ( throttle[engine] >  1.0 ) throttle[engine] =  1.0;
+               CLAMP( &throttle[engine], 0.0, 1.0 );
            }
        }
     }
@@ -133,14 +176,64 @@ public:
        if ( engine == ALL_ENGINES ) {
            for ( int i = 0; i < MAX_ENGINES; i++ ) {
                throttle[i] += amt;
-               if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
-               if ( throttle[i] >  1.0 ) throttle[i] =  1.0;
+               CLAMP( &throttle[i], 0.0, 1.0 );
            }
        } else {
            if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
                throttle[engine] += amt;
-               if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
-               if ( throttle[engine] >  1.0 ) throttle[engine] =  1.0;
+               CLAMP( &throttle[engine], 0.0, 1.0 );
+           }
+       }
+    }
+    inline void set_mixture( int engine, double pos ) {
+       if ( engine == ALL_ENGINES ) {
+           for ( int i = 0; i < MAX_ENGINES; i++ ) {
+               mixture[i] = pos;
+               CLAMP( &mixture[i], 0.0, 1.0 );
+           }
+       } else {
+           if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
+               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 );
            }
        }
     }
@@ -148,14 +241,12 @@ public:
        if ( wheel == ALL_WHEELS ) {
            for ( int i = 0; i < MAX_WHEELS; i++ ) {
                brake[i] = pos;
-               if ( brake[i] < 0.0 ) brake[i] = 0.0;
-               if ( brake[i] >  1.0 ) brake[i] =  1.0;
+               CLAMP( &brake[i], 0.0, 1.0 );
            }
        } else {
            if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
                brake[wheel] = pos;
-               if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
-               if ( brake[wheel] >  1.0 ) brake[wheel] =  1.0;
+               CLAMP( &brake[wheel], 0.0, 1.0 );
            }
        }
     }
@@ -163,14 +254,12 @@ public:
        if ( wheel == ALL_WHEELS ) {
            for ( int i = 0; i < MAX_WHEELS; i++ ) {
                brake[i] += amt;
-               if ( brake[i] < 0.0 ) brake[i] = 0.0;
-               if ( brake[i] >  1.0 ) brake[i] =  1.0;
+               CLAMP( &brake[i], 0.0, 1.0 );
            }
        } else {
            if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
                brake[wheel] += amt;
-               if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
-               if ( brake[wheel] >  1.0 ) brake[wheel] =  1.0;
+               CLAMP( &brake[wheel], 0.0, 1.0 );
            }
        }
     }