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 //$$$ begin - added Neetha
671 } else if ( arg == "--enable-default_hud" ) {
674 globals->get_props()->setBoolValue("/sim/hud/visibility", true);
675 } else if ( arg == "--enable-ada_hud" ) {
678 globals->get_props()->setBoolValue("/sim/hud/visibility", true);
679 //$$$ end - added Neetha
680 } else if ( arg == "--disable-panel" ) {
681 panel_status = false;
682 globals->get_props()->setBoolValue("/sim/panel/visibility", false);
683 if ( current_panel != NULL )
684 current_panel->setVisibility(false);
685 } else if ( arg == "--enable-panel" ) {
687 globals->get_props()->setBoolValue("/sim/panel/visibility", true);
688 if ( current_panel != NULL )
689 current_panel->setVisibility(true);
690 } else if ( arg == "--disable-sound" ) {
692 } else if ( arg == "--enable-sound" ) {
694 } else if ( arg.find( "--airport-id=") != string::npos ) {
695 airport_id = arg.substr( 13 );
696 globals->get_props()->setStringValue("/position/airport-id", airport_id);
697 } else if ( arg.find( "--lon=" ) != string::npos ) {
698 lon = parse_degree( arg.substr(6) );
700 globals->get_props()->setDoubleValue("/position/longitude", lon);
701 globals->get_props()->setStringValue("/position/airport-id", airport_id);
702 } else if ( arg.find( "--lat=" ) != string::npos ) {
703 lat = parse_degree( arg.substr(6) );
705 globals->get_props()->setDoubleValue("/position/latitude", lat);
706 globals->get_props()->setStringValue("/position/airport-id", airport_id);
707 } else if ( arg.find( "--altitude=" ) != string::npos ) {
708 if ( units == FG_UNITS_FEET ) {
709 altitude = atof( arg.substr(11) ) * FEET_TO_METER;
711 altitude = atof( arg.substr(11) );
713 globals->get_props()->setDoubleValue("/position/altitude", altitude);
714 } else if ( arg.find( "--uBody=" ) != string::npos ) {
716 if ( units == FG_UNITS_FEET ) {
717 uBody = atof( arg.substr(8) );
719 uBody = atof( arg.substr(8) ) * FEET_TO_METER;
721 //globals->get_props()->setDoubleValue("/velocities/speed-north", uBody);
722 } else if ( arg.find( "--vBody=" ) != string::npos ) {
724 if ( units == FG_UNITS_FEET ) {
725 vBody = atof( arg.substr(8) );
727 vBody = atof( arg.substr(8) ) * FEET_TO_METER;
729 //globals->get_props()->setDoubleValue("/velocities/speed-east", vBody);
730 } else if ( arg.find( "--wBody=" ) != string::npos ) {
732 if ( units == FG_UNITS_FEET ) {
733 wBody = atof( arg.substr(8) );
735 wBody = atof( arg.substr(8) ) * FEET_TO_METER;
737 } else if ( arg.find( "--vNorth=" ) != string::npos ) {
739 if ( units == FG_UNITS_FEET ) {
740 vNorth = atof( arg.substr(9) );
742 vNorth = atof( arg.substr(9) ) * FEET_TO_METER;
744 globals->get_props()->setDoubleValue("/velocities/speed-north", vNorth);
745 } else if ( arg.find( "--vEast=" ) != string::npos ) {
747 if ( units == FG_UNITS_FEET ) {
748 vEast = atof( arg.substr(8) );
750 vEast = atof( arg.substr(8) ) * FEET_TO_METER;
752 globals->get_props()->setDoubleValue("/velocities/speed-east", vEast);
753 } else if ( arg.find( "--vDown=" ) != string::npos ) {
755 if ( units == FG_UNITS_FEET ) {
756 vDown = atof( arg.substr(8) );
758 vDown = atof( arg.substr(8) ) * FEET_TO_METER;
760 globals->get_props()->setDoubleValue("/velocities/speed-down", vDown);
761 } else if ( arg.find( "--vc=" ) != string::npos) {
763 vkcas=atof( arg.substr(5) );
764 cout << "Got vc: " << vkcas << endl;
765 } else if ( arg.find( "--mach=" ) != string::npos) {
767 mach=atof( arg.substr(7) );
768 } else if ( arg.find( "--heading=" ) != string::npos ) {
769 heading = atof( arg.substr(10) );
770 globals->get_props()->setDoubleValue("/orientation/heading", heading);
771 } else if ( arg.find( "--roll=" ) != string::npos ) {
772 roll = atof( arg.substr(7) );
773 globals->get_props()->setDoubleValue("/orientation/roll", roll);
774 } else if ( arg.find( "--pitch=" ) != string::npos ) {
775 pitch = atof( arg.substr(8) );
776 globals->get_props()->setDoubleValue("/orientation/pitch", pitch);
777 } else if ( arg.find( "--fg-root=" ) != string::npos ) {
778 fg_root = arg.substr( 10 );
779 } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
780 fg_scenery = arg.substr( 13 );
781 } else if ( arg.find( "--fdm=" ) != string::npos ) {
782 flight_model = parse_fdm( arg.substr(6) );
783 globals->get_props()->setIntValue("/sim/flight-model", flight_model);
784 if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
789 } else if ( arg.find( "--aircraft=" ) != string::npos ) {
790 aircraft = arg.substr(11);
791 globals->get_props()->setStringValue("/sim/aircraft", aircraft);
792 } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
793 aircraft_dir = arg.substr(15); // (UIUC)
794 } else if ( arg.find( "--model-hz=" ) != string::npos ) {
795 model_hz = atoi( arg.substr(11) );
796 } else if ( arg.find( "--speed=" ) != string::npos ) {
797 speed_up = atoi( arg.substr(8) );
798 } else if ( arg.find( "--notrim") != string::npos) {
800 } else if ( arg == "--fog-disable" ) {
801 fog = FG_FOG_DISABLED;
802 } else if ( arg == "--fog-fastest" ) {
803 fog = FG_FOG_FASTEST;
804 } else if ( arg == "--fog-nicest" ) {
806 } else if ( arg == "--disable-clouds" ) {
808 } else if ( arg == "--enable-clouds" ) {
810 } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
811 if ( units == FG_UNITS_FEET ) {
812 clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
814 clouds_asl = atof( arg.substr(13) );
816 } else if ( arg.find( "--fov=" ) != string::npos ) {
817 parse_fov( arg.substr(6) );
818 } else if ( arg == "--disable-fullscreen" ) {
820 } else if ( arg== "--enable-fullscreen") {
822 } else if ( arg == "--shading-flat") {
824 } else if ( arg == "--shading-smooth") {
826 } else if ( arg == "--disable-skyblend") {
828 } else if ( arg== "--enable-skyblend" ) {
830 } else if ( arg == "--disable-textures" ) {
832 } else if ( arg == "--enable-textures" ) {
834 } else if ( arg == "--disable-wireframe" ) {
836 } else if ( arg == "--enable-wireframe" ) {
838 } else if ( arg.find( "--geometry=" ) != string::npos ) {
839 bool geometry_ok = true;
840 string geometry = arg.substr( 11 );
841 string::size_type i = geometry.find('x');
843 if (i != string::npos) {
844 xsize = atoi(geometry.substr(0, i));
845 ysize = atoi(geometry.substr(i+1));
846 // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
851 if ( xsize <= 0 || ysize <= 0 ) {
857 if ( !geometry_ok ) {
858 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
859 FG_LOG( FG_GENERAL, FG_ALERT,
860 "Setting geometry to " << xsize << 'x' << ysize << '\n');
862 } else if ( arg.find( "--bpp=" ) != string::npos ) {
863 string bits_per_pix = arg.substr( 6 );
864 if ( bits_per_pix == "16" ) {
866 } else if ( bits_per_pix == "24" ) {
868 } else if ( bits_per_pix == "32" ) {
871 } else if ( arg == "--units-feet" ) {
872 units = FG_UNITS_FEET;
873 } else if ( arg == "--units-meters" ) {
874 units = FG_UNITS_METERS;
875 } else if ( arg.find( "--time-offset" ) != string::npos ) {
876 time_offset = parse_time_offset( (arg.substr(14)) );
877 //time_offset_type = FG_TIME_SYS_OFFSET;
878 } else if ( arg.find( "--time-match-real") != string::npos ) {
879 //time_offset = parse_time_offset(arg.substr(18));
880 time_offset_type = FG_TIME_SYS_OFFSET;
881 } else if ( arg.find( "--time-match-local") != string::npos ) {
882 //time_offset = parse_time_offset(arg.substr(18));
883 time_offset_type = FG_TIME_LAT_OFFSET;
884 } else if ( arg.find( "--start-date-sys=") != string::npos ) {
885 time_offset = parse_date( (arg.substr(17)) );
886 time_offset_type = FG_TIME_SYS_ABSOLUTE;
887 } else if ( arg.find( "--start-date-lat=") != string::npos ) {
888 time_offset = parse_date( (arg.substr(17)) );
889 time_offset_type = FG_TIME_LAT_ABSOLUTE;
890 } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
891 time_offset = parse_date( (arg.substr(17)) );
892 time_offset_type = FG_TIME_GMT_ABSOLUTE;
894 } else if ( arg == "--hud-tris" ) {
896 } else if ( arg == "--hud-culled" ) {
898 } else if ( arg.find( "--native=" ) != string::npos ) {
899 parse_channel( "native", arg.substr(9) );
900 } else if ( arg.find( "--garmin=" ) != string::npos ) {
901 parse_channel( "garmin", arg.substr(9) );
902 } else if ( arg.find( "--nmea=" ) != string::npos ) {
903 parse_channel( "nmea", arg.substr(7) );
904 } else if ( arg.find( "--props=" ) != string::npos ) {
905 parse_channel( "props", arg.substr(8) );
906 } else if ( arg.find( "--pve=" ) != string::npos ) {
907 parse_channel( "pve", arg.substr(6) );
908 } else if ( arg.find( "--ray=" ) != string::npos ) {
909 parse_channel( "ray", arg.substr(6) );
910 } else if ( arg.find( "--rul=" ) != string::npos ) {
911 parse_channel( "rul", arg.substr(6) );
912 } else if ( arg.find( "--joyclient=" ) != string::npos ) {
913 parse_channel( "joyclient", arg.substr(12) );
914 #ifdef FG_NETWORK_OLK
915 } else if ( arg == "--disable-network-olk" ) {
917 } else if ( arg== "--enable-network-olk") {
919 } else if ( arg == "--net-hud" ) {
921 } else if ( arg.find( "--net-id=") != string::npos ) {
922 net_id = arg.substr( 9 );
924 } else if ( arg.find( "--prop:" ) == 0 ) {
925 string assign = arg.substr(7);
926 int pos = assign.find('=');
927 if (pos == arg.npos || pos == 0) {
928 FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
929 return FG_OPTIONS_ERROR;
931 string name = assign.substr(0, pos);
932 string value = assign.substr(pos + 1);
933 globals->get_props()->setStringValue(name.c_str(), value);
934 FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
935 << name << " to \"" << value << '"');
936 // $$$ begin - added VS Renganathan, 14 Oct 2K
937 // for multi-window outside window imagery
938 } else if ( arg.find( "--view-offset=" ) != string::npos ) {
939 string woffset = arg.substr( 14 );
940 if ( woffset == "LEFT" ) {
941 default_view_offset = M_PI * 0.25;
942 } else if ( woffset == "RIGHT" ) {
943 default_view_offset = M_PI * 1.75;
944 } else if ( woffset == "CENTER" ) {
945 default_view_offset = 0.00;
947 default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD;
949 FGViewerRPH *pilot_view =
950 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
951 pilot_view->set_view_offset( default_view_offset );
952 pilot_view->set_goal_view_offset( default_view_offset );
953 // $$$ end - added VS Renganathan, 14 Oct 2K
954 } else if ( arg.find( "--visibility=" ) != string::npos ) {
955 visibility = atof( arg.substr( 13 ) );
956 } else if ( arg.find( "--visibility-miles=" ) != string::npos ) {
957 visibility = atof( arg.substr( 19 ) ) * 5280.0 * FEET_TO_METER;
958 } else if ( arg.find( "--wp=" ) != string::npos ) {
959 parse_wp( arg.substr( 5 ) );
960 } else if ( arg.find( "--flight-plan=") != string::npos) {
961 parse_flightplan ( arg.substr (14) );
963 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
964 return FG_OPTIONS_ERROR;
967 return FG_OPTIONS_OK;
971 // Scan the command line options for an fg_root definition and set
973 int FGOptions::scan_command_line_for_root( int argc, char **argv ) {
976 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
979 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
981 string arg = argv[i];
982 if ( arg.find( "--fg-root=" ) != string::npos ) {
983 fg_root = arg.substr( 10 );
989 return FG_OPTIONS_OK;
993 // Scan the config file for an fg_root definition and set just that.
994 int FGOptions::scan_config_file_for_root( const string& path ) {
995 fg_gzifstream in( path );
997 return(FG_OPTIONS_ERROR);
999 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
1003 while ( ! in.eof() ) {
1006 while ( in.get(c) && c != '\0' ) {
1011 #ifdef GETLINE_NEEDS_TERMINATOR
1012 getline( in, line, '\n' );
1013 #elif defined( macintosh )
1014 getline( in, line, '\r' );
1016 getline( in, line );
1019 if ( line.find( "--fg-root=" ) != string::npos ) {
1020 fg_root = line.substr( 10 );
1026 return FG_OPTIONS_OK;
1030 // Parse the command line options
1031 int FGOptions::parse_command_line( int argc, char **argv ) {
1035 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
1037 while ( i < argc ) {
1038 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
1040 result = parse_option(argv[i]);
1041 if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
1048 return FG_OPTIONS_OK;
1052 // Parse config file options
1053 int FGOptions::parse_config_file( const string& path ) {
1054 fg_gzifstream in( path );
1055 if ( !in.is_open() )
1056 return(FG_OPTIONS_ERROR);
1058 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
1062 while ( ! in.eof() ) {
1065 while ( in.get(c) && c != '\0' ) {
1070 #ifdef GETLINE_NEEDS_TERMINATOR
1071 getline( in, line, '\n' );
1072 #elif defined( macintosh )
1073 getline( in, line, '\r' );
1075 getline( in, line );
1078 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1079 FG_LOG( FG_GENERAL, FG_ALERT,
1080 "Config file parse error: " << path << " '"
1087 return FG_OPTIONS_OK;
1091 // Print usage message
1092 void FGOptions::usage ( void ) {
1093 cout << "Usage: fg [ options ... ]" << endl;
1096 cout << "General Options:" << endl;
1097 cout << "\t--help -h: print usage" << endl;
1098 cout << "\t--fg-root=path: specify the root path for all the data files"
1100 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
1102 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1103 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
1104 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1105 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1106 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1107 cout << "\t--disable-intro-music: disable introduction music" << endl;
1108 cout << "\t--enable-intro-music: enable introduction music" << endl;
1109 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1110 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1112 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1113 cout << "\t--disable-freeze: start out in an running state" << endl;
1114 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1115 cout << "\t--control=mode: primary control mode "
1116 << "(joystick, keyboard, mouse)" << endl;
1119 cout << "Features:" << endl;
1120 cout << "\t--disable-hud: disable heads up display" << endl;
1121 cout << "\t--enable-hud: enable heads up display" << endl;
1122 cout << "\t--disable-panel: disable instrument panel" << endl;
1123 cout << "\t--enable-panel: enable instrumetn panel" << endl;
1124 cout << "\t--disable-sound: disable sound effects" << endl;
1125 cout << "\t--enable-sound: enable sound effects" << endl;
1126 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1127 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1130 cout << "Flight Model:" << endl;
1131 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1132 cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1134 cout << "\t--aircraft=abcd: aircraft model to load" << endl;
1135 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1137 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1138 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1141 cout <<"Aircraft model directory:" << endl;
1142 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1145 cout << "Initial Position and Orientation:" << endl;
1146 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1148 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1150 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1152 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1153 cout << "\t\t(unless --units-meters specified" << endl;
1154 cout << "\t--heading=degrees: heading (yaw) angle in degress (Psi)"
1156 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1157 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1158 cout << "\t--uBody=feet per second: velocity along the body X axis"
1160 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1162 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1164 cout << "\t\t(unless --units-meters specified" << endl;
1165 cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1166 cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1169 cout << "Rendering Options:" << endl;
1170 cout << "\t--fog-disable: disable fog/haze" << endl;
1171 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1172 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1173 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1174 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1175 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1176 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1178 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1179 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1180 cout << "\t--shading-flat: enable flat shading" << endl;
1181 cout << "\t--shading-smooth: enable smooth shading" << endl;
1182 cout << "\t--disable-skyblend: disable sky blending" << endl;
1183 cout << "\t--enable-skyblend: enable sky blending" << endl;
1184 cout << "\t--disable-textures: disable textures" << endl;
1185 cout << "\t--enable-textures: enable textures" << endl;
1186 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1187 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1188 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1190 cout << "\t--view-offset=xxx: set the default forward view direction"
1192 cout << "\t\tas an offset from straight ahead. Allowable values are"
1194 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1195 cout << "\t--visibility=xxx: specify initial visibility in meters" << endl;
1196 cout << "\t--visibility-miles=xxx: specify initial visibility in miles"
1200 cout << "Scenery Options:" << endl;
1201 cout << "\t--tile-radius=n: specify tile radius, must be 1 - 4" << endl;
1204 cout << "Hud Options:" << endl;
1205 cout << "\t--units-feet: Hud displays units in feet" << endl;
1206 cout << "\t--units-meters: Hud displays units in meters" << endl;
1207 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1208 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1212 cout << "Time Options:" << endl;
1213 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1214 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1215 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1216 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1217 << "\t\tFlightGear time" << endl;
1218 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1219 << "\t\tdate/time. Uses your system time " << endl;
1220 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1221 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1222 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1223 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1224 #ifdef FG_NETWORK_OLK
1227 cout << "Network Options:" << endl;
1228 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1229 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1230 cout << "\t--net-hud: Hud displays network info" << endl;
1231 cout << "\t--net-id=name: specify your own callsign" << endl;
1235 cout << "Route/Way Point Options:" << endl;
1236 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1237 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1239 cout << "\t\tinstances of --wp=" << endl;
1240 cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;
1245 FGOptions::~FGOptions( void ) {