]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.hxx
3bef864d9ae54a3f6d1097dfe970cffa6266f1a7
[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 STL_STRING
53 #include <vector>
54
55 FG_USING_STD(vector);
56 FG_USING_STD(string);
57
58 #define NEW_DEFAULT_MODEL_HZ 120
59
60
61 class fgOPTIONS {
62
63 public:
64
65     enum
66     {
67         FG_OPTIONS_OK = 0,
68         FG_OPTIONS_HELP = 1,
69         FG_OPTIONS_ERROR = 2
70     };
71
72     enum
73     {
74         FG_UNITS_FEET = 0,
75         FG_UNITS_METERS = 1
76     };
77
78     enum fgFogKind
79     {
80         FG_FOG_DISABLED = 0,
81         FG_FOG_FASTEST  = 1,
82         FG_FOG_NICEST   = 2
83     };
84
85     enum
86     {
87         FG_RADIUS_MIN = 1,
88         FG_RADIUS_MAX = 4
89     };
90
91     enum fgControlMode
92     {
93         FG_JOYSTICK = 0,
94         FG_KEYBOARD = 1,
95         FG_MOUSE = 2
96     };
97
98     enum fgViewMode
99     {
100         FG_VIEW_PILOT = 0,      // Pilot perspective
101         FG_VIEW_FOLLOW  = 1,    // Following in the "foot steps" so to speak
102         FG_VIEW_CHASE = 2,      // Chase
103         FG_VIEW_CIRCLING = 3,   // Circling
104         FG_VIEW_SATELLITE = 4,  // From high above
105         FG_VIEW_ANCHOR = 5,     // Drop an anchor and watch from there
106         FG_VIEW_TOWER = 6,      // From nearest tower?
107         FG_VIEW_SPOTTER = 7     // Fron a ground spotter
108     };
109
110     enum fgAutoCoordMode
111     {
112         FG_AUTO_COORD_NOT_SPECIFIED = 0,
113         FG_AUTO_COORD_DISABLED = 1,
114         FG_AUTO_COORD_ENABLED = 2
115     };
116
117     enum fgTimingOffsetType {
118         FG_TIME_SYS_OFFSET   = 0,
119         FG_TIME_GMT_OFFSET   = 1,
120         FG_TIME_LAT_OFFSET   = 2,
121         FG_TIME_SYS_ABSOLUTE = 3,
122         FG_TIME_GMT_ABSOLUTE = 4,
123         FG_TIME_LAT_ABSOLUTE = 5
124     };
125
126 private:
127
128     // The flight gear "root" directory
129     string fg_root;
130
131     // The scenery "root" directory
132     string fg_scenery;
133
134     // Starting position and orientation
135     string airport_id;  // ID of initial starting airport
136     double lon;         // starting longitude in degrees (west = -)
137     double lat;         // starting latitude in degrees (south = -)
138     double altitude;    // starting altitude in meters
139     double heading;     // heading (yaw) angle in degress (Psi)
140     double roll;        // roll angle in degrees (Phi)
141     double pitch;       // pitch angle in degrees (Theta)
142     double uBody;       // Body axis X velocity (U)
143     double vBody;       // Body axis Y velocity (V)
144     double wBody;       // Body axis Z velocity (W)
145     double vkcas;       // Calibrated airspeed, knots
146     double mach;        // Mach number
147
148     // Miscellaneous
149     bool game_mode;     // Game mode enabled/disabled
150     bool splash_screen; // show splash screen
151     bool intro_music;   // play introductory music
152     int mouse_pointer;  // show mouse pointer
153     fgControlMode control_mode; // primary control mode
154     fgAutoCoordMode auto_coordination;  // enable auto coordination
155
156     // Features
157     bool hud_status;    // HUD on/off
158     bool panel_status;  // Panel on/off
159     bool sound;         // play sound effects
160     bool anti_alias_hud;
161
162     // Flight Model options
163     int flight_model;   // Core flight model code:  jsb, larcsim, magic, etc.
164     string aircraft;    // Aircraft to model
165     int model_hz;       // number of FDM iterations per second
166     int speed_up;       // Sim mechanics run this much faster than normal speed
167     int trim;           // use the FDM trimming routine during init
168                         // <0 --notrim set, 0 no trim, >0 trim
169                         // default behavior is to enable trimming for jsbsim
170                         // disable for all other fdm's
171
172     // Rendering options
173     fgFogKind fog;      // Fog nicest/fastest/disabled
174     bool clouds;        // Enable clouds
175     double clouds_asl;  // Cloud layer height above sea level
176     double fov;         // Field of View
177     bool fullscreen;    // Full screen mode enabled/disabled
178     int shading;        // shading method, 0 = Flat, 1 = Smooth
179     bool skyblend;      // Blend sky to haze (using polygons) or just clear
180     bool textures;      // Textures enabled/disabled
181     bool wireframe;     // Wireframe mode enabled/disabled
182     int xsize, ysize;   // window size derived from geometry string
183     int bpp;            // bits per pixel
184     fgViewMode view_mode; // view mode
185
186     // Scenery options
187     int tile_radius;   // Square radius of rendered tiles (around center 
188                        // square.)
189     int tile_diameter; // Diameter of rendered tiles.  for instance
190                        // if tile_diameter = 3 then a 3 x 3 grid of tiles will 
191                        // be drawn.  Increase this to see terrain that is 
192                        // further away.
193
194     // HUD options
195     int units;         // feet or meters
196     int tris_or_culled;
197
198     // Time options
199     int time_offset;            // Use this value to change time.
200     fgTimingOffsetType time_offset_type; // Will be set to one of the
201                                 // FG_TIME_* enums, to deterine how
202                                 // time_offset should be used 
203
204     // Serial port configuration strings
205     string_list channel_options_list;
206
207     // Network options
208     bool network_olk;
209     string net_id;
210     
211 public:
212
213     fgOPTIONS();
214     ~fgOPTIONS();
215
216     // Parse a single option
217     int parse_option( const string& arg );
218
219     // Scan the command line options for an fg_root definition and set
220     // just that.
221     int scan_command_line_for_root( int argc, char **argv );
222
223     // Scan the config file for an fg_root definition and set just
224     // that.
225     int scan_config_file_for_root( const string& path );
226
227     // Parse the command line options
228     int parse_command_line( int argc, char **argv );
229
230     // Parse the command line options
231     int parse_config_file( const string& path );
232
233     // Print usage message
234     void usage ( void );
235
236     // Query functions
237     inline string get_fg_root() const { return fg_root; }
238     inline string get_fg_scenery() const { return fg_scenery; }
239     inline string get_airport_id() const { return airport_id; }
240     inline double get_lon() const { return lon; }
241     inline double get_lat() const { return lat; }
242     inline double get_altitude() const { return altitude; }
243     inline double get_heading() const { return heading; }
244     inline double get_roll() const { return roll; }
245     inline double get_pitch() const { return pitch; }
246     inline double get_uBody() const {return uBody;}
247     inline double get_vBody() const {return vBody;}
248     inline double get_wBody() const {return wBody;}
249     inline double get_vc() const {return vkcas;}
250     inline double get_mach() const {return mach;}
251         
252     inline bool get_game_mode() const { return game_mode; }
253     inline bool get_splash_screen() const { return splash_screen; }
254     inline bool get_intro_music() const { return intro_music; }
255     inline int get_mouse_pointer() const { return mouse_pointer; }
256     inline bool get_anti_alias_hud() const { return anti_alias_hud; }
257     inline fgControlMode get_control_mode() const { return control_mode; }
258     inline void set_control_mode( fgControlMode mode ) { control_mode = mode; }
259     inline fgAutoCoordMode get_auto_coordination() const { 
260         return auto_coordination;
261     }
262     inline void set_auto_coordination(fgAutoCoordMode m) { 
263         auto_coordination = m;
264     }
265     inline bool get_hud_status() const { return hud_status; }
266     inline bool get_panel_status() const { return panel_status; }
267     inline bool get_sound() const { return sound; }
268     inline int get_flight_model() const { return flight_model; }
269     inline string get_aircraft() const { return aircraft; }
270     inline int get_model_hz() const { return model_hz; }
271     inline int get_speed_up() const { return speed_up; }
272     inline void set_speed_up( int speed ) { speed_up = speed; }
273     inline int get_trim_mode(void) { return trim; }
274         
275     inline bool fog_enabled() const { return fog != FG_FOG_DISABLED; }
276     inline fgFogKind get_fog() const { return fog; }
277     inline bool get_clouds() const { return clouds; }
278     inline double get_clouds_asl() const { return clouds_asl; }
279     inline double get_fov() const { return fov; }
280     inline bool get_fullscreen() const { return fullscreen; }
281     inline int get_shading() const { return shading; }
282     inline bool get_skyblend() const { return skyblend; }
283     inline bool get_textures() const { return textures; }
284     inline bool get_wireframe() const { return wireframe; }
285     inline int get_xsize() const { return xsize; }
286     inline int get_ysize() const { return ysize; }
287     inline int get_bpp() const { return bpp; }
288     inline fgViewMode get_view_mode() const { return view_mode; }
289     inline int get_tile_radius() const { return tile_radius; }
290     inline int get_tile_diameter() const { return tile_diameter; }
291
292     inline int get_units() const { return units; }
293     inline int get_tris_or_culled() const { return tris_or_culled; }
294
295     inline int get_time_offset() const { return time_offset; }
296     inline fgTimingOffsetType  get_time_offset_type() const {
297         return time_offset_type;
298     };
299
300     inline string_list get_channel_options_list() const { 
301         return channel_options_list;
302     }
303
304     inline bool get_network_olk() const { return network_olk; }
305     inline string get_net_id() const { return net_id; }
306
307     // Update functions
308     inline void set_fg_root (const string value) { fg_root = value; }
309     inline void set_fg_scenery (const string value) { fg_scenery = value; }
310     inline void set_airport_id( const string id ) { airport_id = id; }
311     inline void set_lon (double value) { lon = value; }
312     inline void set_lat (double value) { lat = value; }
313     inline void set_altitude (double value) { altitude = value; }
314     inline void set_heading (double value) { heading = value; }
315     inline void set_roll (double value) { roll = value; }
316     inline void set_pitch (double value) { pitch = value; }
317     inline void set_uBody (double value) { uBody = value; }
318     inline void set_vBody (double value) { vBody = value; }
319     inline void set_wBody (double value) { wBody = value; }
320     inline void set_vc (double value) { vkcas = value; }
321     inline void set_mach(double value) { mach = value; }
322     inline void set_game_mode (bool value) { game_mode = value; }
323     inline void set_splash_screen (bool value) { splash_screen = value; }
324     inline void set_intro_music (bool value) { intro_music = value; }
325     inline void set_mouse_pointer (int value) { mouse_pointer = value; }
326     inline void set_anti_alias_hud (bool value) { anti_alias_hud = value; }
327     inline void set_hud_status( bool status ) { hud_status = status; }
328     inline void set_sound (bool value) { sound = value; }
329     inline void set_flight_model (int value) { flight_model = value; }
330     inline void set_aircraft (const string &ac) { aircraft = ac; }
331     inline void set_model_hz (int value) { model_hz = value; }
332     inline void set_trim_mode(int value) { trim = value; }
333     inline void set_fog (fgFogKind value) { fog = value; }
334     inline void set_clouds( bool value ) { clouds = value; }
335     inline void set_clouds_asl( double value ) { clouds_asl = value; }
336     inline void set_fov( double amount ) { fov = amount; }
337     inline void set_fullscreen (bool value) { fullscreen = value; }
338     inline void set_shading (int value) { shading = value; }
339     inline void set_skyblend (bool value) { skyblend = value; }
340     inline void set_textures( bool status ) { textures = status; }
341     inline void set_wireframe (bool status) { wireframe = status; }
342     inline void cycle_fog( void ) { 
343         if ( fog == FG_FOG_DISABLED ) {
344             fog = FG_FOG_FASTEST;
345         } else if ( fog == FG_FOG_FASTEST ) {
346             fog = FG_FOG_NICEST;
347             xglHint ( GL_FOG_HINT, GL_NICEST );
348         } else if ( fog == FG_FOG_NICEST ) {
349             fog = FG_FOG_DISABLED;
350             xglHint ( GL_FOG_HINT, GL_FASTEST );
351         }
352     }
353     void toggle_panel();
354     inline void set_xsize( int x ) { xsize = x; }
355     inline void set_ysize( int y ) { ysize = y; }
356     inline void set_view_mode (fgViewMode value) { view_mode = value; }
357     inline void set_tile_radius (int value) { tile_radius = value; }
358     inline void set_tile_diameter (int value) { tile_diameter = value; }
359     inline void set_units (int value) { units = value; }
360     inline void set_tris_or_culled (int value) { tris_or_culled = value; }
361     inline void set_time_offset (int value) { time_offset = value; }
362     inline void set_time_offset_type (fgTimingOffsetType value) {
363         time_offset_type = value;
364     }
365     inline void cycle_view_mode() { 
366         if ( view_mode == FG_VIEW_PILOT ) {
367             view_mode = FG_VIEW_FOLLOW;
368         } else if ( view_mode == FG_VIEW_FOLLOW ) {
369             view_mode = FG_VIEW_PILOT;
370         }
371     }
372
373     inline void set_network_olk( bool net ) { network_olk = net; }
374     inline void set_net_id( const string id ) { net_id = id; }
375
376 private:
377
378     void parse_control( const string& mode );
379     double parse_time( const string& time_str );
380     long int parse_date( const string& date_str );
381     double parse_degree( const string& degree_str );
382     int parse_time_offset( const string& time_str );
383     int parse_tile_radius( const string& arg );
384     int parse_fdm( const string& fm );
385     double parse_fov( const string& arg );
386     bool parse_channel( const string& type, const string& channel_str );
387 };
388
389
390 extern fgOPTIONS current_options;
391
392
393 #endif /* _OPTIONS_HXX */
394
395