From: curt Date: Sun, 25 Oct 1998 14:08:37 +0000 (+0000) Subject: Turned "struct fgCONTROLS" into a class, with inlined accessor functions. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bab1b9c2e58a1e9a1de64d0738d0e4fa42aba459;p=flightgear.git Turned "struct fgCONTROLS" into a class, with inlined accessor functions. --- diff --git a/Aircraft/aircraft.cxx b/Aircraft/aircraft.cxx index d2ff48cae..21c9a3518 100644 --- a/Aircraft/aircraft.cxx +++ b/Aircraft/aircraft.cxx @@ -38,30 +38,37 @@ void fgAircraftInit( void ) { fgPrintf( FG_AIRCRAFT, FG_INFO, "Initializing Aircraft structure\n" ); current_aircraft.flight = &cur_flight_params; - current_aircraft.controls = &cur_control_params; + current_aircraft.controls = &controls; } // Display various parameters to stdout void fgAircraftOutputCurrent(fgAIRCRAFT *a) { fgFLIGHT *f; - fgCONTROLS *c; f = a->flight; - c = a->controls; fgPrintf( FG_FLIGHT, FG_DEBUG, "Pos = (%.2f,%.2f,%.2f) (Phi,Theta,Psi)=(%.2f,%.2f,%.2f)\n", FG_Longitude * 3600.0 * RAD_TO_DEG, FG_Latitude * 3600.0 * RAD_TO_DEG, FG_Altitude, FG_Phi, FG_Theta, FG_Psi); + + double elevator = controls.get_elevator(); + double aileron = controls.get_aileron(); + double rudder = controls.get_rudder(); + double throttle = controls.get_throttle( 0 ); + fgPrintf( FG_FLIGHT, FG_DEBUG, "Kts = %.0f Elev = %.2f, Aileron = %.2f, Rudder = %.2f Power = %.2f\n", - FG_V_equiv_kts, FG_Elevator, FG_Aileron, FG_Rudder, FG_Throttle[0]); + FG_V_equiv_kts, elevator, aileron,rudder, throttle ); } // $Log$ +// Revision 1.3 1998/10/25 14:08:37 curt +// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. +// // Revision 1.2 1998/10/17 01:33:52 curt // C++ ifying ... // diff --git a/Autopilot/autopilot.cxx b/Autopilot/autopilot.cxx index f5a64710f..663a5e45b 100644 --- a/Autopilot/autopilot.cxx +++ b/Autopilot/autopilot.cxx @@ -57,45 +57,6 @@ // They should eventually be member functions of the aircraft. // -static double get_throttleval( void ) -{ - fgCONTROLS *pcontrols; - - pcontrols = current_aircraft.controls; - return pcontrols->throttle[0]; // Hack limiting to one engine -} - -static double get_aileronval( void ) -{ - fgCONTROLS *pcontrols; - - pcontrols = current_aircraft.controls; - return pcontrols->aileron; -} - -static double get_elevatorval( void ) -{ - fgCONTROLS *pcontrols; - - pcontrols = current_aircraft.controls; - return pcontrols->elevator; -} - -static double get_elev_trimval( void ) -{ - fgCONTROLS *pcontrols; - - pcontrols = current_aircraft.controls; - return pcontrols->elevator_trim; -} - -static double get_rudderval( void ) -{ - fgCONTROLS *pcontrols; - - pcontrols = current_aircraft.controls; - return pcontrols->rudder; -} static double get_speed( void ) { @@ -290,8 +251,8 @@ int fgAPRun( void ) APData->MaxAileron ); } - fgAileronSet(AileronSet); - fgRudderSet(0.0); + controls.set_aileron( AileronSet ); + controls.set_rudder( 0.0 ); } // altitude hold or terrain follow enabled? @@ -350,7 +311,7 @@ int fgAPRun( void ) if ( total_adj > 0.6 ) { total_adj = 0.6; } if ( total_adj < -0.2 ) { total_adj = -0.2; } - fgElevSet( total_adj ); + controls.set_elevator( total_adj ); } // auto throttle enabled? @@ -385,7 +346,7 @@ int fgAPRun( void ) if ( total_adj > 1.0 ) { total_adj = 1.0; } if ( total_adj < 0.0 ) { total_adj = 0.0; } - fgThrottleSet( 0, total_adj ); + controls.set_throttle( fgCONTROLS::FG_ALL_ENGINES, total_adj ); } /* diff --git a/Cockpit/cockpit.cxx b/Cockpit/cockpit.cxx index e4c77d2f8..827202e8c 100644 --- a/Cockpit/cockpit.cxx +++ b/Cockpit/cockpit.cxx @@ -113,42 +113,27 @@ double get_long_min( void ) double get_throttleval( void ) { - fgCONTROLS *pcontrols; - - pcontrols = current_aircraft.controls; - return pcontrols->throttle[0]; // Hack limiting to one engine + return controls.get_throttle( 0 ); // Hack limiting to one engine } double get_aileronval( void ) { - fgCONTROLS *pcontrols; - - pcontrols = current_aircraft.controls; - return pcontrols->aileron; + return controls.get_aileron(); } double get_elevatorval( void ) { - fgCONTROLS *pcontrols; - - pcontrols = current_aircraft.controls; - return pcontrols->elevator; + return controls.get_elevator(); } double get_elev_trimval( void ) { - fgCONTROLS *pcontrols; - - pcontrols = current_aircraft.controls; - return pcontrols->elevator_trim; + return controls.get_elevator_trim(); } double get_rudderval( void ) { - fgCONTROLS *pcontrols; - - pcontrols = current_aircraft.controls; - return pcontrols->rudder; + return controls.get_rudder(); } double get_speed( void ) @@ -315,6 +300,9 @@ void fgCockpitUpdate( void ) { // $Log$ +// Revision 1.20 1998/10/25 14:08:40 curt +// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. +// // Revision 1.19 1998/10/17 01:33:56 curt // C++ ifying ... // diff --git a/Controls/controls.cxx b/Controls/controls.cxx index 058d76eb8..adf5426d7 100644 --- a/Controls/controls.cxx +++ b/Controls/controls.cxx @@ -22,169 +22,38 @@ // (Log is kept at end of this file) -#include -#include +#include "controls.hxx" -fgCONTROLS cur_control_params; +fgCONTROLS controls; -void fgControlsInit( void ) { - int i; - fgCONTROLS *c; - c = current_aircraft.controls; - - FG_Elevator = 0.0; - FG_Elev_Trim = 1.969572E-03; - FG_Aileron = 0.0; - FG_Rudder = 0.0; - - for ( i = 0; i < FG_MAX_ENGINES; i++ ) { - FG_Throttle[i] = 0.0; - } - - FG_Brake_Amt = 0.0; -} - - -void fgElevMove(double amt) { - fgCONTROLS *c; - c = current_aircraft.controls; - - FG_Elevator += amt; - - if ( FG_Elevator < -1.0 ) FG_Elevator = -1.0; - if ( FG_Elevator > 1.0 ) FG_Elevator = 1.0; -} - -void fgElevSet(double pos) { - fgCONTROLS *c; - c = current_aircraft.controls; - - FG_Elevator = pos; - - if ( FG_Elevator < -1.0 ) FG_Elevator = -1.0; - if ( FG_Elevator > 1.0 ) FG_Elevator = 1.0; -} - -void fgElevTrimMove(double amt) { - fgCONTROLS *c; - c = current_aircraft.controls; - - FG_Elev_Trim += amt; - - if ( FG_Elev_Trim < -1.0 ) FG_Elev_Trim = -1.0; - if ( FG_Elev_Trim > 1.0 ) FG_Elev_Trim = 1.0; -} - -void fgElevTrimSet(double pos) { - fgCONTROLS *c; - c = current_aircraft.controls; - - FG_Elev_Trim = pos; - - if ( FG_Elev_Trim < -1.0 ) FG_Elev_Trim = -1.0; - if ( FG_Elev_Trim > 1.0 ) FG_Elev_Trim = 1.0; -} - -void fgAileronMove(double amt) { - fgCONTROLS *c; - c = current_aircraft.controls; - - FG_Aileron += amt; - - if ( FG_Aileron < -1.0 ) FG_Aileron = -1.0; - if ( FG_Aileron > 1.0 ) FG_Aileron = 1.0; -} - -void fgAileronSet(double pos) { - fgCONTROLS *c; - c = current_aircraft.controls; - - FG_Aileron = pos; - - if ( FG_Aileron < -1.0 ) FG_Aileron = -1.0; - if ( FG_Aileron > 1.0 ) FG_Aileron = 1.0; -} - -void fgRudderMove(double amt) { - fgCONTROLS *c; - c = current_aircraft.controls; - - FG_Rudder += amt; - - if ( FG_Rudder < -1.0 ) FG_Rudder = -1.0; - if ( FG_Rudder > 1.0 ) FG_Rudder = 1.0; -} - -void fgRudderSet(double pos) { - fgCONTROLS *c; - c = current_aircraft.controls; - - FG_Rudder = pos; - - if ( FG_Rudder < -1.0 ) FG_Rudder = -1.0; - if ( FG_Rudder > 1.0 ) FG_Rudder = 1.0; -} - -void fgThrottleMove(int engine, double amt) { - int i; - fgCONTROLS *c; - c = current_aircraft.controls; - - if ( engine == FG_Throttle_All ) { - for ( i = 0; i < FG_MAX_ENGINES; i++ ) { - FG_Throttle[i] += amt; - if ( FG_Throttle[i] < 0.0 ) FG_Throttle[i] = 0.0; - if ( FG_Throttle[i] > 1.0 ) FG_Throttle[i] = 1.0; - } - } else { - if ( (engine >= 0) && (engine < FG_MAX_ENGINES) ) { - FG_Throttle[engine] += amt; - if ( FG_Throttle[engine] < 0.0 ) FG_Throttle[engine] = 0.0; - if ( FG_Throttle[engine] > 1.0 ) FG_Throttle[engine] = 1.0; - } +// Constructor +fgCONTROLS::fgCONTROLS() : + aileron( 0.0 ), + elevator( 0.0 ), + elevator_trim( 1.969572E-03 ), + rudder( 0.0 ) +{ + for ( int engine = 0; engine < FG_MAX_ENGINES; engine++ ) { + throttle[engine] = 0.0; } -} - -void fgThrottleSet(int engine, double pos) { - int i; - fgCONTROLS *c; - c = current_aircraft.controls; - if ( engine == FG_Throttle_All ) { - for ( i = 0; i < FG_MAX_ENGINES; i++ ) { - FG_Throttle[i] = pos; - if ( FG_Throttle[i] < 0.0 ) FG_Throttle[i] = 0.0; - if ( FG_Throttle[i] > 1.0 ) FG_Throttle[i] = 1.0; - } - } else { - if ( (engine >= 0) && (engine < FG_MAX_ENGINES) ) { - FG_Throttle[engine] = pos; - if ( FG_Throttle[engine] < 0.0 ) FG_Throttle[engine] = 0.0; - if ( FG_Throttle[engine] > 1.0 ) FG_Throttle[engine] = 1.0; - } + for ( int wheel = 0; wheel < FG_MAX_WHEELS; wheel++ ) { + brake[wheel] = 0.0; } } -double fgBrakeGet( void ) { - fgCONTROLS *c; - c = current_aircraft.controls; - - return FG_Brake_Amt; -} - - -void fgBrakeSet( double brake_amt ) { - fgCONTROLS *c; - c = current_aircraft.controls; - - FG_Brake_Amt = brake_amt; +// Destructor +fgCONTROLS::~fgCONTROLS() { } // $Log$ +// Revision 1.2 1998/10/25 14:08:41 curt +// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. +// // Revision 1.1 1998/10/18 01:51:05 curt // c++-ifying ... // diff --git a/Controls/controls.hxx b/Controls/controls.hxx index 79550732e..f9d77234e 100644 --- a/Controls/controls.hxx +++ b/Controls/controls.hxx @@ -26,7 +26,7 @@ #define _CONTROLS_HXX -#include +// #include #ifndef __cplusplus @@ -36,16 +36,143 @@ // Define a structure containing the control parameters -typedef struct { +class fgCONTROLS { + +public: + + static const int FG_ALL_ENGINES = -1; + static const int FG_MAX_ENGINES = 10; + + static const int FG_ALL_WHEELS = -1; + static const int FG_MAX_WHEELS = 3; + +private: + double aileron; double elevator; double elevator_trim; double rudder; double throttle[FG_MAX_ENGINES]; - double brake_amt; -} fgCONTROLS, *pfgControls; + double brake[FG_MAX_WHEELS]; + +public: + + fgCONTROLS(); + ~fgCONTROLS(); + + // Query functions + inline double get_aileron() const { return aileron; } + 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_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; + } + inline void move_aileron( double amt ) { + aileron += amt; + if ( aileron < -1.0 ) aileron = -1.0; + if ( aileron > 1.0 ) aileron = 1.0; + } + inline void set_elevator( double pos ) { + elevator = pos; + if ( elevator < -1.0 ) elevator = -1.0; + if ( elevator > 1.0 ) elevator = 1.0; + } + inline void move_elevator( double amt ) { + elevator += amt; + if ( elevator < -1.0 ) elevator = -1.0; + if ( elevator > 1.0 ) elevator = 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; + } + 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; + } + inline void set_rudder( double pos ) { + rudder = pos; + if ( rudder < -1.0 ) rudder = -1.0; + if ( rudder > 1.0 ) rudder = 1.0; + } + inline void move_rudder( double amt ) { + rudder += amt; + if ( rudder < -1.0 ) rudder = -1.0; + if ( rudder > 1.0 ) rudder = 1.0; + } + inline void set_throttle( int engine, double pos ) { + if ( engine == FG_ALL_ENGINES ) { + for ( int i = 0; i < FG_MAX_ENGINES; i++ ) { + throttle[i] = pos; + if ( throttle[i] < 0.0 ) throttle[i] = 0.0; + if ( throttle[i] > 1.0 ) throttle[i] = 1.0; + } + } else { + if ( (engine >= 0) && (engine < FG_MAX_ENGINES) ) { + throttle[engine] = pos; + if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0; + if ( throttle[engine] > 1.0 ) throttle[engine] = 1.0; + } + } + } + inline void move_throttle( int engine, double amt ) { + if ( engine == FG_ALL_ENGINES ) { + for ( int i = 0; i < FG_MAX_ENGINES; i++ ) { + throttle[i] += amt; + if ( throttle[i] < 0.0 ) throttle[i] = 0.0; + if ( throttle[i] > 1.0 ) throttle[i] = 1.0; + } + } else { + if ( (engine >= 0) && (engine < FG_MAX_ENGINES) ) { + throttle[engine] += amt; + if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0; + if ( throttle[engine] > 1.0 ) throttle[engine] = 1.0; + } + } + } + inline void set_brake( int wheel, double pos ) { + if ( wheel == FG_ALL_WHEELS ) { + for ( int i = 0; i < FG_MAX_WHEELS; i++ ) { + brake[i] = pos; + if ( brake[i] < 0.0 ) brake[i] = 0.0; + if ( brake[i] > 1.0 ) brake[i] = 1.0; + } + } else { + if ( (wheel >= 0) && (wheel < FG_MAX_WHEELS) ) { + brake[wheel] = pos; + if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0; + if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0; + } + } + } + inline void move_brake( int wheel, double amt ) { + if ( wheel == FG_ALL_WHEELS ) { + for ( int i = 0; i < FG_MAX_WHEELS; i++ ) { + brake[i] += amt; + if ( brake[i] < 0.0 ) brake[i] = 0.0; + if ( brake[i] > 1.0 ) brake[i] = 1.0; + } + } else { + if ( (wheel >= 0) && (wheel < FG_MAX_WHEELS) ) { + brake[wheel] += amt; + if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0; + if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0; + } + } + } +}; + +/* #define FG_Elevator c->elevator #define FG_Aileron c->aileron #define FG_Rudder c->rudder @@ -53,24 +180,12 @@ typedef struct { #define FG_Throttle_All -1 #define FG_Elev_Trim c->elevator_trim #define FG_Brake_Amt c->brake_amt - -/* -#define Left_button cockpit_.left_pb_on_stick -#define Right_button cockpit_.right_pb_on_stick -#define First_trigger cockpit_.trig_pos_1 -#define Second_trigger cockpit_.trig_pos_2 -#define Left_trim cockpit_.left_trim -#define Right_trim cockpit_.right_trim -#define SB_extend cockpit_.sb_extend -#define SB_retract cockpit_.sb_retract -#define Gear_sel_up cockpit_.gear_sel_up */ +extern fgCONTROLS controls; -extern fgCONTROLS cur_control_params; - +/* void fgControlsInit( void ); - void fgElevMove(double amt); void fgElevSet(double pos); void fgElevTrimMove(double amt); @@ -83,12 +198,15 @@ void fgThrottleMove(int engine, double amt); void fgThrottleSet(int engine, double pos); void fgBrakeSet( double brake_amt ); double fgBrakeGet( void ); - +*/ #endif // _CONTROLS_HXX // $Log$ +// Revision 1.2 1998/10/25 14:08:42 curt +// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. +// // Revision 1.1 1998/10/18 01:51:07 curt // c++-ifying ... // diff --git a/FDM/LaRCsim.cxx b/FDM/LaRCsim.cxx index 8adc23b40..3230274f3 100644 --- a/FDM/LaRCsim.cxx +++ b/FDM/LaRCsim.cxx @@ -78,16 +78,13 @@ int fgLaRCsimUpdate(fgFLIGHT *f, int multiloop) { // Convert from the fgFLIGHT struct to the LaRCsim generic_ struct int fgFlight_2_LaRCsim (fgFLIGHT *f) { - fgCONTROLS *c; - c = current_aircraft.controls; - - Lat_control = FG_Aileron; - Long_control = FG_Elevator; - Long_trim = FG_Elev_Trim; - Rudder_pedal = FG_Rudder; - Throttle_pct = FG_Throttle[0]; - Brake_pct = FG_Brake_Amt; + Lat_control = controls.get_aileron(); + Long_control = controls.get_elevator(); + Long_trim = controls.get_elevator_trim(); + Rudder_pedal = controls.get_rudder(); + Throttle_pct = controls.get_throttle( 0 ); + Brake_pct = controls.get_brake( 0 ); Mass = FG_Mass; I_xx = FG_I_xx; @@ -440,6 +437,9 @@ int fgLaRCsim_2_Flight (fgFLIGHT *f) { // $Log$ +// Revision 1.3 1998/10/25 14:08:43 curt +// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. +// // Revision 1.2 1998/10/17 01:34:11 curt // C++ ifying ... // diff --git a/Joystick/joystick.cxx b/Joystick/joystick.cxx index 0cba4f6e5..a95f971cf 100644 --- a/Joystick/joystick.cxx +++ b/Joystick/joystick.cxx @@ -86,21 +86,18 @@ int fgJoystickInit( void ) { // update the control parameters based on joystick intput int fgJoystickRead( void ) { - fgCONTROLS *c; int b; - c = current_aircraft.controls; - if ( ! js0->notWorking() ) { js0->read( &b, js_ax0 ) ; - fgAileronSet( js_ax0[0] ); - fgElevSet( -js_ax0[1] ); + controls.set_aileron( js_ax0[0] ); + controls.set_elevator( -js_ax0[1] ); } if ( ! js1->notWorking() ) { js1->read( &b, js_ax1 ) ; - fgRudderSet( js_ax1[0] ); - fgThrottleSet(FG_Throttle_All, -js_ax1[1] * 1.05 ); + controls.set_rudder( js_ax1[0] ); + controls.set_throttle( fgCONTROLS::FG_ALL_ENGINES, -js_ax1[1] * 1.05 ); } return 1; @@ -108,6 +105,9 @@ int fgJoystickRead( void ) { // $Log$ +// Revision 1.3 1998/10/25 14:08:44 curt +// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. +// // Revision 1.2 1998/10/25 10:56:25 curt // Completely rewritten to use Steve Baker's joystick interface class. // diff --git a/Main/GLUTkey.cxx b/Main/GLUTkey.cxx index 357bcab0c..85b6969bf 100644 --- a/Main/GLUTkey.cxx +++ b/Main/GLUTkey.cxx @@ -69,7 +69,6 @@ static void local_update_sky_and_lighting_params( void ) { // Handle keyboard events void GLUTkey(unsigned char k, int x, int y) { - fgCONTROLS *c; fgFLIGHT *f; fgTIME *t; fgVIEW *v; @@ -77,7 +76,6 @@ void GLUTkey(unsigned char k, int x, int y) { float fov, tmp; static bool winding_ccw = true; - c = current_aircraft.controls; f = current_aircraft.flight; t = &cur_time_params; v = ¤t_view; @@ -178,46 +176,46 @@ void GLUTkey(unsigned char k, int x, int y) { fgPrintf( FG_INPUT, FG_DEBUG, "\n"); switch (k) { case 50: // numeric keypad 2 - fgElevMove(-0.05); + controls.move_elevator(-0.05); return; case 56: // numeric keypad 8 - fgElevMove(0.05); + controls.move_elevator(0.05); return; case 49: // numeric keypad 1 - fgElevTrimMove(-0.001); + controls.move_elevator_trim(-0.001); return; case 55: // numeric keypad 7 - fgElevTrimMove(0.001); + controls.move_elevator_trim(0.001); return; case 52: // numeric keypad 4 - fgAileronMove(-0.05); + controls.move_aileron(-0.05); return; case 54: // numeric keypad 6 - fgAileronMove(0.05); + controls.move_aileron(0.05); return; case 48: // numeric keypad Ins - fgRudderMove(-0.05); + controls.move_rudder(-0.05); return; case 13: // numeric keypad Enter - fgRudderMove(0.05); + controls.move_rudder(0.05); return; case 53: // numeric keypad 5 - fgAileronSet(0.0); - fgElevSet(0.0); - fgRudderSet(0.0); + controls.set_aileron(0.0); + controls.set_elevator(0.0); + controls.set_rudder(0.0); return; case 57: // numeric keypad 9 (Pg Up) - fgThrottleMove(0, 0.01); + controls.move_throttle( fgCONTROLS::FG_ALL_ENGINES, 0.01 ); return; case 51: // numeric keypad 3 (Pg Dn) - fgThrottleMove(0, -0.01); + controls.move_throttle( fgCONTROLS::FG_ALL_ENGINES, -0.01 ); return; case 98: // b key int b_ret; double b_set; - b_ret = int( fgBrakeGet() ); + b_ret = int( controls.get_brake( 0 ) ); b_set = double(!b_ret); - fgBrakeSet(b_set); + controls.set_brake( fgCONTROLS::FG_ALL_WHEELS, b_set); return; case 104: // h key HUD_brightkey( false ); @@ -351,39 +349,39 @@ void GLUTspecialkey(int k, int x, int y) { //exit(1); return; case GLUT_KEY_UP: - fgElevMove(0.05); + controls.move_elevator(0.05); return; case GLUT_KEY_DOWN: - fgElevMove(-0.05); + controls.move_elevator(-0.05); return; case GLUT_KEY_LEFT: - fgAileronMove(-0.05); + controls.move_aileron(-0.05); return; case GLUT_KEY_RIGHT: - fgAileronMove(0.05); + controls.move_aileron(0.05); return; case GLUT_KEY_HOME: // numeric keypad 1 - fgElevTrimMove(0.001); + controls.move_elevator_trim(0.001); return; case GLUT_KEY_END: // numeric keypad 7 - fgElevTrimMove(-0.001); + controls.move_elevator_trim(-0.001); return; case GLUT_KEY_INSERT: // numeric keypad Ins - fgRudderMove(-0.05); + controls.move_rudder(-0.05); return; case 13: // numeric keypad Enter - fgRudderMove(0.05); + controls.move_rudder(0.05); return; case 53: // numeric keypad 5 - fgAileronSet(0.0); - fgElevSet(0.0); - fgRudderSet(0.0); + controls.set_aileron(0.0); + controls.set_elevator(0.0); + controls.set_rudder(0.0); return; case GLUT_KEY_PAGE_UP: // numeric keypad 9 (Pg Up) - fgThrottleMove(0, 0.01); + controls.move_throttle( fgCONTROLS::FG_ALL_ENGINES, 0.01 ); return; case GLUT_KEY_PAGE_DOWN: // numeric keypad 3 (Pg Dn) - fgThrottleMove(0, -0.01); + controls.move_throttle( fgCONTROLS::FG_ALL_ENGINES, -0.01 ); return; } } @@ -391,6 +389,9 @@ void GLUTspecialkey(int k, int x, int y) { // $Log$ +// Revision 1.30 1998/10/25 14:08:46 curt +// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. +// // Revision 1.29 1998/10/20 14:58:57 curt // Ctrl-R now reverses default polygon winding so I can see if a hole in the // terrain is a result of improper winding, or if it is just an empty hole. diff --git a/Main/GLUTmain.cxx b/Main/GLUTmain.cxx index 4aa25ddc2..d7f420e59 100644 --- a/Main/GLUTmain.cxx +++ b/Main/GLUTmain.cxx @@ -460,7 +460,6 @@ static const double alt_adjust_m = alt_adjust_ft * FEET_TO_METER; // What should we do when we have nothing else to do? Let's get ready // for the next move and update the display? static void fgMainLoop( void ) { - fgCONTROLS *c; fgFLIGHT *f; fgGENERAL *g; fgTIME *t; @@ -469,7 +468,6 @@ static void fgMainLoop( void ) { int i; double accum; - c = &cur_control_params; f = current_aircraft.flight; g = &general; t = &cur_time_params; @@ -577,7 +575,7 @@ static void fgMainLoop( void ) { // Run audio scheduler #ifdef ENABLE_AUDIO_SUPPORT if ( current_options.get_sound() && audio_sched->working() ) { - double param = c->throttle[0] * 2.0 + 1.0; + double param = controls.get_throttle( 0 ) * 2.0 + 1.0; pitch_envelope.setStep ( 0, 0.01, param ); volume_envelope.setStep ( 0, 0.01, param ); @@ -894,6 +892,9 @@ int main( int argc, char **argv ) { // $Log$ +// Revision 1.61 1998/10/25 14:08:47 curt +// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. +// // Revision 1.60 1998/10/25 10:57:18 curt // Changes to use the new joystick library if it is available. // diff --git a/Main/options.hxx b/Main/options.hxx index fbf9e8002..1c6620894 100644 --- a/Main/options.hxx +++ b/Main/options.hxx @@ -1,4 +1,3 @@ -// // options.hxx -- class to handle command line options // // Written by Curtis Olson, started April 1998. @@ -48,8 +47,11 @@ using namespace std; #endif + class fgOPTIONS { + public: + enum { FG_OPTIONS_OK = 0, @@ -137,41 +139,41 @@ public: void usage ( void ); // Query functions - string get_fg_root() const { return fg_root; } - string get_airport_id() const { return airport_id; } - double get_lon() const { return lon; } - double get_lat() const { return lat; } - double get_altitude() const { return altitude; } - double get_heading() const { return heading; } - double get_roll() const { return roll; } - double get_pitch() const { return pitch; } - bool get_game_mode() const { return game_mode; } - bool get_splash_screen() const { return splash_screen; } - bool get_intro_music() const { return intro_music; } - int get_mouse_pointer() const { return mouse_pointer; } - bool get_pause() const { return pause; } - bool get_hud_status() const { return hud_status; } - bool get_panel_status() const { return panel_status; } - bool get_sound() const { return sound; } - int get_flight_model() const { return flight_model; } - bool fog_enabled() const { return fog != FG_FOG_DISABLED; } - fgFogKind get_fog() const { return fog; } - double get_fov() const { return fov; } - bool get_fullscreen() const { return fullscreen; } - int get_shading() const { return shading; } - bool get_skyblend() const { return skyblend; } - bool get_textures() const { return textures; } - bool get_wireframe() const { return wireframe; } - int get_tile_radius() const { return tile_radius; } - int get_tile_diameter() const { return tile_diameter; } - int get_time_offset() const { return time_offset; } - int get_tris_or_culled() const { return tris_or_culled; } + inline string get_fg_root() const { return fg_root; } + inline string get_airport_id() const { return airport_id; } + inline double get_lon() const { return lon; } + inline double get_lat() const { return lat; } + inline double get_altitude() const { return altitude; } + inline double get_heading() const { return heading; } + inline double get_roll() const { return roll; } + inline double get_pitch() const { return pitch; } + inline bool get_game_mode() const { return game_mode; } + inline bool get_splash_screen() const { return splash_screen; } + inline bool get_intro_music() const { return intro_music; } + inline int get_mouse_pointer() const { return mouse_pointer; } + inline bool get_pause() const { return pause; } + inline bool get_hud_status() const { return hud_status; } + inline bool get_panel_status() const { return panel_status; } + inline bool get_sound() const { return sound; } + inline int get_flight_model() const { return flight_model; } + inline bool fog_enabled() const { return fog != FG_FOG_DISABLED; } + inline fgFogKind get_fog() const { return fog; } + inline double get_fov() const { return fov; } + inline bool get_fullscreen() const { return fullscreen; } + inline int get_shading() const { return shading; } + inline bool get_skyblend() const { return skyblend; } + inline bool get_textures() const { return textures; } + inline bool get_wireframe() const { return wireframe; } + inline int get_tile_radius() const { return tile_radius; } + inline int get_tile_diameter() const { return tile_diameter; } + inline int get_time_offset() const { return time_offset; } + inline int get_tris_or_culled() const { return tris_or_culled; } // Update functions - void set_hud_status( bool status ) { hud_status = status; } - void set_fov( double amount ) { fov = amount; } - void set_textures( bool status ) { textures = status; } - void cycle_fog( void ) { + inline void set_hud_status( bool status ) { hud_status = status; } + inline void set_fov( double amount ) { fov = amount; } + inline void set_textures( bool status ) { textures = status; } + inline void cycle_fog( void ) { if ( fog == FG_FOG_DISABLED ) { fog = FG_FOG_FASTEST; } else if ( fog == FG_FOG_FASTEST ) { @@ -201,6 +203,9 @@ extern fgOPTIONS current_options; // $Log$ +// Revision 1.19 1998/10/25 14:08:49 curt +// Turned "struct fgCONTROLS" into a class, with inlined accessor functions. +// // Revision 1.18 1998/09/17 18:35:31 curt // Added F8 to toggle fog and F9 to toggle texturing. //