X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FControls%2Fcontrols.hxx;h=08f840950941050133a43417096d5bc6c5c80ac5;hb=485230b443de22c97d5c4ddfda98598fb52ce98a;hp=690e9b11c6be30a5a595e876c26ee6ab556dad86;hpb=6de1139450e08653c4be1d89f65518bcd8f46541;p=flightgear.git diff --git a/src/Controls/controls.hxx b/src/Controls/controls.hxx index 690e9b11c..08f840950 100644 --- a/src/Controls/controls.hxx +++ b/src/Controls/controls.hxx @@ -55,9 +55,15 @@ private: double elevator; double elevator_trim; double rudder; + double flaps; double throttle[MAX_ENGINES]; double brake[MAX_WHEELS]; + inline void CLAMP(double *x, double min, double max ) { + if ( *x < min ) { *x = min; } + if ( *x > max ) { *x = max; } + } + public: FGControls(); @@ -71,15 +77,15 @@ 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_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 ( current_options.get_auto_coordination() == fgOPTIONS::FG_AUTO_COORD_ENABLED ) @@ -89,9 +95,8 @@ public: } 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 ( current_options.get_auto_coordination() == fgOPTIONS::FG_AUTO_COORD_ENABLED ) @@ -101,46 +106,46 @@ public: } 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 ) { + flaps = pos; + CLAMP( &flaps, 0.0, 1.0 ); + } + inline void move_flaps( double amt ) { + 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 ); } } } @@ -148,14 +153,12 @@ 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 ); } } } @@ -163,14 +166,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 ); } } } @@ -178,14 +179,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 ); } } }