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),
196 units(FG_UNITS_FEET),
204 // set initial values/defaults
205 time_offset_type = FG_TIME_SYS_OFFSET;
206 char* envp = ::getenv( "FG_ROOT" );
208 if ( envp != NULL ) {
209 // fg_root could be anywhere, so default to environmental
210 // variable $FG_ROOT if it is set.
213 // Otherwise, default to a random compiled-in location if
214 // $FG_ROOT is not set. This can still be overridden from the
215 // command line or a config file.
218 fg_root = "\\FlightGear";
219 #elif defined( macintosh )
226 // set a possibly independent location for scenery data
227 envp = ::getenv( "FG_SCENERY" );
229 if ( envp != NULL ) {
230 // fg_root could be anywhere, so default to environmental
231 // variable $FG_ROOT if it is set.
234 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
238 airport_id = "KPAO"; // default airport id
239 net_id = "Johnney"; // default pilot's name
241 // initialize port config string list
242 channel_options_list.clear();
246 FGOptions::toggle_panel() {
248 bool freeze = globals->get_freeze();
251 globals->set_freeze(true);
254 panel_status = false;
255 if ( current_panel != NULL )
256 current_panel->setVisibility(false);
259 if ( current_panel != NULL )
260 current_panel->setVisibility(true);
263 fgReshape( xsize, ysize);
266 globals->set_freeze( false );
270 FGOptions::parse_time(const string& time_in) {
271 char *time_str, num[256];
272 double hours, minutes, seconds;
277 time_str = (char *)time_in.c_str();
279 // printf("parse_time(): %s\n", time_str);
282 if ( strlen(time_str) ) {
283 if ( time_str[0] == '+' ) {
286 } else if ( time_str[0] == '-' ) {
291 // printf("sign = %d\n", sign);
294 if ( strlen(time_str) ) {
296 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
297 num[i] = time_str[0];
301 if ( time_str[0] == ':' ) {
306 // printf("hours = %.2lf\n", hours);
312 if ( strlen(time_str) ) {
314 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
315 num[i] = time_str[0];
319 if ( time_str[0] == ':' ) {
324 // printf("minutes = %.2lf\n", minutes);
326 result += minutes / 60.0;
330 if ( strlen(time_str) ) {
332 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
333 num[i] = time_str[0];
339 // printf("seconds = %.2lf\n", seconds);
341 result += seconds / 3600.0;
344 return(sign * result);
348 long int FGOptions::parse_date( const string& date)
351 char * date_str, num[256];
353 // initialize to zero
360 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
361 date_str = (char *)date.c_str();
363 if ( strlen(date_str) ) {
365 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
366 num[i] = date_str[0];
370 if ( date_str[0] == ':' ) {
374 gmt.tm_year = atoi(num) - 1900;
377 if ( strlen(date_str) ) {
379 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
380 num[i] = date_str[0];
384 if ( date_str[0] == ':' ) {
388 gmt.tm_mon = atoi(num) -1;
391 if ( strlen(date_str) ) {
393 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
394 num[i] = date_str[0];
398 if ( date_str[0] == ':' ) {
402 gmt.tm_mday = atoi(num);
405 if ( strlen(date_str) ) {
407 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
408 num[i] = date_str[0];
412 if ( date_str[0] == ':' ) {
416 gmt.tm_hour = atoi(num);
419 if ( strlen(date_str) ) {
421 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
422 num[i] = date_str[0];
426 if ( date_str[0] == ':' ) {
430 gmt.tm_min = atoi(num);
433 if ( strlen(date_str) ) {
435 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
436 num[i] = date_str[0];
440 if ( date_str[0] == ':' ) {
444 gmt.tm_sec = atoi(num);
446 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
447 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
448 //printf ("Date is %s\n", ctime(&theTime));
449 //printf ("in seconds that is %d\n", theTime);
455 // parse degree in the form of [+/-]hhh:mm:ss
456 void FGOptions::parse_control( const string& mode ) {
457 if ( mode == "joystick" ) {
458 control_mode = FG_JOYSTICK;
459 } else if ( mode == "mouse" ) {
460 control_mode = FG_MOUSE;
462 control_mode = FG_KEYBOARD;
467 /// parse degree in the form of [+/-]hhh:mm:ss
469 FGOptions::parse_degree( const string& degree_str) {
470 double result = parse_time( degree_str );
472 // printf("Degree = %.4f\n", result);
478 // parse time offset command line option
480 FGOptions::parse_time_offset( const string& time_str) {
483 // printf("time offset = %s\n", time_str);
486 result = (int)rint(parse_time(time_str) * 3600.0);
488 result = (int)(parse_time(time_str) * 3600.0);
491 // printf("parse_time_offset(): %d\n", result);
497 // Parse --fdm=abcdefg type option
499 FGOptions::parse_fdm( const string& fm ) {
500 // cout << "fdm = " << fm << endl;
503 return FGInterface::FG_ADA;
504 } else if ( fm == "balloon" ) {
505 return FGInterface::FG_BALLOONSIM;
506 } else if ( fm == "external" ) {
507 return FGInterface::FG_EXTERNAL;
508 } else if ( fm == "jsb" ) {
509 return FGInterface::FG_JSBSIM;
510 } else if ( (fm == "larcsim") || (fm == "LaRCsim") ) {
511 return FGInterface::FG_LARCSIM;
512 } else if ( fm == "magic" ) {
513 return FGInterface::FG_MAGICCARPET;
515 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown fdm = " << fm );
519 // we'll never get here, but it makes the compiler happy.
524 // Parse --fov=x.xx type option
526 FGOptions::parse_fov( const string& arg ) {
527 double fov = atof(arg);
529 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
530 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
532 globals->get_current_view()->set_fov( fov );
534 // printf("parse_fov(): result = %.4f\n", fov);
540 // Parse I/O channel option
542 // Format is "--protocol=medium,direction,hz,medium_options,..."
544 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
545 // medium = { serial, socket, file, etc. }
546 // direction = { in, out, bi }
547 // hz = number of times to process channel per second (floating
548 // point values are ok.
550 // Serial example "--nmea=serial,dir,hz,device,baud" where
552 // device = OS device name of serial line to be open()'ed
553 // baud = {300, 1200, 2400, ..., 230400}
555 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
557 // machine = machine name or ip address if client (leave empty if server)
558 // port = port, leave empty to let system choose
559 // style = tcp or udp
561 // File example "--garmin=file,dir,hz,filename" where
563 // filename = file system file name
566 FGOptions::parse_channel( const string& type, const string& channel_str ) {
567 // cout << "Channel string = " << channel_str << endl;
569 channel_options_list.push_back( type + "," + channel_str );
575 // Parse --wp=ID[,alt]
576 bool FGOptions::parse_wp( const string& arg ) {
580 int pos = arg.find( "@" );
581 if ( pos != string::npos ) {
582 id = arg.substr( 0, pos );
583 alt_str = arg.substr( pos + 1 );
584 // cout << "id str = " << id << " alt str = " << alt_str << endl;
585 alt = atof( alt_str.c_str() );
586 if ( units == FG_UNITS_FEET ) {
587 alt *= FEET_TO_METER;
594 if ( fgFindAirportID( id, &a ) ) {
595 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
596 globals->get_route()->add_waypoint( wp );
605 // Parse --flight-plan=[file]
606 bool FGOptions::parse_flightplan(const string& arg)
608 fg_gzifstream infile(arg.c_str());
614 #ifdef GETLINE_NEEDS_TERMINATOR
615 getline( infile, line, '\n' );
616 #elif defined( macintosh )
617 getline( infile, line, '\r' );
619 getline( infile, line );
621 if ( infile.eof() ) {
631 // Parse a single option
632 int FGOptions::parse_option( const string& arg ) {
634 if ( (arg == "--help") || (arg == "-h") ) {
635 // help/usage request
636 return(FG_OPTIONS_HELP);
637 } else if ( arg == "--disable-game-mode") {
639 } else if ( arg == "--enable-game-mode" ) {
641 } else if ( arg == "--disable-splash-screen" ) {
642 splash_screen = false;
643 } else if ( arg == "--enable-splash-screen" ) {
644 splash_screen = true;
645 } else if ( arg == "--disable-intro-music" ) {
647 } else if ( arg == "--enable-intro-music" ) {
649 } else if ( arg == "--disable-mouse-pointer" ) {
651 } else if ( arg == "--enable-mouse-pointer" ) {
653 } else if ( arg == "--disable-freeze" ) {
654 globals->set_freeze( false );
655 } else if ( arg == "--enable-freeze" ) {
656 globals->set_freeze( true );
657 } else if ( arg == "--disable-anti-alias-hud" ) {
658 anti_alias_hud = false;
659 } else if ( arg == "--enable-anti-alias-hud" ) {
660 anti_alias_hud = true;
661 } else if ( arg.find( "--control=") != string::npos ) {
662 parse_control( arg.substr(10) );
663 } else if ( arg == "--disable-auto-coordination" ) {
664 auto_coordination = FG_AUTO_COORD_DISABLED;
665 } else if ( arg == "--enable-auto-coordination" ) {
666 auto_coordination = FG_AUTO_COORD_ENABLED;
667 } else if ( arg == "--disable-hud" ) {
669 globals->get_props()->setBoolValue("/sim/hud/visibility", false);
670 } else if ( arg == "--enable-hud" ) {
672 globals->get_props()->setBoolValue("/sim/hud/visibility", true);
673 } else if ( arg == "--disable-panel" ) {
674 panel_status = false;
675 globals->get_props()->setBoolValue("/sim/panel/visibility", false);
676 if ( current_panel != NULL )
677 current_panel->setVisibility(false);
678 } else if ( arg == "--enable-panel" ) {
680 globals->get_props()->setBoolValue("/sim/panel/visibility", true);
681 if ( current_panel != NULL )
682 current_panel->setVisibility(true);
683 } else if ( arg == "--disable-sound" ) {
685 } else if ( arg == "--enable-sound" ) {
687 } else if ( arg.find( "--airport-id=") != string::npos ) {
688 airport_id = arg.substr( 13 );
689 globals->get_props()->setStringValue("/position/airport-id", airport_id);
690 } else if ( arg.find( "--lon=" ) != string::npos ) {
691 lon = parse_degree( arg.substr(6) );
693 globals->get_props()->setDoubleValue("/position/longitude", lon);
694 globals->get_props()->setStringValue("/position/airport-id", airport_id);
695 } else if ( arg.find( "--lat=" ) != string::npos ) {
696 lat = parse_degree( arg.substr(6) );
698 globals->get_props()->setDoubleValue("/position/latitude", lat);
699 globals->get_props()->setStringValue("/position/airport-id", airport_id);
700 } else if ( arg.find( "--altitude=" ) != string::npos ) {
701 if ( units == FG_UNITS_FEET ) {
702 altitude = atof( arg.substr(11) ) * FEET_TO_METER;
704 altitude = atof( arg.substr(11) );
706 globals->get_props()->setDoubleValue("/position/altitude", altitude);
707 } else if ( arg.find( "--uBody=" ) != string::npos ) {
709 if ( units == FG_UNITS_FEET ) {
710 uBody = atof( arg.substr(8) );
712 uBody = atof( arg.substr(8) ) * FEET_TO_METER;
714 //globals->get_props()->setDoubleValue("/velocities/speed-north", uBody);
715 } else if ( arg.find( "--vBody=" ) != string::npos ) {
717 if ( units == FG_UNITS_FEET ) {
718 vBody = atof( arg.substr(8) );
720 vBody = atof( arg.substr(8) ) * FEET_TO_METER;
722 //globals->get_props()->setDoubleValue("/velocities/speed-east", vBody);
723 } else if ( arg.find( "--wBody=" ) != string::npos ) {
725 if ( units == FG_UNITS_FEET ) {
726 wBody = atof( arg.substr(8) );
728 wBody = atof( arg.substr(8) ) * FEET_TO_METER;
730 } else if ( arg.find( "--vNorth=" ) != string::npos ) {
732 if ( units == FG_UNITS_FEET ) {
733 vNorth = atof( arg.substr(9) );
735 vNorth = atof( arg.substr(9) ) * FEET_TO_METER;
737 globals->get_props()->setDoubleValue("/velocities/speed-north", vNorth);
738 } else if ( arg.find( "--vEast=" ) != string::npos ) {
740 if ( units == FG_UNITS_FEET ) {
741 vEast = atof( arg.substr(8) );
743 vEast = atof( arg.substr(8) ) * FEET_TO_METER;
745 globals->get_props()->setDoubleValue("/velocities/speed-east", vEast);
746 } else if ( arg.find( "--vDown=" ) != string::npos ) {
748 if ( units == FG_UNITS_FEET ) {
749 vDown = atof( arg.substr(8) );
751 vDown = atof( arg.substr(8) ) * FEET_TO_METER;
753 globals->get_props()->setDoubleValue("/velocities/speed-down", vDown);
754 } else if ( arg.find( "--vc=" ) != string::npos) {
756 vkcas=atof( arg.substr(5) );
757 cout << "Got vc: " << vkcas << endl;
758 } else if ( arg.find( "--mach=" ) != string::npos) {
760 mach=atof( arg.substr(7) );
761 } else if ( arg.find( "--heading=" ) != string::npos ) {
762 heading = atof( arg.substr(10) );
763 globals->get_props()->setDoubleValue("/orientation/heading", heading);
764 } else if ( arg.find( "--roll=" ) != string::npos ) {
765 roll = atof( arg.substr(7) );
766 globals->get_props()->setDoubleValue("/orientation/roll", roll);
767 } else if ( arg.find( "--pitch=" ) != string::npos ) {
768 pitch = atof( arg.substr(8) );
769 globals->get_props()->setDoubleValue("/orientation/pitch", pitch);
770 } else if ( arg.find( "--fg-root=" ) != string::npos ) {
771 fg_root = arg.substr( 10 );
772 } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
773 fg_scenery = arg.substr( 13 );
774 } else if ( arg.find( "--fdm=" ) != string::npos ) {
775 flight_model = parse_fdm( arg.substr(6) );
776 globals->get_props()->setIntValue("/sim/flight-model", flight_model);
777 if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
782 } else if ( arg.find( "--aircraft=" ) != string::npos ) {
783 aircraft = arg.substr(11);
784 globals->get_props()->setStringValue("/sim/aircraft", aircraft);
785 } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
786 aircraft_dir = arg.substr(15); // (UIUC)
787 } else if ( arg.find( "--model-hz=" ) != string::npos ) {
788 model_hz = atoi( arg.substr(11) );
789 } else if ( arg.find( "--speed=" ) != string::npos ) {
790 speed_up = atoi( arg.substr(8) );
791 } else if ( arg.find( "--notrim") != string::npos) {
793 } else if ( arg == "--fog-disable" ) {
794 fog = FG_FOG_DISABLED;
795 } else if ( arg == "--fog-fastest" ) {
796 fog = FG_FOG_FASTEST;
797 } else if ( arg == "--fog-nicest" ) {
799 } else if ( arg == "--disable-clouds" ) {
801 } else if ( arg == "--enable-clouds" ) {
803 } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
804 if ( units == FG_UNITS_FEET ) {
805 clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
807 clouds_asl = atof( arg.substr(13) );
809 } else if ( arg.find( "--fov=" ) != string::npos ) {
810 parse_fov( arg.substr(6) );
811 } else if ( arg == "--disable-fullscreen" ) {
813 } else if ( arg== "--enable-fullscreen") {
815 } else if ( arg == "--shading-flat") {
817 } else if ( arg == "--shading-smooth") {
819 } else if ( arg == "--disable-skyblend") {
821 } else if ( arg== "--enable-skyblend" ) {
823 } else if ( arg == "--disable-textures" ) {
825 } else if ( arg == "--enable-textures" ) {
827 } else if ( arg == "--disable-wireframe" ) {
829 } else if ( arg == "--enable-wireframe" ) {
831 } else if ( arg.find( "--geometry=" ) != string::npos ) {
832 bool geometry_ok = true;
833 string geometry = arg.substr( 11 );
834 string::size_type i = geometry.find('x');
836 if (i != string::npos) {
837 xsize = atoi(geometry.substr(0, i));
838 ysize = atoi(geometry.substr(i+1));
839 // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
844 if ( xsize <= 0 || ysize <= 0 ) {
850 if ( !geometry_ok ) {
851 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
852 FG_LOG( FG_GENERAL, FG_ALERT,
853 "Setting geometry to " << xsize << 'x' << ysize << '\n');
855 } else if ( arg.find( "--bpp=" ) != string::npos ) {
856 string bits_per_pix = arg.substr( 6 );
857 if ( bits_per_pix == "16" ) {
859 } else if ( bits_per_pix == "24" ) {
861 } else if ( bits_per_pix == "32" ) {
864 } else if ( arg == "--units-feet" ) {
865 units = FG_UNITS_FEET;
866 } else if ( arg == "--units-meters" ) {
867 units = FG_UNITS_METERS;
868 } else if ( arg.find( "--time-offset" ) != string::npos ) {
869 time_offset = parse_time_offset( (arg.substr(14)) );
870 //time_offset_type = FG_TIME_SYS_OFFSET;
871 } else if ( arg.find( "--time-match-real") != string::npos ) {
872 //time_offset = parse_time_offset(arg.substr(18));
873 time_offset_type = FG_TIME_SYS_OFFSET;
874 } else if ( arg.find( "--time-match-local") != string::npos ) {
875 //time_offset = parse_time_offset(arg.substr(18));
876 time_offset_type = FG_TIME_LAT_OFFSET;
877 } else if ( arg.find( "--start-date-sys=") != string::npos ) {
878 time_offset = parse_date( (arg.substr(17)) );
879 time_offset_type = FG_TIME_SYS_ABSOLUTE;
880 } else if ( arg.find( "--start-date-lat=") != string::npos ) {
881 time_offset = parse_date( (arg.substr(17)) );
882 time_offset_type = FG_TIME_LAT_ABSOLUTE;
883 } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
884 time_offset = parse_date( (arg.substr(17)) );
885 time_offset_type = FG_TIME_GMT_ABSOLUTE;
887 } else if ( arg == "--hud-tris" ) {
889 } else if ( arg == "--hud-culled" ) {
891 } else if ( arg.find( "--native=" ) != string::npos ) {
892 parse_channel( "native", arg.substr(9) );
893 } else if ( arg.find( "--garmin=" ) != string::npos ) {
894 parse_channel( "garmin", arg.substr(9) );
895 } else if ( arg.find( "--nmea=" ) != string::npos ) {
896 parse_channel( "nmea", arg.substr(7) );
897 } else if ( arg.find( "--props=" ) != string::npos ) {
898 parse_channel( "props", arg.substr(8) );
899 } else if ( arg.find( "--pve=" ) != string::npos ) {
900 parse_channel( "pve", arg.substr(6) );
901 } else if ( arg.find( "--ray=" ) != string::npos ) {
902 parse_channel( "ray", arg.substr(6) );
903 } else if ( arg.find( "--rul=" ) != string::npos ) {
904 parse_channel( "rul", arg.substr(6) );
905 } else if ( arg.find( "--joyclient=" ) != string::npos ) {
906 parse_channel( "joyclient", arg.substr(12) );
907 #ifdef FG_NETWORK_OLK
908 } else if ( arg == "--disable-network-olk" ) {
910 } else if ( arg== "--enable-network-olk") {
912 } else if ( arg == "--net-hud" ) {
914 } else if ( arg.find( "--net-id=") != string::npos ) {
915 net_id = arg.substr( 9 );
917 } else if ( arg.find( "--prop:" ) == 0 ) {
918 string assign = arg.substr(7);
919 int pos = assign.find('=');
920 if (pos == arg.npos || pos == 0) {
921 FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
922 return FG_OPTIONS_ERROR;
924 string name = assign.substr(0, pos);
925 string value = assign.substr(pos + 1);
926 globals->get_props()->setStringValue(name.c_str(), value);
927 FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
928 << name << " to \"" << value << '"');
929 // $$$ begin - added VS Renganathan, 14 Oct 2K
930 // for multi-window outside window imagery
931 } else if ( arg.find( "--view-offset=" ) != string::npos ) {
932 string woffset = arg.substr( 14 );
933 if ( woffset == "LEFT" ) {
934 default_view_offset = M_PI * 0.25;
935 } else if ( woffset == "RIGHT" ) {
936 default_view_offset = M_PI * 1.75;
937 } else if ( woffset == "CENTER" ) {
938 default_view_offset = 0.00;
940 default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD;
942 FGViewerRPH *pilot_view =
943 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
944 pilot_view->set_view_offset( default_view_offset );
945 pilot_view->set_goal_view_offset( default_view_offset );
946 // $$$ end - added VS Renganathan, 14 Oct 2K
947 } else if ( arg.find( "--visibility=" ) != string::npos ) {
948 visibility = atof( arg.substr( 13 ) );
949 } else if ( arg.find( "--visibility-miles=" ) != string::npos ) {
950 visibility = atof( arg.substr( 19 ) ) * 5280.0 * FEET_TO_METER;
951 } else if ( arg.find( "--wp=" ) != string::npos ) {
952 parse_wp( arg.substr( 5 ) );
953 } else if ( arg.find( "--flight-plan=") != string::npos) {
954 parse_flightplan ( arg.substr (14) );
956 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
957 return FG_OPTIONS_ERROR;
960 return FG_OPTIONS_OK;
964 // Scan the command line options for an fg_root definition and set
966 int FGOptions::scan_command_line_for_root( int argc, char **argv ) {
969 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
972 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
974 string arg = argv[i];
975 if ( arg.find( "--fg-root=" ) != string::npos ) {
976 fg_root = arg.substr( 10 );
982 return FG_OPTIONS_OK;
986 // Scan the config file for an fg_root definition and set just that.
987 int FGOptions::scan_config_file_for_root( const string& path ) {
988 fg_gzifstream in( path );
990 return(FG_OPTIONS_ERROR);
992 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
996 while ( ! in.eof() ) {
999 while ( in.get(c) && c != '\0' ) {
1004 #ifdef GETLINE_NEEDS_TERMINATOR
1005 getline( in, line, '\n' );
1006 #elif defined( macintosh )
1007 getline( in, line, '\r' );
1009 getline( in, line );
1012 if ( line.find( "--fg-root=" ) != string::npos ) {
1013 fg_root = line.substr( 10 );
1019 return FG_OPTIONS_OK;
1023 // Parse the command line options
1024 int FGOptions::parse_command_line( int argc, char **argv ) {
1028 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
1030 while ( i < argc ) {
1031 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
1033 result = parse_option(argv[i]);
1034 if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
1041 return FG_OPTIONS_OK;
1045 // Parse config file options
1046 int FGOptions::parse_config_file( const string& path ) {
1047 fg_gzifstream in( path );
1048 if ( !in.is_open() )
1049 return(FG_OPTIONS_ERROR);
1051 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
1055 while ( ! in.eof() ) {
1058 while ( in.get(c) && c != '\0' ) {
1063 #ifdef GETLINE_NEEDS_TERMINATOR
1064 getline( in, line, '\n' );
1065 #elif defined( macintosh )
1066 getline( in, line, '\r' );
1068 getline( in, line );
1071 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1072 FG_LOG( FG_GENERAL, FG_ALERT,
1073 "Config file parse error: " << path << " '"
1080 return FG_OPTIONS_OK;
1084 // Print usage message
1085 void FGOptions::usage ( void ) {
1086 cout << "Usage: fg [ options ... ]" << endl;
1089 cout << "General Options:" << endl;
1090 cout << "\t--help -h: print usage" << endl;
1091 cout << "\t--fg-root=path: specify the root path for all the data files"
1093 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
1095 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1096 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
1097 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1098 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1099 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1100 cout << "\t--disable-intro-music: disable introduction music" << endl;
1101 cout << "\t--enable-intro-music: enable introduction music" << endl;
1102 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1103 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1105 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1106 cout << "\t--disable-freeze: start out in an running state" << endl;
1107 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1108 cout << "\t--control=mode: primary control mode "
1109 << "(joystick, keyboard, mouse)" << endl;
1112 cout << "Features:" << endl;
1113 cout << "\t--disable-hud: disable heads up display" << endl;
1114 cout << "\t--enable-hud: enable heads up display" << endl;
1115 cout << "\t--disable-panel: disable instrument panel" << endl;
1116 cout << "\t--enable-panel: enable instrumetn panel" << endl;
1117 cout << "\t--disable-sound: disable sound effects" << endl;
1118 cout << "\t--enable-sound: enable sound effects" << endl;
1119 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1120 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1123 cout << "Flight Model:" << endl;
1124 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1125 cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1127 cout << "\t--aircraft=abcd: aircraft model to load" << endl;
1128 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1130 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1131 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1134 cout <<"Aircraft model directory:" << endl;
1135 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1138 cout << "Initial Position and Orientation:" << endl;
1139 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1141 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1143 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1145 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1146 cout << "\t\t(unless --units-meters specified" << endl;
1147 cout << "\t--heading=degrees: heading (yaw) angle in degress (Psi)"
1149 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1150 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1151 cout << "\t--uBody=feet per second: velocity along the body X axis"
1153 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1155 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1157 cout << "\t\t(unless --units-meters specified" << endl;
1158 cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1159 cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1162 cout << "Rendering Options:" << endl;
1163 cout << "\t--fog-disable: disable fog/haze" << endl;
1164 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1165 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1166 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1167 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1168 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1169 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1171 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1172 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1173 cout << "\t--shading-flat: enable flat shading" << endl;
1174 cout << "\t--shading-smooth: enable smooth shading" << endl;
1175 cout << "\t--disable-skyblend: disable sky blending" << endl;
1176 cout << "\t--enable-skyblend: enable sky blending" << endl;
1177 cout << "\t--disable-textures: disable textures" << endl;
1178 cout << "\t--enable-textures: enable textures" << endl;
1179 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1180 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1181 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1183 cout << "\t--view-offset=xxx: set the default forward view direction"
1185 cout << "\t\tas an offset from straight ahead. Allowable values are"
1187 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1188 cout << "\t--visibility=xxx: specify initial visibility in meters" << endl;
1189 cout << "\t--visibility-miles=xxx: specify initial visibility in miles"
1193 cout << "Scenery Options:" << endl;
1194 cout << "\t--tile-radius=n: specify tile radius, must be 1 - 4" << endl;
1197 cout << "Hud Options:" << endl;
1198 cout << "\t--units-feet: Hud displays units in feet" << endl;
1199 cout << "\t--units-meters: Hud displays units in meters" << endl;
1200 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1201 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1205 cout << "Time Options:" << endl;
1206 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1207 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1208 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1209 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1210 << "\t\tFlightGear time" << endl;
1211 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1212 << "\t\tdate/time. Uses your system time " << endl;
1213 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1214 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1215 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1216 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1217 #ifdef FG_NETWORK_OLK
1220 cout << "Network Options:" << endl;
1221 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1222 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1223 cout << "\t--net-hud: Hud displays network info" << endl;
1224 cout << "\t--net-id=name: specify your own callsign" << endl;
1228 cout << "Route/Way Point Options:" << endl;
1229 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1230 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1232 cout << "\t\tinstances of --wp=" << endl;
1233 cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;
1238 FGOptions::~FGOptions( void ) {