]> git.mxchange.org Git - flightgear.git/blob - Main/options.hxx
Support for an arbitrary number of serial ports.
[flightgear.git] / 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 // (Log is kept at end of this file)
23
24
25 #ifndef _OPTIONS_HXX
26 #define _OPTIONS_HXX
27
28
29 #ifndef __cplusplus
30 # error This library requires C++
31 #endif                                   
32
33 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #ifdef HAVE_WINDOWS_H
38 #  include <windows.h>
39 #endif
40
41 #include <GL/glut.h>
42 #include <XGL/xgl.h>
43
44 #include <string>
45 #include <Include/compiler.h>
46 FG_USING_STD(string);
47
48 #include <vector>                                                               
49 #include "Include/fg_stl_config.h"                                              
50
51 #ifdef NEEDNAMESPACESTD                                                         
52 using namespace std;                                                            
53 #endif                                                                          
54
55 #include "fg_serial.hxx"
56
57
58 typedef vector < string > str_container;
59 typedef str_container::iterator str_iterator;
60 typedef str_container::const_iterator const_str_iterator;
61
62
63 class fgOPTIONS {
64
65 public:
66
67     enum
68     {
69         FG_OPTIONS_OK = 0,
70         FG_OPTIONS_HELP = 1,
71         FG_OPTIONS_ERROR = 2
72     };
73
74     enum
75     {
76         FG_UNITS_FEET = 0,
77         FG_UNITS_METERS = 1
78     };
79
80     enum fgFogKind
81     {
82         FG_FOG_DISABLED = 0,
83         FG_FOG_FASTEST  = 1,
84         FG_FOG_NICEST   = 2
85     };
86
87     enum
88     {
89         FG_RADIUS_MIN = 1,
90         FG_RADIUS_MAX = 4
91     };
92
93 private:
94
95     // The flight gear "root" directory
96     string fg_root;
97
98     // Starting position and orientation
99     string airport_id;  // ID of initial starting airport
100     double lon;         // starting longitude in degrees (west = -)
101     double lat;         // starting latitude in degrees (south = -)
102     double altitude;    // starting altitude in meters
103     double heading;     // heading (yaw) angle in degress (Psi)
104     double roll;        // roll angle in degrees (Phi)
105     double pitch;       // pitch angle in degrees (Theta)
106
107     // Miscellaneous
108     bool game_mode;     // Game mode enabled/disabled
109     bool splash_screen; // show splash screen
110     bool intro_music;   // play introductory music
111     int mouse_pointer;  // show mouse pointer
112     bool pause;         // pause intially enabled/disabled
113
114     // Features
115     bool hud_status;    // HUD on/off
116     bool panel_status;  // Panel on/off
117     bool sound;         // play sound effects
118
119     // Flight Model options
120     int flight_model;   // Flight Model:  FG_SLEW, FG_LARCSIM, etc.
121
122     // Rendering options
123     fgFogKind fog;      // Fog nicest/fastest/disabled
124     double fov;         // Field of View
125     bool fullscreen;    // Full screen mode enabled/disabled
126     int shading;        // shading method, 0 = Flat, 1 = Smooth
127     bool skyblend;      // Blend sky to haze (using polygons) or just clear
128     bool textures;      // Textures enabled/disabled
129     bool wireframe;     // Wireframe mode enabled/disabled
130     int xsize, ysize;   // window size derived from geometry string
131
132     // Scenery options
133     int tile_radius;   // Square radius of rendered tiles (around center 
134                        // square.)
135     int tile_diameter; // Diameter of rendered tiles.  for instance
136                        // if tile_diameter = 3 then a 3 x 3 grid of tiles will 
137                        // be drawn.  Increase this to see terrain that is 
138                        // further away.
139
140     // HUD options
141     int units;         // feet or meters
142     int tris_or_culled;
143
144     // Time options
145     int time_offset;   // Offset true time by this many seconds
146
147     // Serial Ports, we currently support up to four channels
148     // fgSerialPortKind port_a_kind;  // Port a kind
149     // fgSerialPortKind port_b_kind;  // Port b kind
150     // fgSerialPortKind port_c_kind;  // Port c kind
151     // fgSerialPortKind port_d_kind;  // Port d kind
152
153     // Serial port configuration strings
154     str_container port_options_list;
155     
156 public:
157
158     fgOPTIONS();
159     ~fgOPTIONS();
160
161     // Parse a single option
162     int parse_option( const string& arg );
163
164     // Parse the command line options
165     int parse_command_line( int argc, char **argv );
166
167     // Parse the command line options
168     int parse_config_file( const string& path );
169
170     // Print usage message
171     void usage ( void );
172
173     // Query functions
174     inline string get_fg_root() const { return fg_root; }
175     inline string get_airport_id() const { return airport_id; }
176     inline double get_lon() const { return lon; }
177     inline double get_lat() const { return lat; }
178     inline double get_altitude() const { return altitude; }
179     inline double get_heading() const { return heading; }
180     inline double get_roll() const { return roll; }
181     inline double get_pitch() const { return pitch; }
182     inline bool get_game_mode() const { return game_mode; }
183     inline bool get_splash_screen() const { return splash_screen; }
184     inline bool get_intro_music() const { return intro_music; }
185     inline int get_mouse_pointer() const { return mouse_pointer; }
186     inline bool get_pause() const { return pause; }
187     inline bool get_hud_status() const { return hud_status; }
188     inline bool get_panel_status() const { return panel_status; }
189     inline bool get_sound() const { return sound; }
190     inline int get_flight_model() const { return flight_model; }
191     inline bool fog_enabled() const { return fog != FG_FOG_DISABLED; }
192     inline fgFogKind get_fog() const { return fog; }
193     inline double get_fov() const { return fov; }
194     inline bool get_fullscreen() const { return fullscreen; }
195     inline int get_shading() const { return shading; }
196     inline bool get_skyblend() const { return skyblend; }
197     inline bool get_textures() const { return textures; }
198     inline bool get_wireframe() const { return wireframe; }
199     inline int get_xsize() const { return xsize; }
200     inline int get_ysize() const { return ysize; }
201     inline int get_tile_radius() const { return tile_radius; }
202     inline int get_tile_diameter() const { return tile_diameter; }
203
204     inline int get_units() const { return units; }
205     inline int get_tris_or_culled() const { return tris_or_culled; }
206
207     inline int get_time_offset() const { return time_offset; }
208
209     inline str_container get_port_options_list() const { 
210         return port_options_list;
211     }
212
213     // Update functions
214     inline void set_hud_status( bool status ) { hud_status = status; }
215     inline void set_fov( double amount ) { fov = amount; }
216     inline void set_textures( bool status ) { textures = status; }
217     inline void cycle_fog( void ) { 
218         if ( fog == FG_FOG_DISABLED ) {
219             fog = FG_FOG_FASTEST;
220         } else if ( fog == FG_FOG_FASTEST ) {
221             fog = FG_FOG_NICEST;
222             xglHint ( GL_FOG_HINT, GL_NICEST );
223         } else if ( fog == FG_FOG_NICEST ) {
224             fog = FG_FOG_DISABLED;
225             xglHint ( GL_FOG_HINT, GL_FASTEST );
226         }
227     }
228     inline void set_xsize( int x ) { xsize= x; }
229     inline void set_ysize( int y ) { xsize= y; }
230
231 private:
232
233     double parse_time( const string& time_str );
234     double parse_degree( const string& degree_str );
235     int parse_time_offset( const string& time_str );
236     int parse_tile_radius( const string& arg );
237     int parse_flight_model( const string& fm );
238     double parse_fov( const string& arg );
239     bool parse_serial( const string& serial_str );
240 };
241
242
243 extern fgOPTIONS current_options;
244
245
246 #endif /* _OPTIONS_HXX */
247
248
249 // $Log$
250 // Revision 1.24  1998/11/25 01:34:01  curt
251 // Support for an arbitrary number of serial ports.
252 //
253 // Revision 1.23  1998/11/23 21:49:05  curt
254 // Borland portability tweaks.
255 //
256 // Revision 1.22  1998/11/20 01:02:38  curt
257 // Try to detect Mesa/Glide/Voodoo and chose the appropriate resolution.
258 //
259 // Revision 1.21  1998/11/16 14:00:04  curt
260 // Added pow() macro bug work around.
261 // Added support for starting FGFS at various resolutions.
262 // Added some initial serial port support.
263 // Specify default log levels in main().
264 //
265 // Revision 1.20  1998/11/02 23:04:05  curt
266 // HUD units now display in feet by default with meters being a command line
267 // option.
268 //
269 // Revision 1.19  1998/10/25 14:08:49  curt
270 // Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
271 //
272 // Revision 1.18  1998/09/17 18:35:31  curt
273 // Added F8 to toggle fog and F9 to toggle texturing.
274 //
275 // Revision 1.17  1998/09/08 21:40:10  curt
276 // Fixes by Charlie Hotchkiss.
277 //
278 // Revision 1.16  1998/08/27 17:02:08  curt
279 // Contributions from Bernie Bright <bbright@c031.aone.net.au>
280 // - use strings for fg_root and airport_id and added methods to return
281 //   them as strings,
282 // - inlined all access methods,
283 // - made the parsing functions private methods,
284 // - deleted some unused functions.
285 // - propogated some of these changes out a bit further.
286 //
287 // Revision 1.15  1998/08/24 20:11:15  curt
288 // Added i/I to toggle full vs. minimal HUD.
289 // Added a --hud-tris vs --hud-culled option.
290 // Moved options accessor funtions to options.hxx.
291 //
292 // Revision 1.14  1998/08/20 15:10:35  curt
293 // Added GameGLUT support.
294 //
295 // Revision 1.13  1998/07/30 23:48:29  curt
296 // Output position & orientation when pausing.
297 // Eliminated libtool use.
298 // Added options to specify initial position and orientation.
299 // Changed default fov to 55 degrees.
300 // Added command line option to start in paused or unpaused state.
301 //
302 // Revision 1.12  1998/07/27 18:41:26  curt
303 // Added a pause command "p"
304 // Fixed some initialization order problems between pui and glut.
305 // Added an --enable/disable-sound option.
306 //
307 // Revision 1.11  1998/07/13 21:01:39  curt
308 // Wrote access functions for current fgOPTIONS.
309 //
310 // Revision 1.10  1998/07/06 21:34:20  curt
311 // Added an enable/disable splash screen option.
312 // Added an enable/disable intro music option.
313 // Added an enable/disable instrument panel option.
314 // Added an enable/disable mouse pointer option.
315 // Added using namespace std for compilers that support this.
316 //
317 // Revision 1.9  1998/06/27 16:54:34  curt
318 // Replaced "extern displayInstruments" with a entry in fgOPTIONS.
319 // Don't change the view port when displaying the panel.
320 //
321 // Revision 1.8  1998/05/16 13:08:36  curt
322 // C++ - ified views.[ch]xx
323 // Shuffled some additional view parameters into the fgVIEW class.
324 // Changed tile-radius to tile-diameter because it is a much better
325 //   name.
326 // Added a WORLD_TO_EYE transformation to views.cxx.  This allows us
327 //  to transform world space to eye space for view frustum culling.
328 //
329 // Revision 1.7  1998/05/13 18:29:59  curt
330 // Added a keyboard binding to dynamically adjust field of view.
331 // Added a command line option to specify fov.
332 // Adjusted terrain color.
333 // Root path info moved to fgOPTIONS.
334 // Added ability to parse options out of a config file.
335 //
336 // Revision 1.6  1998/05/06 03:16:26  curt
337 // Added an averaged global frame rate counter.
338 // Added an option to control tile radius.
339 //
340 // Revision 1.5  1998/05/03 00:47:32  curt
341 // Added an option to enable/disable full-screen mode.
342 //
343 // Revision 1.4  1998/04/30 12:34:19  curt
344 // Added command line rendering options:
345 //   enable/disable fog/haze
346 //   specify smooth/flat shading
347 //   disable sky blending and just use a solid color
348 //   enable wireframe drawing mode
349 //
350 // Revision 1.3  1998/04/28 01:20:23  curt
351 // Type-ified fgTIME and fgVIEW.
352 // Added a command line option to disable textures.
353 //
354 // Revision 1.2  1998/04/25 15:11:13  curt
355 // Added an command line option to set starting position based on airport ID.
356 //
357 // Revision 1.1  1998/04/24 00:49:21  curt
358 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
359 // Trying out some different option parsing code.
360 // Some code reorganization.
361 //
362 //