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