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