]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.hxx
Allow aircraft model file to be specified from the command line.
[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 <Include/fg_types.hxx>
50
51 #include STL_STRING
52 #include <vector>
53
54 FG_USING_STD(vector);
55 FG_USING_STD(string);
56
57 class fgOPTIONS {
58
59 public:
60
61     enum
62     {
63         FG_OPTIONS_OK = 0,
64         FG_OPTIONS_HELP = 1,
65         FG_OPTIONS_ERROR = 2
66     };
67
68     enum
69     {
70         FG_UNITS_FEET = 0,
71         FG_UNITS_METERS = 1
72     };
73
74     enum fgFogKind
75     {
76         FG_FOG_DISABLED = 0,
77         FG_FOG_FASTEST  = 1,
78         FG_FOG_NICEST   = 2
79     };
80
81     enum
82     {
83         FG_RADIUS_MIN = 1,
84         FG_RADIUS_MAX = 4
85     };
86
87     enum
88     {
89       FG_TIME_SYS_OFFSET   = 1,
90       FG_TIME_GMT_OFFSET   = 2,
91       FG_TIME_LAT_OFFSET   = 3,
92       FG_TIME_SYS_ABSOLUTE = 4,
93       FG_TIME_GMT_ABSOLUTE = 5,
94       FG_TIME_LAT_ABSOLUTE = 6
95     };
96
97     enum fgControlMode
98     {
99         FG_JOYSTICK = 0,
100         FG_KEYBOARD = 1,
101         FG_MOUSE = 2
102     };
103
104     enum fgViewMode
105     {
106         FG_VIEW_PILOT = 0,      // Pilot perspective
107         FG_VIEW_FOLLOW  = 1,    // Following in the "foot steps" so to speak
108         FG_VIEW_CHASE = 2,      // Chase
109         FG_VIEW_CIRCLING = 3,   // Circling
110         FG_VIEW_SATELLITE = 4,  // From high above
111         FG_VIEW_ANCHOR = 5,     // Drop an anchor and watch from there
112         FG_VIEW_TOWER = 6,      // From nearest tower?
113         FG_VIEW_SPOTTER = 7     // Fron a ground spotter
114     };
115
116     enum fgAutoCoordMode
117     {
118         FG_AUTO_COORD_NOT_SPECIFIED = 0,
119         FG_AUTO_COORD_DISABLED = 1,
120         FG_AUTO_COORD_ENABLED = 2
121     };
122
123 private:
124
125     // The flight gear "root" directory
126     string fg_root;
127
128     // Starting position and orientation
129     string airport_id;  // ID of initial starting airport
130     double lon;         // starting longitude in degrees (west = -)
131     double lat;         // starting latitude in degrees (south = -)
132     double altitude;    // starting altitude in meters
133     double heading;     // heading (yaw) angle in degress (Psi)
134     double roll;        // roll angle in degrees (Phi)
135     double pitch;       // pitch angle in degrees (Theta)
136     double uBody;       // Body axis X velocity (U)
137     double vBody;       // Body axis Y velocity (V)
138     double wBody;       // Body axis Z velocity (W)
139
140     // Miscellaneous
141     bool game_mode;     // Game mode enabled/disabled
142     bool splash_screen; // show splash screen
143     bool intro_music;   // play introductory music
144     int mouse_pointer;  // show mouse pointer
145     bool pause;         // pause intially enabled/disabled
146     fgControlMode control_mode; // primary control mode
147     fgAutoCoordMode auto_coordination;  // enable auto coordination
148
149     // Features
150     bool hud_status;    // HUD on/off
151     bool panel_status;  // Panel on/off
152     bool sound;         // play sound effects
153
154     // Flight Model options
155     int flight_model;   // Flight Model:  FG_SLEW, FG_LARCSIM, etc.
156     int model_hz;       // number of FDM iterations per second
157     int speed_up;       // Sim mechanics run this much faster than normal speed
158
159     // Rendering options
160     fgFogKind fog;      // Fog nicest/fastest/disabled
161     bool clouds;        // Enable clouds
162     double clouds_asl;  // Cloud layer height above sea level
163     double fov;         // Field of View
164     bool fullscreen;    // Full screen mode enabled/disabled
165     int shading;        // shading method, 0 = Flat, 1 = Smooth
166     bool skyblend;      // Blend sky to haze (using polygons) or just clear
167     bool textures;      // Textures enabled/disabled
168     bool wireframe;     // Wireframe mode enabled/disabled
169     int xsize, ysize;   // window size derived from geometry string
170     fgViewMode view_mode; // view mode
171
172     // Scenery options
173     int tile_radius;   // Square radius of rendered tiles (around center 
174                        // square.)
175     int tile_diameter; // Diameter of rendered tiles.  for instance
176                        // if tile_diameter = 3 then a 3 x 3 grid of tiles will 
177                        // be drawn.  Increase this to see terrain that is 
178                        // further away.
179
180     // HUD options
181     int units;         // feet or meters
182     int tris_or_culled;
183
184     // Time options
185     int time_offset;            // Use this value to change time.
186     int time_offset_type;       // Will be set to one of the FG_TIME_* enums,
187                                 // To deterine how time_offset should be used 
188
189     // Serial port configuration strings
190     string_list channel_options_list;
191
192     // Network options
193     string net_id;
194     
195 public:
196
197     fgOPTIONS();
198     ~fgOPTIONS();
199
200     // Parse a single option
201     int parse_option( const string& arg );
202
203     // Parse the command line options
204     int parse_command_line( int argc, char **argv );
205
206     // Parse the command line options
207     int parse_config_file( const string& path );
208
209     // Print usage message
210     void usage ( void );
211
212     // Query functions
213     inline string get_fg_root() const { return fg_root; }
214     inline string get_airport_id() const { return airport_id; }
215     inline double get_lon() const { return lon; }
216     inline double get_lat() const { return lat; }
217     inline double get_altitude() const { return altitude; }
218     inline double get_heading() const { return heading; }
219     inline double get_roll() const { return roll; }
220     inline double get_pitch() const { return pitch; }
221     inline double get_uBody() const {return uBody;}
222     inline double get_vBody() const {return vBody;}
223     inline double get_wBody() const {return wBody;}
224     inline bool get_game_mode() const { return game_mode; }
225     inline bool get_splash_screen() const { return splash_screen; }
226     inline bool get_intro_music() const { return intro_music; }
227     inline int get_mouse_pointer() const { return mouse_pointer; }
228     inline bool get_pause() const { return pause; }
229     inline fgControlMode get_control_mode() const { return control_mode; }
230     inline void set_control_mode( fgControlMode mode ) { control_mode = mode; }
231     inline fgAutoCoordMode get_auto_coordination() const { 
232         return auto_coordination;
233     }
234     inline void set_auto_coordination(fgAutoCoordMode m) { 
235         auto_coordination = m;
236     }
237     inline bool get_hud_status() const { return hud_status; }
238     inline bool get_panel_status() const { return panel_status; }
239     inline bool get_sound() const { return sound; }
240     inline int get_flight_model() const { return flight_model; }
241     inline int get_model_hz() const { return model_hz; }
242     inline int get_speed_up() const { return speed_up; }
243     inline void set_speed_up( int speed ) { speed_up = speed; }
244     inline bool fog_enabled() const { return fog != FG_FOG_DISABLED; }
245     inline fgFogKind get_fog() const { return fog; }
246     inline bool get_clouds() const { return clouds; }
247     inline double get_clouds_asl() const { return clouds_asl; }
248     inline double get_fov() const { return fov; }
249     inline bool get_fullscreen() const { return fullscreen; }
250     inline int get_shading() const { return shading; }
251     inline bool get_skyblend() const { return skyblend; }
252     inline bool get_textures() const { return textures; }
253     inline bool get_wireframe() const { return wireframe; }
254     inline int get_xsize() const { return xsize; }
255     inline int get_ysize() const { return ysize; }
256     inline fgViewMode get_view_mode() const { return view_mode; }
257     inline int get_tile_radius() const { return tile_radius; }
258     inline int get_tile_diameter() const { return tile_diameter; }
259
260     inline int get_units() const { return units; }
261     inline int get_tris_or_culled() const { return tris_or_culled; }
262
263     inline int get_time_offset() const { return time_offset; }
264     inline int get_time_offset_type() const { return time_offset_type; };
265
266     inline string_list get_channel_options_list() const { 
267         return channel_options_list;
268     }
269     inline string get_net_id() const { return net_id; }
270
271     // Update functions
272     inline void set_airport_id( const string id ) { airport_id = id; }
273     inline void set_hud_status( bool status ) { hud_status = status; }
274     inline void set_clouds( bool value ) { clouds = value; }
275     inline void set_clouds_asl( double value ) { clouds_asl = value; }
276     inline void set_fov( double amount ) { fov = amount; }
277     inline void set_textures( bool status ) { textures = status; }
278     inline void cycle_fog( void ) { 
279         if ( fog == FG_FOG_DISABLED ) {
280             fog = FG_FOG_FASTEST;
281         } else if ( fog == FG_FOG_FASTEST ) {
282             fog = FG_FOG_NICEST;
283             xglHint ( GL_FOG_HINT, GL_NICEST );
284         } else if ( fog == FG_FOG_NICEST ) {
285             fog = FG_FOG_DISABLED;
286             xglHint ( GL_FOG_HINT, GL_FASTEST );
287         }
288     }
289     void toggle_panel();
290     inline void set_xsize( int x ) { xsize = x; }
291     inline void set_ysize( int y ) { ysize = y; }
292     inline void cycle_view_mode() { 
293         if ( view_mode == FG_VIEW_PILOT ) {
294             view_mode = FG_VIEW_FOLLOW;
295         } else if ( view_mode == FG_VIEW_FOLLOW ) {
296             view_mode = FG_VIEW_PILOT;
297         }
298     }
299
300     inline void set_net_id( const string id ) { net_id = id; }
301
302 private:
303
304     void parse_control( const string& mode );
305     double parse_time( const string& time_str );
306     long int parse_date( const string& date_str );
307     double parse_degree( const string& degree_str );
308     int parse_time_offset( const string& time_str );
309     int parse_tile_radius( const string& arg );
310     int parse_fdm( const string& fm );
311     double parse_fov( const string& arg );
312     bool parse_channel( const string& type, const string& channel_str );
313 };
314
315
316 extern fgOPTIONS current_options;
317
318
319 #endif /* _OPTIONS_HXX */
320
321