]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.hxx
5156481960835aff088e4fb5d274cd35a5fb2922
[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 <simgear/compiler.h>
37
38 #ifdef HAVE_WINDOWS_H
39 #  include <windows.h>
40 #endif
41
42 #include <GL/glut.h>
43 #include <simgear/xgl/xgl.h>
44
45 #if defined(FX) && defined(XMESA)
46 extern bool global_fullscreen;
47 #endif
48
49 #include <simgear/math/sg_types.hxx>
50 #include <simgear/timing/sg_time.hxx>
51
52 #include <FDM/flight.hxx>
53
54 #include "globals.hxx"
55
56 #include STL_STRING
57 #include <vector>
58
59 FG_USING_STD(vector);
60 FG_USING_STD(string);
61
62 #define NEW_DEFAULT_MODEL_HZ 120
63
64
65 class FGOptions {
66
67 public:
68
69     enum
70     {
71         FG_OPTIONS_OK = 0,
72         FG_OPTIONS_HELP = 1,
73         FG_OPTIONS_ERROR = 2
74     };
75
76     enum
77     {
78         FG_UNITS_FEET = 0,
79         FG_UNITS_METERS = 1
80     };
81
82     enum fgFogKind
83     {
84         FG_FOG_DISABLED = 0,
85         FG_FOG_FASTEST  = 1,
86         FG_FOG_NICEST   = 2
87     };
88
89     enum
90     {
91         FG_RADIUS_MIN = 1,
92         FG_RADIUS_MAX = 4
93     };
94
95     enum fgControlMode
96     {
97         FG_JOYSTICK = 0,
98         FG_KEYBOARD = 1,
99         FG_MOUSE = 2
100     };
101
102     enum fgViewMode
103     {
104         FG_VIEW_PILOT = 0,      // Pilot perspective
105         FG_VIEW_FOLLOW  = 1,    // Following in the "foot steps" so to speak
106         FG_VIEW_CHASE = 2,      // Chase
107         FG_VIEW_CIRCLING = 3,   // Circling
108         FG_VIEW_SATELLITE = 4,  // From high above
109         FG_VIEW_ANCHOR = 5,     // Drop an anchor and watch from there
110         FG_VIEW_TOWER = 6,      // From nearest tower?
111         FG_VIEW_SPOTTER = 7     // Fron a ground spotter
112     };
113
114     enum fgAutoCoordMode
115     {
116         FG_AUTO_COORD_NOT_SPECIFIED = 0,
117         FG_AUTO_COORD_DISABLED = 1,
118         FG_AUTO_COORD_ENABLED = 2
119     };
120
121     enum fgTimingOffsetType {
122         FG_TIME_SYS_OFFSET   = 0,
123         FG_TIME_GMT_OFFSET   = 1,
124         FG_TIME_LAT_OFFSET   = 2,
125         FG_TIME_SYS_ABSOLUTE = 3,
126         FG_TIME_GMT_ABSOLUTE = 4,
127         FG_TIME_LAT_ABSOLUTE = 5
128     };
129     
130     enum fgSpeedSet {
131         FG_VC    = 1,
132         FG_MACH  = 2,
133         FG_VTUVW  = 3,
134         FG_VTNED = 4
135     };
136
137 private:
138
139     // The flight gear "root" directory
140 //     string fg_root;
141
142     // The scenery "root" directory
143 //     string fg_scenery;
144
145     // Starting position and orientation
146
147     // These are now all SGValue pointers, but they won't stay
148     // that way forever -- it's just to ease the transition to the
149     // property manager.  Gradually, references to the methods that
150     // use these variables will be culled out, and the variables
151     // and methods will be removed.
152
153     SGValue * airport_id;       // ID of initial starting airport
154     SGValue * lon;              // starting longitude in degrees (west = -)
155     SGValue * lat;              // starting latitude in degrees (south = -)
156     SGValue * altitude;         // starting altitude in meters
157     SGValue * heading;          // heading (yaw) angle in degress (Psi)
158     SGValue * roll;             // roll angle in degrees (Phi)
159     SGValue * pitch;            // pitch angle in degrees (Theta)
160     SGValue * speedset;         // which speed does the user want
161     SGValue * uBody;            // Body axis X velocity (U)
162     SGValue * vBody;            // Body axis Y velocity (V)
163     SGValue * wBody;            // Body axis Z velocity (W)
164     SGValue * vNorth;           // North component of vt
165     SGValue * vEast;            // East component of vt
166     SGValue * vDown;            // Down component of vt
167     SGValue * vkcas;            // Calibrated airspeed, knots
168     SGValue * mach;             // Mach number
169
170     // Miscellaneous
171     SGValue * game_mode;        // Game mode enabled/disabled
172     SGValue * splash_screen;    // show splash screen
173     SGValue * intro_music;      // play introductory music
174     SGValue * mouse_pointer;    // show mouse pointer
175     SGValue * control_mode;     // primary control mode
176     SGValue * auto_coordination; // enable auto coordination
177
178     // Features
179     SGValue * hud_status;       // HUD on/off
180     SGValue * panel_status;     // Panel on/off
181     SGValue * sound;            // play sound effects
182     SGValue * anti_alias_hud;
183
184     // Flight Model options
185     SGValue * flight_model;     // Core flight model code
186     SGValue * aircraft;         // Aircraft to model
187     SGValue * model_hz;         // number of FDM iterations per second
188     SGValue * speed_up;         // Sim mechanics run this much faster than 
189                                 // normal speed
190     SGValue * trim;             // use the FDM trimming routine during init
191                                 // <0 --notrim set, 0 no trim, >0 trim
192                                 // default behavior is to enable trimming for 
193                                 // jsbsim and disable for all other fdm's
194
195     // Rendering options
196     SGValue * fog;              // Fog nicest/fastest/disabled
197     SGValue * clouds;           // Enable clouds
198     SGValue * clouds_asl;       // Cloud layer height above sea level
199     SGValue * fullscreen;       // Full screen mode enabled/disabled
200     SGValue * shading;          // shading method, 0 = Flat, 1 = Smooth
201     SGValue * skyblend;         // Blend sky to haze (using polygons) or 
202                                 // just clear
203     SGValue * textures;         // Textures enabled/disabled
204     SGValue * wireframe;        // Wireframe mode enabled/disabled
205     SGValue * xsize;            // window size derived from geometry string
206     SGValue * ysize;
207     SGValue * bpp;              // bits per pixel
208     SGValue * view_mode;        // view mode
209     SGValue * default_view_offset; // default forward view offset (for use by
210                                 // multi-display configuration
211     SGValue * visibility;       // visibilty in meters
212
213     // HUD options
214     SGValue * units;         // feet or meters
215     SGValue * tris_or_culled;
216
217     // Time options
218     SGValue * time_offset;      // Use this value to change time.
219     SGValue * time_offset_type; // Will be set to one of the
220                                 // FG_TIME_* enums, to deterine how
221                                 // time_offset should be used 
222
223     // Serial port configuration strings
224 //     string_list channel_options_list;
225
226     // Network options
227     SGValue * network_olk;
228     SGValue * net_id;
229
230 public:
231
232     FGOptions();
233     ~FGOptions();
234
235     void init ();
236
237     void set_default_props ();
238
239     // Parse a single option
240     int parse_option( const string& arg );
241
242     // Scan the command line options for an fg_root definition and set
243     // just that.
244     int scan_command_line_for_root( int argc, char **argv );
245
246     // Scan the config file for an fg_root definition and set just
247     // that.
248     int scan_config_file_for_root( const string& path );
249
250     // Parse the command line options
251     int parse_command_line( int argc, char **argv );
252
253     // Parse the command line options
254     int parse_config_file( const string& path );
255
256     // Print usage message
257     void usage ( void );
258
259     // Query functions
260     string get_fg_root() const;
261     string get_fg_scenery() const;
262     inline string get_airport_id() const {
263       return airport_id->getStringValue();
264     }
265     inline double get_lon() const { return lon->getDoubleValue(); }
266     inline double get_lat() const { return lat->getDoubleValue(); }
267     inline double get_altitude() const { return altitude->getDoubleValue(); }
268     inline double get_heading() const { return heading->getDoubleValue(); }
269     inline double get_roll() const { return roll->getDoubleValue(); }
270     inline double get_pitch() const { return pitch->getDoubleValue(); }
271     inline fgSpeedSet get_speedset() const { 
272       const string &s = speedset->getStringValue();
273       if (s == "UVW" || s == "uvw")
274         return FG_VTUVW;
275       else if (s == "NED" || s == "ned")
276         return FG_VTNED;
277       else if (s == "knots" || s == "KNOTS")
278         return FG_VC;
279       else if (s == "mach" || s == "MACH")
280         return FG_MACH;
281       else
282         return FG_VC;
283     }
284     inline double get_uBody() const {return uBody->getDoubleValue();}
285     inline double get_vBody() const {return vBody->getDoubleValue();}
286     inline double get_wBody() const {return wBody->getDoubleValue();}
287     inline double get_vNorth() const {return vNorth->getDoubleValue();}
288     inline double get_vEast() const {return vEast->getDoubleValue();}
289     inline double get_vDown() const {return vDown->getDoubleValue();}
290     inline double get_vc() const {return vkcas->getDoubleValue();}
291     inline double get_mach() const {return mach->getDoubleValue();}
292         
293     inline bool get_game_mode() const { return game_mode->getBoolValue(); }
294     inline bool get_splash_screen() const {
295       return splash_screen->getBoolValue();
296     }
297     inline bool get_intro_music() const {
298       return intro_music->getBoolValue();
299     }
300     inline int get_mouse_pointer() const {
301       return mouse_pointer->getBoolValue();
302     }
303     inline bool get_anti_alias_hud() const {
304       return anti_alias_hud->getBoolValue();
305     }
306     inline fgControlMode get_control_mode() const {
307       const string &s = control_mode->getStringValue();
308       if (s == "joystick")
309         return FG_JOYSTICK;
310       else if (s == "keyboard")
311         return FG_KEYBOARD;
312       else if (s == "mouse")
313         return FG_MOUSE;
314       else
315         return FG_JOYSTICK;
316     }
317     inline void set_control_mode( fgControlMode mode ) {
318       if(mode == FG_JOYSTICK)
319         control_mode->setStringValue("joystick");
320       else if (mode == FG_KEYBOARD)
321         control_mode->setStringValue("keyboard");
322       else if (mode == FG_MOUSE)
323         control_mode->setStringValue("mouse");
324       else
325         control_mode->setStringValue("joystick");
326     }
327     inline fgAutoCoordMode get_auto_coordination() const { 
328         if (auto_coordination->getBoolValue())
329           return FG_AUTO_COORD_ENABLED;
330         else
331           return FG_AUTO_COORD_DISABLED;
332     }
333     inline void set_auto_coordination(fgAutoCoordMode m) { 
334         if (m == FG_AUTO_COORD_ENABLED)
335           auto_coordination->setBoolValue(true);
336         else if (m == FG_AUTO_COORD_DISABLED)
337           auto_coordination->setBoolValue(false);
338     }
339     inline bool get_hud_status() const { return hud_status->getBoolValue(); }
340     inline bool get_panel_status() const {
341       return panel_status->getBoolValue();
342     }
343     inline bool get_sound() const { return sound->getBoolValue(); }
344     inline int get_flight_model() const {
345       return parse_fdm(flight_model->getStringValue());
346     }
347     inline string get_aircraft() const { return aircraft->getStringValue(); }
348     inline int get_model_hz() const { return model_hz->getIntValue(); }
349     inline int get_speed_up() const { return speed_up->getIntValue(); }
350     inline void set_speed_up( int speed ) { speed_up->setIntValue(speed); }
351     inline int get_trim_mode(void) { return trim->getIntValue(); }
352         
353     inline bool fog_enabled() const { 
354       return fog->getStringValue() != "disabled";
355     }
356     inline fgFogKind get_fog() const {
357       const string &s = fog->getStringValue();
358       if (s == "disabled")
359         return FG_FOG_DISABLED;
360       else if (s == "fastest")
361         return FG_FOG_FASTEST;
362       else if (s == "nicest")
363         return FG_FOG_NICEST;
364       else
365         return FG_FOG_DISABLED;
366     }
367     inline bool get_clouds() const { return clouds->getBoolValue(); }
368     inline double get_clouds_asl() const {
369       return clouds_asl->getDoubleValue() * FEET_TO_METER;
370     }
371     inline bool get_fullscreen() const { return fullscreen->getBoolValue(); }
372     inline int get_shading() const { return shading->getIntValue(); }
373     inline bool get_skyblend() const { return skyblend->getBoolValue(); }
374     inline bool get_textures() const { return textures->getBoolValue(); }
375     inline bool get_wireframe() const { return wireframe->getBoolValue(); }
376     inline int get_xsize() const { return xsize->getIntValue(); }
377     inline int get_ysize() const { return ysize->getIntValue(); }
378     inline int get_bpp() const { return bpp->getIntValue(); }
379     inline fgViewMode get_view_mode() const {
380       return (fgViewMode)(view_mode->getIntValue()); // FIXME!!
381     }
382     inline double get_default_view_offset() const {
383         return default_view_offset->getDoubleValue();;
384     }
385     inline double get_default_visibility() const {
386       return visibility->getDoubleValue();
387     }
388
389     inline int get_units() const { 
390       if (units->getStringValue() == "meters")
391         return FG_UNITS_METERS;
392       else
393         return FG_UNITS_FEET;
394     }
395     inline int get_tris_or_culled() const { 
396       if (tris_or_culled->getStringValue() == "tris")
397         return 1;               // FIXME: check this!!!
398       else
399         return 2;
400     }
401
402     inline int get_time_offset() const { return time_offset->getIntValue(); }
403     inline fgTimingOffsetType  get_time_offset_type() const {
404       const string &s = time_offset_type->getStringValue();
405       if (s == "system-offset")
406         return FG_TIME_SYS_OFFSET;
407       else if (s == "gmt-offset")
408         return FG_TIME_GMT_OFFSET;
409       else if (s == "latitude-offset")
410         return FG_TIME_LAT_OFFSET;
411       else if (s == "system")
412         return FG_TIME_SYS_ABSOLUTE;
413       else if (s == "gmt")
414         return FG_TIME_GMT_ABSOLUTE;
415       else if (s == "latitude")
416         return FG_TIME_LAT_ABSOLUTE;
417       else
418         return FG_TIME_SYS_OFFSET;
419     };
420
421     string_list get_channel_options_list () const;
422
423     inline bool get_network_olk() const { return network_olk->getBoolValue(); }
424     inline string get_net_id() const { return net_id->getStringValue(); }
425
426     // Update functions
427     inline void set_airport_id( const string id ) {
428       airport_id->setStringValue(id);
429     }
430     inline void set_lon (double value) { lon->setDoubleValue(value); }
431     inline void set_lat (double value) { lat->setDoubleValue(value); }
432     inline void set_altitude (double value) {
433       altitude->setDoubleValue(value);
434     }
435     inline void set_heading (double value) { heading->setDoubleValue(value); }
436     inline void set_roll (double value) { roll->setDoubleValue(value); }
437     inline void set_pitch (double value) { pitch->setDoubleValue(value); }
438     inline void set_anti_alias_hud (bool value) {
439       anti_alias_hud->setBoolValue(value);
440     }
441     inline void set_hud_status( bool status ) {
442       hud_status->setBoolValue(status);
443     }
444     inline void set_flight_model (int value) {
445       if (value == FGInterface::FG_ADA)
446         flight_model->setStringValue("ada");
447       else if (value == FGInterface::FG_BALLOONSIM)
448         flight_model->setStringValue("balloon");
449       else if (value == FGInterface::FG_EXTERNAL)
450         flight_model->setStringValue("external");
451       else if (value == FGInterface::FG_JSBSIM)
452         flight_model->setStringValue("jsb");
453       else if (value == FGInterface::FG_LARCSIM)
454         flight_model->setStringValue("larcsim");
455       else if (value == FGInterface::FG_MAGICCARPET)
456         flight_model->setStringValue("magic");
457       else
458         flight_model->setStringValue("larcsim");
459     }
460     inline void set_aircraft (const string &ac) {
461       aircraft->setStringValue(ac);
462     }
463     inline void set_textures( bool status ) { textures->setBoolValue(status); }
464     inline void cycle_fog( void ) { 
465         const string &s = fog->getStringValue();
466         if ( s == "disabled" ) {
467             fog->setStringValue("fastest");
468         } else if ( s == "fastest" ) {
469             fog->setStringValue("nicest");
470             glHint ( GL_FOG_HINT, GL_NICEST );
471         } else if ( s == "nicest" ) {
472             fog->setStringValue("disabled");
473             glHint ( GL_FOG_HINT, GL_FASTEST );
474         }
475     }
476     void toggle_panel();
477     inline void set_xsize( int x ) { xsize->setIntValue(x); }
478     inline void set_ysize( int y ) { ysize->setIntValue(y); }
479
480     inline void set_net_id( const string id ) { net_id->setStringValue(id); }
481
482 private:
483
484     void parse_control( const string& mode );
485     double parse_time( const string& time_str );
486     long int parse_date( const string& date_str );
487     double parse_degree( const string& degree_str );
488     int parse_time_offset( const string& time_str );
489     int parse_fdm( const string& fm ) const;
490     double parse_fov( const string& arg );
491     bool parse_channel( const string& type, const string& channel_str );
492     bool parse_wp( const string& arg );
493     bool parse_flightplan(const string& arg);
494 };
495
496
497 #endif /* _OPTIONS_HXX */
498
499