1 // options.cxx -- 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.
28 #if defined(FX) && defined(XMESA)
29 bool global_fullscreen = true;
32 #include <simgear/compiler.h>
34 #include <math.h> // rint()
36 #include <stdlib.h> // atof(), atoi()
41 #include <simgear/constants.h>
42 #include <simgear/debug/logstream.hxx>
43 #include <simgear/misc/fgstream.hxx>
44 #include <simgear/misc/props.hxx>
45 #include <simgear/timing/sg_time.hxx>
47 #include <Include/general.hxx>
48 #include <Airports/simple.hxx>
49 #include <Cockpit/cockpit.hxx>
50 #include <FDM/flight.hxx>
51 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
53 # include <NetworkOLK/network.h>
56 #include "fg_init.hxx"
57 #include "globals.hxx"
58 #include "options.hxx"
61 FG_USING_NAMESPACE(std);
64 extern void fgReshape( int width, int height );
67 atof( const string& str )
71 // -dw- if ::atof is called, then we get an infinite loop
72 return std::atof( str.c_str() );
74 return ::atof( str.c_str() );
79 atoi( const string& str )
82 // -dw- if ::atoi is called, then we get an infinite loop
83 return std::atoi( str.c_str() );
85 return ::atoi( str.c_str() );
90 // Defined the shared options class here
91 // FGOptions current_options;
95 FGOptions::FGOptions() :
96 // starting longitude in degrees (west = -)
97 // starting latitude in degrees (south = -)
99 // Default initial position is Globe, AZ (P13)
103 // North of the city of Globe
107 // North of the city of Globe
111 // Near where I used to live in Globe, AZ
115 // 10125 Jewell St. NE
119 // Near KHSP (Hot Springs, VA)
120 // lon(-79.8338964 + 0.01),
121 // lat( 37.9514564 + 0.008),
123 // (SEZ) SEDONA airport
124 // lon(-111.7884614 + 0.01),
125 // lat( 34.8486289 - 0.015),
127 // Jim Brennon's Kingmont Observatory
128 // lon(-121.1131667),
131 // Huaras, Peru (S09d 31.871' W077d 31.498')
135 // Eclipse Watching w73.5 n10 (approx) 18:00 UT
140 // lon(-90.1953055556),
141 // lat( 45.4511388889),
143 // starting altitude in meters (this will be reset to ground level
144 // if it is lower than the terrain
147 // Initial Orientation
148 heading(270.0), // heading (yaw) angle in degress (Psi)
149 roll(0.0), // roll angle in degrees (Phi)
150 pitch(0.424), // pitch angle in degrees (Theta)
152 // Initialize current options velocities to 0.0
154 uBody(0.0), vBody(0.0), wBody(0.0),
155 vNorth(0.0),vEast(0.0), vDown(0.0),
156 vkcas(0.0), mach(0.0),
163 control_mode(FG_JOYSTICK),
164 auto_coordination(FG_AUTO_COORD_NOT_SPECIFIED),
172 // Flight Model options
173 flight_model( FGInterface::FG_LARCSIM ),
175 model_hz( NEW_DEFAULT_MODEL_HZ ),
180 fog(FG_FOG_NICEST), // nicest
182 clouds_asl(5000*FEET_TO_METER),
191 view_mode(FG_VIEW_PILOT),
192 default_view_offset(0),
198 units(FG_UNITS_FEET),
206 // set initial values/defaults
207 time_offset_type = FG_TIME_SYS_OFFSET;
208 char* envp = ::getenv( "FG_ROOT" );
210 if ( envp != NULL ) {
211 // fg_root could be anywhere, so default to environmental
212 // variable $FG_ROOT if it is set.
215 // Otherwise, default to a random compiled-in location if
216 // $FG_ROOT is not set. This can still be overridden from the
217 // command line or a config file.
220 fg_root = "\\FlightGear";
221 #elif defined( macintosh )
228 // set a possibly independent location for scenery data
229 envp = ::getenv( "FG_SCENERY" );
231 if ( envp != NULL ) {
232 // fg_root could be anywhere, so default to environmental
233 // variable $FG_ROOT if it is set.
236 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
240 airport_id = "KPAO"; // default airport id
241 net_id = "Johnney"; // default pilot's name
243 // initialize port config string list
244 channel_options_list.clear();
248 FGOptions::toggle_panel() {
250 bool freeze = globals->get_freeze();
253 globals->set_freeze(true);
256 panel_status = false;
257 if ( current_panel != NULL )
258 current_panel->setVisibility(false);
261 if ( current_panel != NULL )
262 current_panel->setVisibility(true);
265 fgReshape( xsize, ysize);
268 globals->set_freeze( false );
272 FGOptions::parse_time(const string& time_in) {
273 char *time_str, num[256];
274 double hours, minutes, seconds;
279 time_str = (char *)time_in.c_str();
281 // printf("parse_time(): %s\n", time_str);
284 if ( strlen(time_str) ) {
285 if ( time_str[0] == '+' ) {
288 } else if ( time_str[0] == '-' ) {
293 // printf("sign = %d\n", sign);
296 if ( strlen(time_str) ) {
298 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
299 num[i] = time_str[0];
303 if ( time_str[0] == ':' ) {
308 // printf("hours = %.2lf\n", hours);
314 if ( strlen(time_str) ) {
316 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
317 num[i] = time_str[0];
321 if ( time_str[0] == ':' ) {
326 // printf("minutes = %.2lf\n", minutes);
328 result += minutes / 60.0;
332 if ( strlen(time_str) ) {
334 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
335 num[i] = time_str[0];
341 // printf("seconds = %.2lf\n", seconds);
343 result += seconds / 3600.0;
346 return(sign * result);
350 long int FGOptions::parse_date( const string& date)
353 char * date_str, num[256];
355 // initialize to zero
362 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
363 date_str = (char *)date.c_str();
365 if ( strlen(date_str) ) {
367 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
368 num[i] = date_str[0];
372 if ( date_str[0] == ':' ) {
376 gmt.tm_year = atoi(num) - 1900;
379 if ( strlen(date_str) ) {
381 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
382 num[i] = date_str[0];
386 if ( date_str[0] == ':' ) {
390 gmt.tm_mon = atoi(num) -1;
393 if ( strlen(date_str) ) {
395 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
396 num[i] = date_str[0];
400 if ( date_str[0] == ':' ) {
404 gmt.tm_mday = atoi(num);
407 if ( strlen(date_str) ) {
409 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
410 num[i] = date_str[0];
414 if ( date_str[0] == ':' ) {
418 gmt.tm_hour = atoi(num);
421 if ( strlen(date_str) ) {
423 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
424 num[i] = date_str[0];
428 if ( date_str[0] == ':' ) {
432 gmt.tm_min = atoi(num);
435 if ( strlen(date_str) ) {
437 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
438 num[i] = date_str[0];
442 if ( date_str[0] == ':' ) {
446 gmt.tm_sec = atoi(num);
448 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
449 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
450 //printf ("Date is %s\n", ctime(&theTime));
451 //printf ("in seconds that is %d\n", theTime);
457 // parse degree in the form of [+/-]hhh:mm:ss
458 void FGOptions::parse_control( const string& mode ) {
459 if ( mode == "joystick" ) {
460 control_mode = FG_JOYSTICK;
461 } else if ( mode == "mouse" ) {
462 control_mode = FG_MOUSE;
464 control_mode = FG_KEYBOARD;
469 /// parse degree in the form of [+/-]hhh:mm:ss
471 FGOptions::parse_degree( const string& degree_str) {
472 double result = parse_time( degree_str );
474 // printf("Degree = %.4f\n", result);
480 // parse time offset command line option
482 FGOptions::parse_time_offset( const string& time_str) {
485 // printf("time offset = %s\n", time_str);
488 result = (int)rint(parse_time(time_str) * 3600.0);
490 result = (int)(parse_time(time_str) * 3600.0);
493 // printf("parse_time_offset(): %d\n", result);
499 // Parse --tile-diameter=n type option
502 FGOptions::parse_tile_radius( const string& arg ) {
503 int radius = atoi( arg );
505 if ( radius < FG_RADIUS_MIN ) { radius = FG_RADIUS_MIN; }
506 if ( radius > FG_RADIUS_MAX ) { radius = FG_RADIUS_MAX; }
508 // printf("parse_tile_radius(): radius = %d\n", radius);
514 // Parse --fdm=abcdefg type option
516 FGOptions::parse_fdm( const string& fm ) {
517 // cout << "fdm = " << fm << endl;
520 return FGInterface::FG_ADA;
521 } else if ( fm == "balloon" ) {
522 return FGInterface::FG_BALLOONSIM;
523 } else if ( fm == "external" ) {
524 return FGInterface::FG_EXTERNAL;
525 } else if ( fm == "jsb" ) {
526 return FGInterface::FG_JSBSIM;
527 } else if ( (fm == "larcsim") || (fm == "LaRCsim") ) {
528 return FGInterface::FG_LARCSIM;
529 } else if ( fm == "magic" ) {
530 return FGInterface::FG_MAGICCARPET;
532 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown fdm = " << fm );
536 // we'll never get here, but it makes the compiler happy.
541 // Parse --fov=x.xx type option
543 FGOptions::parse_fov( const string& arg ) {
544 double fov = atof(arg);
546 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
547 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
549 globals->get_current_view()->set_fov( fov );
551 // printf("parse_fov(): result = %.4f\n", fov);
557 // Parse I/O channel option
559 // Format is "--protocol=medium,direction,hz,medium_options,..."
561 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
562 // medium = { serial, socket, file, etc. }
563 // direction = { in, out, bi }
564 // hz = number of times to process channel per second (floating
565 // point values are ok.
567 // Serial example "--nmea=serial,dir,hz,device,baud" where
569 // device = OS device name of serial line to be open()'ed
570 // baud = {300, 1200, 2400, ..., 230400}
572 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
574 // machine = machine name or ip address if client (leave empty if server)
575 // port = port, leave empty to let system choose
576 // style = tcp or udp
578 // File example "--garmin=file,dir,hz,filename" where
580 // filename = file system file name
583 FGOptions::parse_channel( const string& type, const string& channel_str ) {
584 // cout << "Channel string = " << channel_str << endl;
586 channel_options_list.push_back( type + "," + channel_str );
592 // Parse --wp=ID[,alt]
593 bool FGOptions::parse_wp( const string& arg ) {
597 int pos = arg.find( "@" );
598 if ( pos != string::npos ) {
599 id = arg.substr( 0, pos );
600 alt_str = arg.substr( pos + 1 );
601 // cout << "id str = " << id << " alt str = " << alt_str << endl;
602 alt = atof( alt_str.c_str() );
603 if ( units == FG_UNITS_FEET ) {
604 alt *= FEET_TO_METER;
611 if ( fgFindAirportID( id, &a ) ) {
612 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
613 globals->get_route()->add_waypoint( wp );
622 // Parse --flight-plan=[file]
623 bool FGOptions::parse_flightplan(const string& arg)
625 fg_gzifstream infile(arg.c_str());
631 #ifdef GETLINE_NEEDS_TERMINATOR
632 getline( infile, line, '\n' );
633 #elif defined( macintosh )
634 getline( infile, line, '\r' );
636 getline( infile, line );
638 if ( infile.eof() ) {
648 // Parse a single option
649 int FGOptions::parse_option( const string& arg ) {
651 if ( (arg == "--help") || (arg == "-h") ) {
652 // help/usage request
653 return(FG_OPTIONS_HELP);
654 } else if ( arg == "--disable-game-mode") {
656 } else if ( arg == "--enable-game-mode" ) {
658 } else if ( arg == "--disable-splash-screen" ) {
659 splash_screen = false;
660 } else if ( arg == "--enable-splash-screen" ) {
661 splash_screen = true;
662 } else if ( arg == "--disable-intro-music" ) {
664 } else if ( arg == "--enable-intro-music" ) {
666 } else if ( arg == "--disable-mouse-pointer" ) {
668 } else if ( arg == "--enable-mouse-pointer" ) {
670 } else if ( arg == "--disable-freeze" ) {
671 globals->set_freeze( false );
672 } else if ( arg == "--enable-freeze" ) {
673 globals->set_freeze( true );
674 } else if ( arg == "--disable-anti-alias-hud" ) {
675 anti_alias_hud = false;
676 } else if ( arg == "--enable-anti-alias-hud" ) {
677 anti_alias_hud = true;
678 } else if ( arg.find( "--control=") != string::npos ) {
679 parse_control( arg.substr(10) );
680 } else if ( arg == "--disable-auto-coordination" ) {
681 auto_coordination = FG_AUTO_COORD_DISABLED;
682 } else if ( arg == "--enable-auto-coordination" ) {
683 auto_coordination = FG_AUTO_COORD_ENABLED;
684 } else if ( arg == "--disable-hud" ) {
686 current_properties.setBoolValue("/sim/hud/visibility", false);
687 } else if ( arg == "--enable-hud" ) {
689 current_properties.setBoolValue("/sim/hud/visibility", true);
690 } else if ( arg == "--disable-panel" ) {
691 panel_status = false;
692 current_properties.setBoolValue("/sim/panel/visibility", false);
693 if ( current_panel != NULL )
694 current_panel->setVisibility(false);
695 } else if ( arg == "--enable-panel" ) {
697 current_properties.setBoolValue("/sim/panel/visibility", true);
698 if ( current_panel != NULL )
699 current_panel->setVisibility(true);
700 } else if ( arg == "--disable-sound" ) {
702 } else if ( arg == "--enable-sound" ) {
704 } else if ( arg.find( "--airport-id=") != string::npos ) {
705 airport_id = arg.substr( 13 );
706 current_properties.setStringValue("/position/airport-id", airport_id);
707 } else if ( arg.find( "--lon=" ) != string::npos ) {
708 lon = parse_degree( arg.substr(6) );
710 current_properties.setDoubleValue("/position/longitude", lon);
711 current_properties.setStringValue("/position/airport-id", airport_id);
712 } else if ( arg.find( "--lat=" ) != string::npos ) {
713 lat = parse_degree( arg.substr(6) );
715 current_properties.setDoubleValue("/position/latitude", lat);
716 current_properties.setStringValue("/position/airport-id", airport_id);
717 } else if ( arg.find( "--altitude=" ) != string::npos ) {
718 if ( units == FG_UNITS_FEET ) {
719 altitude = atof( arg.substr(11) ) * FEET_TO_METER;
721 altitude = atof( arg.substr(11) );
723 current_properties.setDoubleValue("/position/altitude", altitude);
724 } else if ( arg.find( "--uBody=" ) != string::npos ) {
726 if ( units == FG_UNITS_FEET ) {
727 uBody = atof( arg.substr(8) );
729 uBody = atof( arg.substr(8) ) * FEET_TO_METER;
731 //current_properties.setDoubleValue("/velocities/speed-north", uBody);
732 } else if ( arg.find( "--vBody=" ) != string::npos ) {
734 if ( units == FG_UNITS_FEET ) {
735 vBody = atof( arg.substr(8) );
737 vBody = atof( arg.substr(8) ) * FEET_TO_METER;
739 //current_properties.setDoubleValue("/velocities/speed-east", vBody);
740 } else if ( arg.find( "--wBody=" ) != string::npos ) {
742 if ( units == FG_UNITS_FEET ) {
743 wBody = atof( arg.substr(8) );
745 wBody = atof( arg.substr(8) ) * FEET_TO_METER;
747 } else if ( arg.find( "--vNorth=" ) != string::npos ) {
749 if ( units == FG_UNITS_FEET ) {
750 vNorth = atof( arg.substr(9) );
752 vNorth = atof( arg.substr(9) ) * FEET_TO_METER;
754 current_properties.setDoubleValue("/velocities/speed-north", vNorth);
755 } else if ( arg.find( "--vEast=" ) != string::npos ) {
757 if ( units == FG_UNITS_FEET ) {
758 vEast = atof( arg.substr(8) );
760 vEast = atof( arg.substr(8) ) * FEET_TO_METER;
762 current_properties.setDoubleValue("/velocities/speed-east", vEast);
763 } else if ( arg.find( "--vDown=" ) != string::npos ) {
765 if ( units == FG_UNITS_FEET ) {
766 vDown = atof( arg.substr(8) );
768 vDown = atof( arg.substr(8) ) * FEET_TO_METER;
770 current_properties.setDoubleValue("/velocities/speed-down", vDown);
771 } else if ( arg.find( "--vc=" ) != string::npos) {
773 vkcas=atof( arg.substr(5) );
774 cout << "Got vc: " << vkcas << endl;
775 } else if ( arg.find( "--mach=" ) != string::npos) {
777 mach=atof( arg.substr(7) );
778 } else if ( arg.find( "--heading=" ) != string::npos ) {
779 heading = atof( arg.substr(10) );
780 current_properties.setDoubleValue("/orientation/heading", heading);
781 } else if ( arg.find( "--roll=" ) != string::npos ) {
782 roll = atof( arg.substr(7) );
783 current_properties.setDoubleValue("/orientation/roll", roll);
784 } else if ( arg.find( "--pitch=" ) != string::npos ) {
785 pitch = atof( arg.substr(8) );
786 current_properties.setDoubleValue("/orientation/pitch", pitch);
787 } else if ( arg.find( "--fg-root=" ) != string::npos ) {
788 fg_root = arg.substr( 10 );
789 } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
790 fg_scenery = arg.substr( 13 );
791 } else if ( arg.find( "--fdm=" ) != string::npos ) {
792 flight_model = parse_fdm( arg.substr(6) );
793 current_properties.setIntValue("/sim/flight-model", flight_model);
794 if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
799 } else if ( arg.find( "--aircraft=" ) != string::npos ) {
800 aircraft = arg.substr(11);
801 current_properties.setStringValue("/sim/aircraft", aircraft);
802 } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
803 aircraft_dir = arg.substr(15); // (UIUC)
804 } else if ( arg.find( "--model-hz=" ) != string::npos ) {
805 model_hz = atoi( arg.substr(11) );
806 } else if ( arg.find( "--speed=" ) != string::npos ) {
807 speed_up = atoi( arg.substr(8) );
808 } else if ( arg.find( "--notrim") != string::npos) {
810 } else if ( arg == "--fog-disable" ) {
811 fog = FG_FOG_DISABLED;
812 } else if ( arg == "--fog-fastest" ) {
813 fog = FG_FOG_FASTEST;
814 } else if ( arg == "--fog-nicest" ) {
816 } else if ( arg == "--disable-clouds" ) {
818 } else if ( arg == "--enable-clouds" ) {
820 } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
821 if ( units == FG_UNITS_FEET ) {
822 clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
824 clouds_asl = atof( arg.substr(13) );
826 } else if ( arg.find( "--fov=" ) != string::npos ) {
827 parse_fov( arg.substr(6) );
828 } else if ( arg == "--disable-fullscreen" ) {
830 } else if ( arg== "--enable-fullscreen") {
832 } else if ( arg == "--shading-flat") {
834 } else if ( arg == "--shading-smooth") {
836 } else if ( arg == "--disable-skyblend") {
838 } else if ( arg== "--enable-skyblend" ) {
840 } else if ( arg == "--disable-textures" ) {
842 } else if ( arg == "--enable-textures" ) {
844 } else if ( arg == "--disable-wireframe" ) {
846 } else if ( arg == "--enable-wireframe" ) {
848 } else if ( arg.find( "--geometry=" ) != string::npos ) {
849 bool geometry_ok = true;
850 string geometry = arg.substr( 11 );
851 string::size_type i = geometry.find('x');
853 if (i != string::npos) {
854 xsize = atoi(geometry.substr(0, i));
855 ysize = atoi(geometry.substr(i+1));
856 // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
861 if ( xsize <= 0 || ysize <= 0 ) {
867 if ( !geometry_ok ) {
868 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
869 FG_LOG( FG_GENERAL, FG_ALERT,
870 "Setting geometry to " << xsize << 'x' << ysize << '\n');
872 } else if ( arg.find( "--bpp=" ) != string::npos ) {
873 string bits_per_pix = arg.substr( 6 );
874 if ( bits_per_pix == "16" ) {
876 } else if ( bits_per_pix == "24" ) {
878 } else if ( bits_per_pix == "32" ) {
881 } else if ( arg == "--units-feet" ) {
882 units = FG_UNITS_FEET;
883 } else if ( arg == "--units-meters" ) {
884 units = FG_UNITS_METERS;
885 } else if ( arg.find( "--tile-radius=" ) != string::npos ) {
886 tile_radius = parse_tile_radius( arg.substr(14) );
887 tile_diameter = tile_radius * 2 + 1;
888 } else if ( arg.find( "--time-offset" ) != string::npos ) {
889 time_offset = parse_time_offset( (arg.substr(14)) );
890 //time_offset_type = FG_TIME_SYS_OFFSET;
891 } else if ( arg.find( "--time-match-real") != string::npos ) {
892 //time_offset = parse_time_offset(arg.substr(18));
893 time_offset_type = FG_TIME_SYS_OFFSET;
894 } else if ( arg.find( "--time-match-local") != string::npos ) {
895 //time_offset = parse_time_offset(arg.substr(18));
896 time_offset_type = FG_TIME_LAT_OFFSET;
897 } else if ( arg.find( "--start-date-sys=") != string::npos ) {
898 time_offset = parse_date( (arg.substr(17)) );
899 time_offset_type = FG_TIME_SYS_ABSOLUTE;
900 } else if ( arg.find( "--start-date-lat=") != string::npos ) {
901 time_offset = parse_date( (arg.substr(17)) );
902 time_offset_type = FG_TIME_LAT_ABSOLUTE;
903 } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
904 time_offset = parse_date( (arg.substr(17)) );
905 time_offset_type = FG_TIME_GMT_ABSOLUTE;
907 } else if ( arg == "--hud-tris" ) {
909 } else if ( arg == "--hud-culled" ) {
911 } else if ( arg.find( "--native=" ) != string::npos ) {
912 parse_channel( "native", arg.substr(9) );
913 } else if ( arg.find( "--garmin=" ) != string::npos ) {
914 parse_channel( "garmin", arg.substr(9) );
915 } else if ( arg.find( "--nmea=" ) != string::npos ) {
916 parse_channel( "nmea", arg.substr(7) );
917 } else if ( arg.find( "--props=" ) != string::npos ) {
918 parse_channel( "props", arg.substr(8) );
919 } else if ( arg.find( "--pve=" ) != string::npos ) {
920 parse_channel( "pve", arg.substr(6) );
921 } else if ( arg.find( "--ray=" ) != string::npos ) {
922 parse_channel( "ray", arg.substr(6) );
923 } else if ( arg.find( "--rul=" ) != string::npos ) {
924 parse_channel( "rul", arg.substr(6) );
925 } else if ( arg.find( "--joyclient=" ) != string::npos ) {
926 parse_channel( "joyclient", arg.substr(12) );
927 #ifdef FG_NETWORK_OLK
928 } else if ( arg == "--disable-network-olk" ) {
930 } else if ( arg== "--enable-network-olk") {
932 } else if ( arg == "--net-hud" ) {
934 } else if ( arg.find( "--net-id=") != string::npos ) {
935 net_id = arg.substr( 9 );
937 } else if ( arg.find( "--prop:" ) == 0 ) {
938 string assign = arg.substr(7);
939 int pos = assign.find('=');
940 if (pos == arg.npos || pos == 0) {
941 FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
942 return FG_OPTIONS_ERROR;
944 string name = assign.substr(0, pos);
945 string value = assign.substr(pos + 1);
946 current_properties.setStringValue(name.c_str(), value);
947 FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
948 << name << " to \"" << value << '"');
949 // $$$ begin - added VS Renganathan, 14 Oct 2K
950 // for multi-window outside window imagery
951 } else if ( arg.find( "--view-offset=" ) != string::npos ) {
952 string woffset = arg.substr( 14 );
953 if ( woffset == "LEFT" ) {
954 default_view_offset = M_PI * 0.25;
955 } else if ( woffset == "RIGHT" ) {
956 default_view_offset = M_PI * 1.75;
957 } else if ( woffset == "CENTER" ) {
958 default_view_offset = 0.00;
960 default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD;
962 FGViewerRPH *pilot_view =
963 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
964 pilot_view->set_view_offset( default_view_offset );
965 pilot_view->set_goal_view_offset( default_view_offset );
966 // $$$ end - added VS Renganathan, 14 Oct 2K
967 } else if ( arg.find( "--wp=" ) != string::npos ) {
968 parse_wp( arg.substr( 5 ) );
969 } else if ( arg.find( "--flight-plan=") != string::npos) {
970 parse_flightplan ( arg.substr (14) );
972 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
973 return FG_OPTIONS_ERROR;
976 return FG_OPTIONS_OK;
980 // Scan the command line options for an fg_root definition and set
982 int FGOptions::scan_command_line_for_root( int argc, char **argv ) {
985 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
988 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
990 string arg = argv[i];
991 if ( arg.find( "--fg-root=" ) != string::npos ) {
992 fg_root = arg.substr( 10 );
998 return FG_OPTIONS_OK;
1002 // Scan the config file for an fg_root definition and set just that.
1003 int FGOptions::scan_config_file_for_root( const string& path ) {
1004 fg_gzifstream in( path );
1005 if ( !in.is_open() )
1006 return(FG_OPTIONS_ERROR);
1008 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
1012 while ( ! in.eof() ) {
1015 while ( in.get(c) && c != '\0' ) {
1020 #ifdef GETLINE_NEEDS_TERMINATOR
1021 getline( in, line, '\n' );
1022 #elif defined( macintosh )
1023 getline( in, line, '\r' );
1025 getline( in, line );
1028 if ( line.find( "--fg-root=" ) != string::npos ) {
1029 fg_root = line.substr( 10 );
1035 return FG_OPTIONS_OK;
1039 // Parse the command line options
1040 int FGOptions::parse_command_line( int argc, char **argv ) {
1044 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
1046 while ( i < argc ) {
1047 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
1049 result = parse_option(argv[i]);
1050 if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
1057 return FG_OPTIONS_OK;
1061 // Parse config file options
1062 int FGOptions::parse_config_file( const string& path ) {
1063 fg_gzifstream in( path );
1064 if ( !in.is_open() )
1065 return(FG_OPTIONS_ERROR);
1067 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
1071 while ( ! in.eof() ) {
1074 while ( in.get(c) && c != '\0' ) {
1079 #ifdef GETLINE_NEEDS_TERMINATOR
1080 getline( in, line, '\n' );
1081 #elif defined( macintosh )
1082 getline( in, line, '\r' );
1084 getline( in, line );
1087 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1088 FG_LOG( FG_GENERAL, FG_ALERT,
1089 "Config file parse error: " << path << " '"
1096 return FG_OPTIONS_OK;
1100 // Print usage message
1101 void FGOptions::usage ( void ) {
1102 cout << "Usage: fg [ options ... ]" << endl;
1105 cout << "General Options:" << endl;
1106 cout << "\t--help -h: print usage" << endl;
1107 cout << "\t--fg-root=path: specify the root path for all the data files"
1109 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
1111 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1112 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
1113 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1114 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1115 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1116 cout << "\t--disable-intro-music: disable introduction music" << endl;
1117 cout << "\t--enable-intro-music: enable introduction music" << endl;
1118 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1119 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1121 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1122 cout << "\t--disable-freeze: start out in an running state" << endl;
1123 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1124 cout << "\t--control=mode: primary control mode "
1125 << "(joystick, keyboard, mouse)" << endl;
1128 cout << "Features:" << endl;
1129 cout << "\t--disable-hud: disable heads up display" << endl;
1130 cout << "\t--enable-hud: enable heads up display" << endl;
1131 cout << "\t--disable-panel: disable instrument panel" << endl;
1132 cout << "\t--enable-panel: enable instrumetn panel" << endl;
1133 cout << "\t--disable-sound: disable sound effects" << endl;
1134 cout << "\t--enable-sound: enable sound effects" << endl;
1135 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1136 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1139 cout << "Flight Model:" << endl;
1140 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1141 cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1143 cout << "\t--aircraft=abcd: aircraft model to load" << endl;
1144 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1146 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1147 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1150 cout <<"Aircraft model directory:" << endl;
1151 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1154 cout << "Initial Position and Orientation:" << endl;
1155 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1157 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1159 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1161 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1162 cout << "\t\t(unless --units-meters specified" << endl;
1163 cout << "\t--heading=degrees: heading (yaw) angle in degress (Psi)"
1165 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1166 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1167 cout << "\t--uBody=feet per second: velocity along the body X axis"
1169 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1171 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1173 cout << "\t\t(unless --units-meters specified" << endl;
1174 cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1175 cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1178 cout << "Rendering Options:" << endl;
1179 cout << "\t--fog-disable: disable fog/haze" << endl;
1180 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1181 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1182 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1183 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1184 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1185 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1187 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1188 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1189 cout << "\t--shading-flat: enable flat shading" << endl;
1190 cout << "\t--shading-smooth: enable smooth shading" << endl;
1191 cout << "\t--disable-skyblend: disable sky blending" << endl;
1192 cout << "\t--enable-skyblend: enable sky blending" << endl;
1193 cout << "\t--disable-textures: disable textures" << endl;
1194 cout << "\t--enable-textures: enable textures" << endl;
1195 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1196 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1197 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1199 cout << "\t--view-offset=xxx: set the default forward view direction"
1201 cout << "\t\tas an offset from straight ahead. Allowable values are"
1203 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1206 cout << "Scenery Options:" << endl;
1207 cout << "\t--tile-radius=n: specify tile radius, must be 1 - 4" << endl;
1210 cout << "Hud Options:" << endl;
1211 cout << "\t--units-feet: Hud displays units in feet" << endl;
1212 cout << "\t--units-meters: Hud displays units in meters" << endl;
1213 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1214 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1218 cout << "Time Options:" << endl;
1219 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1220 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1221 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1222 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1223 << "\t\tFlightGear time" << endl;
1224 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1225 << "\t\tdate/time. Uses your system time " << endl;
1226 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1227 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1228 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1229 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1230 #ifdef FG_NETWORK_OLK
1233 cout << "Network Options:" << endl;
1234 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1235 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1236 cout << "\t--net-hud: Hud displays network info" << endl;
1237 cout << "\t--net-id=name: specify your own callsign" << endl;
1241 cout << "Route/Way Point Options:" << endl;
1242 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1243 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1245 cout << "\t\tinstances of --wp=" << endl;
1246 cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;
1251 FGOptions::~FGOptions( void ) {