1 // options.hxx -- class to handle command line options
3 // Written by Curtis Olson, started April 1998.
5 // Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
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.
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.
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.
29 # error This library requires C++
36 #include <simgear/compiler.h>
43 #include <simgear/xgl/xgl.h>
45 #if defined(FX) && defined(XMESA)
46 extern bool global_fullscreen;
49 #include <simgear/math/sg_types.hxx>
50 #include <simgear/timing/sg_time.hxx>
52 #include <FDM/flight.hxx>
54 #include "globals.hxx"
62 #define NEW_DEFAULT_MODEL_HZ 120
104 FG_VIEW_PILOT = 0, // Pilot perspective
105 FG_VIEW_FOLLOW = 1, // Following in the "foot steps" so to speak
106 FG_VIEW_CHASE = 2, // Chase
107 FG_VIEW_CIRCLING = 3, // Circling
108 FG_VIEW_SATELLITE = 4, // From high above
109 FG_VIEW_ANCHOR = 5, // Drop an anchor and watch from there
110 FG_VIEW_TOWER = 6, // From nearest tower?
111 FG_VIEW_SPOTTER = 7 // Fron a ground spotter
116 FG_AUTO_COORD_NOT_SPECIFIED = 0,
117 FG_AUTO_COORD_DISABLED = 1,
118 FG_AUTO_COORD_ENABLED = 2
121 enum fgTimingOffsetType {
122 FG_TIME_SYS_OFFSET = 0,
123 FG_TIME_GMT_OFFSET = 1,
124 FG_TIME_LAT_OFFSET = 2,
125 FG_TIME_SYS_ABSOLUTE = 3,
126 FG_TIME_GMT_ABSOLUTE = 4,
127 FG_TIME_LAT_ABSOLUTE = 5
139 // The flight gear "root" directory
142 // The scenery "root" directory
143 // string fg_scenery;
145 // Starting position and orientation
147 // These are now all SGValue pointers, but they won't stay
148 // that way forever -- it's just to ease the transition to the
149 // property manager. Gradually, references to the methods that
150 // use these variables will be culled out, and the variables
151 // and methods will be removed.
153 SGValue * airport_id; // ID of initial starting airport
154 SGValue * lon; // starting longitude in degrees (west = -)
155 SGValue * lat; // starting latitude in degrees (south = -)
156 SGValue * altitude; // starting altitude in meters
157 SGValue * heading; // heading (yaw) angle in degress (Psi)
158 SGValue * roll; // roll angle in degrees (Phi)
159 SGValue * pitch; // pitch angle in degrees (Theta)
160 SGValue * speedset; // which speed does the user want
161 SGValue * uBody; // Body axis X velocity (U)
162 SGValue * vBody; // Body axis Y velocity (V)
163 SGValue * wBody; // Body axis Z velocity (W)
164 SGValue * vNorth; // North component of vt
165 SGValue * vEast; // East component of vt
166 SGValue * vDown; // Down component of vt
167 SGValue * vkcas; // Calibrated airspeed, knots
168 SGValue * mach; // Mach number
171 SGValue * game_mode; // Game mode enabled/disabled
172 SGValue * splash_screen; // show splash screen
173 SGValue * intro_music; // play introductory music
174 SGValue * mouse_pointer; // show mouse pointer
175 SGValue * control_mode; // primary control mode
176 SGValue * auto_coordination; // enable auto coordination
179 SGValue * hud_status; // HUD on/off
180 SGValue * panel_status; // Panel on/off
181 SGValue * sound; // play sound effects
182 SGValue * anti_alias_hud;
184 // Flight Model options
185 SGValue * flight_model; // Core flight model code
186 SGValue * aircraft; // Aircraft to model
187 SGValue * model_hz; // number of FDM iterations per second
188 SGValue * speed_up; // Sim mechanics run this much faster than
190 SGValue * trim; // use the FDM trimming routine during init
191 // <0 --notrim set, 0 no trim, >0 trim
192 // default behavior is to enable trimming for
193 // jsbsim and disable for all other fdm's
196 SGValue * fog; // Fog nicest/fastest/disabled
197 SGValue * clouds; // Enable clouds
198 SGValue * clouds_asl; // Cloud layer height above sea level
199 SGValue * fullscreen; // Full screen mode enabled/disabled
200 SGValue * shading; // shading method, 0 = Flat, 1 = Smooth
201 SGValue * skyblend; // Blend sky to haze (using polygons) or
203 SGValue * textures; // Textures enabled/disabled
204 SGValue * wireframe; // Wireframe mode enabled/disabled
205 SGValue * xsize; // window size derived from geometry string
207 SGValue * bpp; // bits per pixel
208 SGValue * view_mode; // view mode
209 SGValue * default_view_offset; // default forward view offset (for use by
210 // multi-display configuration
211 SGValue * visibility; // visibilty in meters
214 SGValue * units; // feet or meters
215 SGValue * tris_or_culled;
218 SGValue * time_offset; // Use this value to change time.
219 SGValue * time_offset_type; // Will be set to one of the
220 // FG_TIME_* enums, to deterine how
221 // time_offset should be used
223 // Serial port configuration strings
224 // string_list channel_options_list;
227 SGValue * network_olk;
237 void set_default_props ();
239 // Parse a single option
240 int parse_option( const string& arg );
242 // Scan the command line options for an fg_root definition and set
244 int scan_command_line_for_root( int argc, char **argv );
246 // Scan the config file for an fg_root definition and set just
248 int scan_config_file_for_root( const string& path );
250 // Parse the command line options
251 int parse_command_line( int argc, char **argv );
253 // Parse the command line options
254 int parse_config_file( const string& path );
256 // Print usage message
260 string get_fg_root() const;
261 string get_fg_scenery() const;
262 inline string get_airport_id() const {
263 return airport_id->getStringValue();
265 inline double get_lon() const { return lon->getDoubleValue(); }
266 inline double get_lat() const { return lat->getDoubleValue(); }
267 inline double get_altitude() const { return altitude->getDoubleValue(); }
268 inline double get_heading() const { return heading->getDoubleValue(); }
269 inline double get_roll() const { return roll->getDoubleValue(); }
270 inline double get_pitch() const { return pitch->getDoubleValue(); }
271 inline fgSpeedSet get_speedset() const {
272 const string &s = speedset->getStringValue();
273 if (s == "UVW" || s == "uvw")
275 else if (s == "NED" || s == "ned")
277 else if (s == "knots" || s == "KNOTS")
279 else if (s == "mach" || s == "MACH")
284 inline double get_uBody() const {return uBody->getDoubleValue();}
285 inline double get_vBody() const {return vBody->getDoubleValue();}
286 inline double get_wBody() const {return wBody->getDoubleValue();}
287 inline double get_vNorth() const {return vNorth->getDoubleValue();}
288 inline double get_vEast() const {return vEast->getDoubleValue();}
289 inline double get_vDown() const {return vDown->getDoubleValue();}
290 inline double get_vc() const {return vkcas->getDoubleValue();}
291 inline double get_mach() const {return mach->getDoubleValue();}
293 inline bool get_game_mode() const { return game_mode->getBoolValue(); }
294 inline bool get_splash_screen() const {
295 return splash_screen->getBoolValue();
297 inline bool get_intro_music() const {
298 return intro_music->getBoolValue();
300 inline int get_mouse_pointer() const {
301 return mouse_pointer->getBoolValue();
303 inline bool get_anti_alias_hud() const {
304 return anti_alias_hud->getBoolValue();
306 inline fgControlMode get_control_mode() const {
307 const string &s = control_mode->getStringValue();
310 else if (s == "keyboard")
312 else if (s == "mouse")
317 inline void set_control_mode( fgControlMode mode ) {
318 if(mode == FG_JOYSTICK)
319 control_mode->setStringValue("joystick");
320 else if (mode == FG_KEYBOARD)
321 control_mode->setStringValue("keyboard");
322 else if (mode == FG_MOUSE)
323 control_mode->setStringValue("mouse");
325 control_mode->setStringValue("joystick");
327 inline fgAutoCoordMode get_auto_coordination() const {
328 if (auto_coordination->getBoolValue())
329 return FG_AUTO_COORD_ENABLED;
331 return FG_AUTO_COORD_DISABLED;
333 inline void set_auto_coordination(fgAutoCoordMode m) {
334 if (m == FG_AUTO_COORD_ENABLED)
335 auto_coordination->setBoolValue(true);
336 else if (m == FG_AUTO_COORD_DISABLED)
337 auto_coordination->setBoolValue(false);
339 inline bool get_hud_status() const { return hud_status->getBoolValue(); }
340 inline bool get_panel_status() const {
341 return panel_status->getBoolValue();
343 inline bool get_sound() const { return sound->getBoolValue(); }
344 inline int get_flight_model() const {
345 return parse_fdm(flight_model->getStringValue());
347 inline string get_aircraft() const { return aircraft->getStringValue(); }
348 inline int get_model_hz() const { return model_hz->getIntValue(); }
349 inline int get_speed_up() const { return speed_up->getIntValue(); }
350 inline void set_speed_up( int speed ) { speed_up->setIntValue(speed); }
351 inline int get_trim_mode(void) { return trim->getIntValue(); }
353 inline bool fog_enabled() const {
354 return fog->getStringValue() != "disabled";
356 inline fgFogKind get_fog() const {
357 const string &s = fog->getStringValue();
359 return FG_FOG_DISABLED;
360 else if (s == "fastest")
361 return FG_FOG_FASTEST;
362 else if (s == "nicest")
363 return FG_FOG_NICEST;
365 return FG_FOG_DISABLED;
367 inline bool get_clouds() const { return clouds->getBoolValue(); }
368 inline double get_clouds_asl() const {
369 return clouds_asl->getDoubleValue() * FEET_TO_METER;
371 inline bool get_fullscreen() const { return fullscreen->getBoolValue(); }
372 inline int get_shading() const { return shading->getIntValue(); }
373 inline bool get_skyblend() const { return skyblend->getBoolValue(); }
374 inline bool get_textures() const { return textures->getBoolValue(); }
375 inline bool get_wireframe() const { return wireframe->getBoolValue(); }
376 inline int get_xsize() const { return xsize->getIntValue(); }
377 inline int get_ysize() const { return ysize->getIntValue(); }
378 inline int get_bpp() const { return bpp->getIntValue(); }
379 inline fgViewMode get_view_mode() const {
380 return (fgViewMode)(view_mode->getIntValue()); // FIXME!!
382 inline double get_default_view_offset() const {
383 return default_view_offset->getDoubleValue();;
385 inline double get_default_visibility() const {
386 return visibility->getDoubleValue();
389 inline int get_units() const {
390 if (units->getStringValue() == "meters")
391 return FG_UNITS_METERS;
393 return FG_UNITS_FEET;
395 inline int get_tris_or_culled() const {
396 if (tris_or_culled->getStringValue() == "tris")
397 return 1; // FIXME: check this!!!
402 inline int get_time_offset() const { return time_offset->getIntValue(); }
403 inline fgTimingOffsetType get_time_offset_type() const {
404 const string &s = time_offset_type->getStringValue();
405 if (s == "system-offset")
406 return FG_TIME_SYS_OFFSET;
407 else if (s == "gmt-offset")
408 return FG_TIME_GMT_OFFSET;
409 else if (s == "latitude-offset")
410 return FG_TIME_LAT_OFFSET;
411 else if (s == "system")
412 return FG_TIME_SYS_ABSOLUTE;
414 return FG_TIME_GMT_ABSOLUTE;
415 else if (s == "latitude")
416 return FG_TIME_LAT_ABSOLUTE;
418 return FG_TIME_SYS_OFFSET;
421 string_list get_channel_options_list () const;
423 inline bool get_network_olk() const { return network_olk->getBoolValue(); }
424 inline string get_net_id() const { return net_id->getStringValue(); }
427 inline void set_airport_id( const string id ) {
428 airport_id->setStringValue(id);
430 inline void set_lon (double value) { lon->setDoubleValue(value); }
431 inline void set_lat (double value) { lat->setDoubleValue(value); }
432 inline void set_altitude (double value) {
433 altitude->setDoubleValue(value);
435 inline void set_heading (double value) { heading->setDoubleValue(value); }
436 inline void set_roll (double value) { roll->setDoubleValue(value); }
437 inline void set_pitch (double value) { pitch->setDoubleValue(value); }
438 inline void set_anti_alias_hud (bool value) {
439 anti_alias_hud->setBoolValue(value);
441 inline void set_hud_status( bool status ) {
442 hud_status->setBoolValue(status);
444 inline void set_flight_model (int value) {
445 if (value == FGInterface::FG_ADA)
446 flight_model->setStringValue("ada");
447 else if (value == FGInterface::FG_BALLOONSIM)
448 flight_model->setStringValue("balloon");
449 else if (value == FGInterface::FG_EXTERNAL)
450 flight_model->setStringValue("external");
451 else if (value == FGInterface::FG_JSBSIM)
452 flight_model->setStringValue("jsb");
453 else if (value == FGInterface::FG_LARCSIM)
454 flight_model->setStringValue("larcsim");
455 else if (value == FGInterface::FG_MAGICCARPET)
456 flight_model->setStringValue("magic");
458 flight_model->setStringValue("larcsim");
460 inline void set_aircraft (const string &ac) {
461 aircraft->setStringValue(ac);
463 inline void set_textures( bool status ) { textures->setBoolValue(status); }
464 inline void cycle_fog( void ) {
465 const string &s = fog->getStringValue();
466 if ( s == "disabled" ) {
467 fog->setStringValue("fastest");
468 } else if ( s == "fastest" ) {
469 fog->setStringValue("nicest");
470 glHint ( GL_FOG_HINT, GL_NICEST );
471 } else if ( s == "nicest" ) {
472 fog->setStringValue("disabled");
473 glHint ( GL_FOG_HINT, GL_FASTEST );
477 inline void set_xsize( int x ) { xsize->setIntValue(x); }
478 inline void set_ysize( int y ) { ysize->setIntValue(y); }
480 inline void set_net_id( const string id ) { net_id->setStringValue(id); }
484 void parse_control( const string& mode );
485 double parse_time( const string& time_str );
486 long int parse_date( const string& date_str );
487 double parse_degree( const string& degree_str );
488 int parse_time_offset( const string& time_str );
489 int parse_fdm( const string& fm ) const;
490 double parse_fov( const string& arg );
491 bool parse_channel( const string& type, const string& channel_str );
492 bool parse_wp( const string& arg );
493 bool parse_flightplan(const string& arg);
497 #endif /* _OPTIONS_HXX */