X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FControls%2Fcontrols.hxx;h=51bb4328c88337788b4ff7d3016cd508fa5f0e56;hb=b17e1bb7c081f2dd03eae7d75079680234cba79c;hp=54405b7619e26a415afd2b09b5d51beef2cd48d9;hpb=7a2ef1d57c330eb6265487a14a70b9633cf9991f;p=flightgear.git diff --git a/src/Controls/controls.hxx b/src/Controls/controls.hxx index 54405b761..51bb4328c 100644 --- a/src/Controls/controls.hxx +++ b/src/Controls/controls.hxx @@ -24,7 +24,10 @@ #ifndef _CONTROLS_HXX #define _CONTROLS_HXX -#include
+#include + +#include
+#include
#ifndef __cplusplus # error This library requires C++ @@ -33,168 +36,116 @@ // Define a structure containing the control parameters -class FGControls { +class FGControls : public FGSubsystem +{ public: - enum - { + enum { ALL_ENGINES = -1, MAX_ENGINES = 10 }; - enum - { + enum { ALL_WHEELS = -1, MAX_WHEELS = 3 }; + enum { + ALL_TANKS = -1, + MAX_TANKS = 4 + }; + private: double aileron; + double aileron_trim; double elevator; double elevator_trim; double rudder; + double rudder_trim; double flaps; double throttle[MAX_ENGINES]; + double mixture[MAX_ENGINES]; + double prop_advance[MAX_ENGINES]; + double parking_brake; double brake[MAX_WHEELS]; + int magnetos[MAX_ENGINES]; bool throttle_idle; + bool starter[MAX_ENGINES]; + bool fuel_selector[MAX_TANKS]; + bool gear_down; + + 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 (double dt); + // Reset function void reset_all(void); // Query functions inline double get_aileron() const { return aileron; } + inline double get_aileron_trim() const { return aileron_trim; } 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_rudder_trim() const { return rudder_trim; } 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_parking_brake() const { return parking_brake; } inline double get_brake(int wheel) const { return brake[wheel]; } + inline int get_magnetos(int engine) const { return magnetos[engine]; } + inline bool get_starter(int engine) const { return starter[engine]; } + inline bool get_fuel_selector(int tank) const { + return fuel_selector[tank]; + } + inline bool get_gear_down() const { return gear_down; } // Update functions - inline void set_aileron( double pos ) { - aileron = pos; - CLAMP( &aileron, -1.0, 1.0 ); - - // check for autocoordination - if ( current_options.get_auto_coordination() == - fgOPTIONS::FG_AUTO_COORD_ENABLED ) - { - set_rudder( aileron / 2.0 ); - } - } - inline void move_aileron( double amt ) { - aileron += amt; - CLAMP( &aileron, -1.0, 1.0 ); - - // check for autocoordination - if ( current_options.get_auto_coordination() == - fgOPTIONS::FG_AUTO_COORD_ENABLED ) - { - set_rudder( aileron / 2.0 ); - } - } - inline void set_elevator( double pos ) { - elevator = pos; - CLAMP( &elevator, -1.0, 1.0 ); - } - inline void move_elevator( double amt ) { - elevator += amt; - CLAMP( &elevator, -1.0, 1.0 ); - } - inline void set_elevator_trim( double pos ) { - elevator_trim = pos; - CLAMP( &elevator_trim, -1.0, 1.0 ); - } - inline void move_elevator_trim( double amt ) { - elevator_trim += amt; - CLAMP( &elevator_trim, -1.0, 1.0 ); - } - inline void set_rudder( double pos ) { - rudder = pos; - CLAMP( &rudder, -1.0, 1.0 ); - } - inline void move_rudder( double amt ) { - rudder += amt; - 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; - CLAMP( &throttle[i], 0.0, 1.0 ); - } - } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - throttle[engine] = pos; - CLAMP( &throttle[engine], 0.0, 1.0 ); - } - } - } - inline void move_throttle( int engine, double amt ) { - if ( engine == ALL_ENGINES ) { - for ( int i = 0; i < MAX_ENGINES; i++ ) { - throttle[i] += amt; - CLAMP( &throttle[i], 0.0, 1.0 ); - } - } else { - if ( (engine >= 0) && (engine < MAX_ENGINES) ) { - throttle[engine] += amt; - CLAMP( &throttle[engine], 0.0, 1.0 ); - } - } - } - inline void set_brake( int wheel, double pos ) { - if ( wheel == ALL_WHEELS ) { - for ( int i = 0; i < MAX_WHEELS; i++ ) { - brake[i] = pos; - CLAMP( &brake[i], 0.0, 1.0 ); - } - } else { - if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) { - brake[wheel] = pos; - CLAMP( &brake[wheel], 0.0, 1.0 ); - } - } - } - inline void move_brake( int wheel, double amt ) { - if ( wheel == ALL_WHEELS ) { - for ( int i = 0; i < MAX_WHEELS; i++ ) { - brake[i] += amt; - CLAMP( &brake[i], 0.0, 1.0 ); - } - } else { - if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) { - brake[wheel] += amt; - CLAMP( &brake[wheel], 0.0, 1.0 ); - } - } - } + void set_aileron( double pos ); + void move_aileron( double amt ); + void set_aileron_trim( double pos ); + void move_aileron_trim( double amt ); + void set_elevator( double pos ); + void move_elevator( double amt ); + void set_elevator_trim( double pos ); + void move_elevator_trim( double amt ); + void set_rudder( double pos ); + void move_rudder( double amt ); + void set_rudder_trim( double pos ); + void move_rudder_trim( double amt ); + void set_flaps( double pos ); + void move_flaps( double amt ); + void set_throttle( int engine, double pos ); + void move_throttle( int engine, double amt ); + void set_mixture( int engine, double pos ); + void move_mixture( int engine, double amt ); + void set_prop_advance( int engine, double pos ); + void move_prop_advance( int engine, double amt ); + void set_magnetos( int engine, int pos ); + void move_magnetos( int engine, int amt ); + void set_starter( int engine, bool flag ); + void set_fuel_selector( int tank, bool pos ); + void set_parking_brake( double pos ); + void set_brake( int wheel, double pos ); + void move_brake( int wheel, double amt ); + void set_gear_down( bool gear ); }; -extern FGControls controls; - - #endif // _CONTROLS_HXX