]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.hxx
360a096ef42610bd14b2fa061524ab3466416ef3
[flightgear.git] / src / Main / options.hxx
1 // options.hxx -- class to handle command line options
2 //
3 // Written by Curtis Olson, started April 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifndef _OPTIONS_HXX
25 #define _OPTIONS_HXX
26
27
28 #ifndef __cplusplus
29 # error This library requires C++
30 #endif                                   
31
32 #ifdef HAVE_CONFIG_H
33 #  include <config.h>
34 #endif
35
36 #include <Include/compiler.h>
37
38 #ifdef HAVE_WINDOWS_H
39 #  include <windows.h>
40 #endif
41
42 #include <GL/glut.h>
43 #include <XGL/xgl.h>
44
45 #if defined(FX) && defined(XMESA)
46 extern bool global_fullscreen;
47 #endif
48
49 #include STL_STRING
50 #include <vector>
51
52 FG_USING_STD(vector);
53 FG_USING_STD(string);
54
55 typedef vector < string > str_container;
56 typedef str_container::iterator str_iterator;
57 typedef str_container::const_iterator const_str_iterator;
58
59
60 class fgOPTIONS {
61
62 public:
63
64     enum
65     {
66         FG_OPTIONS_OK = 0,
67         FG_OPTIONS_HELP = 1,
68         FG_OPTIONS_ERROR = 2
69     };
70
71     enum
72     {
73         FG_UNITS_FEET = 0,
74         FG_UNITS_METERS = 1
75     };
76
77     enum fgFogKind
78     {
79         FG_FOG_DISABLED = 0,
80         FG_FOG_FASTEST  = 1,
81         FG_FOG_NICEST   = 2
82     };
83
84     enum
85     {
86         FG_RADIUS_MIN = 1,
87         FG_RADIUS_MAX = 4
88     };
89
90     enum
91     {
92       FG_TIME_SYS_OFFSET   = 1,
93       FG_TIME_GMT_OFFSET   = 2,
94       FG_TIME_LAT_OFFSET   = 3,
95       FG_TIME_SYS_ABSOLUTE = 4,
96       FG_TIME_GMT_ABSOLUTE = 5,
97       FG_TIME_LAT_ABSOLUTE = 6
98     };
99
100     enum fgControlMode
101     {
102         FG_JOYSTICK = 0,
103         FG_KEYBOARD = 1,
104         FG_MOUSE = 2
105     };
106
107     enum fgViewMode
108     {
109         FG_VIEW_FIRST_PERSON = 0,
110         FG_VIEW_FOLLOW  = 1
111     };
112
113 private:
114
115     // The flight gear "root" directory
116     string fg_root;
117
118     // Starting position and orientation
119     string airport_id;  // ID of initial starting airport
120     double lon;         // starting longitude in degrees (west = -)
121     double lat;         // starting latitude in degrees (south = -)
122     double altitude;    // starting altitude in meters
123     double heading;     // heading (yaw) angle in degress (Psi)
124     double roll;        // roll angle in degrees (Phi)
125     double pitch;       // pitch angle in degrees (Theta)
126     double uBody;       // Body axis X velocity (U)
127     double vBody;       // Body axis Y velocity (V)
128     double wBody;       // Body axis Z velocity (W)
129
130     // Miscellaneous
131     bool game_mode;     // Game mode enabled/disabled
132     bool splash_screen; // show splash screen
133     bool intro_music;   // play introductory music
134     int mouse_pointer;  // show mouse pointer
135     bool pause;         // pause intially enabled/disabled
136     fgControlMode control_mode; // primary control mode
137
138     // Features
139     bool hud_status;    // HUD on/off
140     bool panel_status;  // Panel on/off
141     bool sound;         // play sound effects
142
143     // Flight Model options
144     int flight_model;   // Flight Model:  FG_SLEW, FG_LARCSIM, etc.
145     int model_hz;       // number of FDM iterations per second
146     int speed_up;       // Sim mechanics run this much faster than normal speed
147
148     // Rendering options
149     fgFogKind fog;      // Fog nicest/fastest/disabled
150     double fov;         // Field of View
151     bool fullscreen;    // Full screen mode enabled/disabled
152     int shading;        // shading method, 0 = Flat, 1 = Smooth
153     bool skyblend;      // Blend sky to haze (using polygons) or just clear
154     bool textures;      // Textures enabled/disabled
155     bool wireframe;     // Wireframe mode enabled/disabled
156     int xsize, ysize;   // window size derived from geometry string
157     fgViewMode view_mode; // view mode
158
159     // Scenery options
160     int tile_radius;   // Square radius of rendered tiles (around center 
161                        // square.)
162     int tile_diameter; // Diameter of rendered tiles.  for instance
163                        // if tile_diameter = 3 then a 3 x 3 grid of tiles will 
164                        // be drawn.  Increase this to see terrain that is 
165                        // further away.
166
167     // HUD options
168     int units;         // feet or meters
169     int tris_or_culled;
170
171     // Time options
172     int time_offset;            // Use this value to change time.
173     int time_offset_type;       // Will be set to one of the FG_TIME_* enums,
174                                 // To deterine how time_offset should be used 
175
176     // Serial Ports, we currently support up to four channels
177     // fgSerialPortKind port_a_kind;  // Port a kind
178     // fgSerialPortKind port_b_kind;  // Port b kind
179     // fgSerialPortKind port_c_kind;  // Port c kind
180     // fgSerialPortKind port_d_kind;  // Port d kind
181
182     // Serial port configuration strings
183     str_container port_options_list;
184
185     // Network options
186     string net_id;
187     
188 public:
189
190     fgOPTIONS();
191     ~fgOPTIONS();
192
193     // Parse a single option
194     int parse_option( const string& arg );
195
196     // Parse the command line options
197     int parse_command_line( int argc, char **argv );
198
199     // Parse the command line options
200     int parse_config_file( const string& path );
201
202     // Print usage message
203     void usage ( void );
204
205     // Query functions
206     inline string get_fg_root() const { return fg_root; }
207     inline string get_airport_id() const { return airport_id; }
208     inline double get_lon() const { return lon; }
209     inline double get_lat() const { return lat; }
210     inline double get_altitude() const { return altitude; }
211     inline double get_heading() const { return heading; }
212     inline double get_roll() const { return roll; }
213     inline double get_pitch() const { return pitch; }
214     inline double get_uBody() const {return uBody;}
215     inline double get_vBody() const {return vBody;}
216     inline double get_wBody() const {return wBody;}
217     inline bool get_game_mode() const { return game_mode; }
218     inline bool get_splash_screen() const { return splash_screen; }
219     inline bool get_intro_music() const { return intro_music; }
220     inline int get_mouse_pointer() const { return mouse_pointer; }
221     inline bool get_pause() const { return pause; }
222     inline fgControlMode get_control_mode() const { return control_mode; }
223     inline void set_control_mode( fgControlMode mode ) { control_mode = mode; }
224     inline bool get_hud_status() const { return hud_status; }
225     inline bool get_panel_status() const { return panel_status; }
226     inline bool get_sound() const { return sound; }
227     inline int get_flight_model() const { return flight_model; }
228     inline int get_model_hz() const { return model_hz; }
229     inline int get_speed_up() const { return speed_up; }
230     inline void set_speed_up( int speed ) { speed_up = speed; }
231     inline bool fog_enabled() const { return fog != FG_FOG_DISABLED; }
232     inline fgFogKind get_fog() const { return fog; }
233     inline double get_fov() const { return fov; }
234     inline bool get_fullscreen() const { return fullscreen; }
235     inline int get_shading() const { return shading; }
236     inline bool get_skyblend() const { return skyblend; }
237     inline bool get_textures() const { return textures; }
238     inline bool get_wireframe() const { return wireframe; }
239     inline int get_xsize() const { return xsize; }
240     inline int get_ysize() const { return ysize; }
241     inline fgViewMode get_view_mode() const { return view_mode; }
242     inline int get_tile_radius() const { return tile_radius; }
243     inline int get_tile_diameter() const { return tile_diameter; }
244
245     inline int get_units() const { return units; }
246     inline int get_tris_or_culled() const { return tris_or_culled; }
247
248     inline int get_time_offset() const { return time_offset; }
249     inline int get_time_offset_type() const { return time_offset_type; };
250
251     inline str_container get_port_options_list() const { 
252         return port_options_list;
253     }
254     inline string get_net_id() const { return net_id; }
255
256     // Update functions
257     inline void set_airport_id( const string id ) { airport_id = id; }
258     inline void set_hud_status( bool status ) { hud_status = status; }
259     inline void set_fov( double amount ) { fov = amount; }
260     inline void set_textures( bool status ) { textures = status; }
261     inline void cycle_fog( void ) { 
262         if ( fog == FG_FOG_DISABLED ) {
263             fog = FG_FOG_FASTEST;
264         } else if ( fog == FG_FOG_FASTEST ) {
265             fog = FG_FOG_NICEST;
266             xglHint ( GL_FOG_HINT, GL_NICEST );
267         } else if ( fog == FG_FOG_NICEST ) {
268             fog = FG_FOG_DISABLED;
269             xglHint ( GL_FOG_HINT, GL_FASTEST );
270         }
271     }
272     void toggle_panel();
273     inline void set_xsize( int x ) { xsize = x; }
274     inline void set_ysize( int y ) { ysize = y; }
275     inline void cycle_view_mode() { 
276         if ( view_mode == FG_VIEW_FIRST_PERSON ) {
277             view_mode = FG_VIEW_FOLLOW;
278         } else if ( view_mode == FG_VIEW_FOLLOW ) {
279             view_mode = FG_VIEW_FIRST_PERSON;
280         }
281     }
282
283     inline void set_net_id( const string id ) { net_id = id; }
284
285 private:
286
287     void parse_control( const string& mode );
288     double parse_time( const string& time_str );
289     long int parse_date( const string& date_str );
290     double parse_degree( const string& degree_str );
291     int parse_time_offset( const string& time_str );
292     int parse_tile_radius( const string& arg );
293     int parse_fdm( const string& fm );
294     double parse_fov( const string& arg );
295     bool parse_serial( const string& serial_str );
296 };
297
298
299 extern fgOPTIONS current_options;
300
301
302 #endif /* _OPTIONS_HXX */
303
304