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),
195 units(FG_UNITS_FEET),
203 // set initial values/defaults
204 time_offset_type = FG_TIME_SYS_OFFSET;
205 char* envp = ::getenv( "FG_ROOT" );
207 if ( envp != NULL ) {
208 // fg_root could be anywhere, so default to environmental
209 // variable $FG_ROOT if it is set.
212 // Otherwise, default to a random compiled-in location if
213 // $FG_ROOT is not set. This can still be overridden from the
214 // command line or a config file.
217 fg_root = "\\FlightGear";
218 #elif defined( macintosh )
225 // set a possibly independent location for scenery data
226 envp = ::getenv( "FG_SCENERY" );
228 if ( envp != NULL ) {
229 // fg_root could be anywhere, so default to environmental
230 // variable $FG_ROOT if it is set.
233 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
237 airport_id = "KPAO"; // default airport id
238 net_id = "Johnney"; // default pilot's name
240 // initialize port config string list
241 channel_options_list.clear();
245 FGOptions::toggle_panel() {
247 bool freeze = globals->get_freeze();
250 globals->set_freeze(true);
253 panel_status = false;
254 if ( current_panel != NULL )
255 current_panel->setVisibility(false);
258 if ( current_panel != NULL )
259 current_panel->setVisibility(true);
262 fgReshape( xsize, ysize);
265 globals->set_freeze( false );
269 FGOptions::parse_time(const string& time_in) {
270 char *time_str, num[256];
271 double hours, minutes, seconds;
276 time_str = (char *)time_in.c_str();
278 // printf("parse_time(): %s\n", time_str);
281 if ( strlen(time_str) ) {
282 if ( time_str[0] == '+' ) {
285 } else if ( time_str[0] == '-' ) {
290 // printf("sign = %d\n", sign);
293 if ( strlen(time_str) ) {
295 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
296 num[i] = time_str[0];
300 if ( time_str[0] == ':' ) {
305 // printf("hours = %.2lf\n", hours);
311 if ( strlen(time_str) ) {
313 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
314 num[i] = time_str[0];
318 if ( time_str[0] == ':' ) {
323 // printf("minutes = %.2lf\n", minutes);
325 result += minutes / 60.0;
329 if ( strlen(time_str) ) {
331 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
332 num[i] = time_str[0];
338 // printf("seconds = %.2lf\n", seconds);
340 result += seconds / 3600.0;
343 return(sign * result);
347 long int FGOptions::parse_date( const string& date)
350 char * date_str, num[256];
352 // initialize to zero
359 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
360 date_str = (char *)date.c_str();
362 if ( strlen(date_str) ) {
364 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
365 num[i] = date_str[0];
369 if ( date_str[0] == ':' ) {
373 gmt.tm_year = atoi(num) - 1900;
376 if ( strlen(date_str) ) {
378 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
379 num[i] = date_str[0];
383 if ( date_str[0] == ':' ) {
387 gmt.tm_mon = atoi(num) -1;
390 if ( strlen(date_str) ) {
392 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
393 num[i] = date_str[0];
397 if ( date_str[0] == ':' ) {
401 gmt.tm_mday = atoi(num);
404 if ( strlen(date_str) ) {
406 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
407 num[i] = date_str[0];
411 if ( date_str[0] == ':' ) {
415 gmt.tm_hour = atoi(num);
418 if ( strlen(date_str) ) {
420 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
421 num[i] = date_str[0];
425 if ( date_str[0] == ':' ) {
429 gmt.tm_min = atoi(num);
432 if ( strlen(date_str) ) {
434 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
435 num[i] = date_str[0];
439 if ( date_str[0] == ':' ) {
443 gmt.tm_sec = atoi(num);
445 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
446 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
447 //printf ("Date is %s\n", ctime(&theTime));
448 //printf ("in seconds that is %d\n", theTime);
454 // parse degree in the form of [+/-]hhh:mm:ss
455 void FGOptions::parse_control( const string& mode ) {
456 if ( mode == "joystick" ) {
457 control_mode = FG_JOYSTICK;
458 } else if ( mode == "mouse" ) {
459 control_mode = FG_MOUSE;
461 control_mode = FG_KEYBOARD;
466 /// parse degree in the form of [+/-]hhh:mm:ss
468 FGOptions::parse_degree( const string& degree_str) {
469 double result = parse_time( degree_str );
471 // printf("Degree = %.4f\n", result);
477 // parse time offset command line option
479 FGOptions::parse_time_offset( const string& time_str) {
482 // printf("time offset = %s\n", time_str);
485 result = (int)rint(parse_time(time_str) * 3600.0);
487 result = (int)(parse_time(time_str) * 3600.0);
490 // printf("parse_time_offset(): %d\n", result);
496 // Parse --fdm=abcdefg type option
498 FGOptions::parse_fdm( const string& fm ) {
499 // cout << "fdm = " << fm << endl;
502 return FGInterface::FG_ADA;
503 } else if ( fm == "balloon" ) {
504 return FGInterface::FG_BALLOONSIM;
505 } else if ( fm == "external" ) {
506 return FGInterface::FG_EXTERNAL;
507 } else if ( fm == "jsb" ) {
508 return FGInterface::FG_JSBSIM;
509 } else if ( (fm == "larcsim") || (fm == "LaRCsim") ) {
510 return FGInterface::FG_LARCSIM;
511 } else if ( fm == "magic" ) {
512 return FGInterface::FG_MAGICCARPET;
514 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown fdm = " << fm );
518 // we'll never get here, but it makes the compiler happy.
523 // Parse --fov=x.xx type option
525 FGOptions::parse_fov( const string& arg ) {
526 double fov = atof(arg);
528 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
529 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
531 globals->get_current_view()->set_fov( fov );
533 // printf("parse_fov(): result = %.4f\n", fov);
539 // Parse I/O channel option
541 // Format is "--protocol=medium,direction,hz,medium_options,..."
543 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
544 // medium = { serial, socket, file, etc. }
545 // direction = { in, out, bi }
546 // hz = number of times to process channel per second (floating
547 // point values are ok.
549 // Serial example "--nmea=serial,dir,hz,device,baud" where
551 // device = OS device name of serial line to be open()'ed
552 // baud = {300, 1200, 2400, ..., 230400}
554 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
556 // machine = machine name or ip address if client (leave empty if server)
557 // port = port, leave empty to let system choose
558 // style = tcp or udp
560 // File example "--garmin=file,dir,hz,filename" where
562 // filename = file system file name
565 FGOptions::parse_channel( const string& type, const string& channel_str ) {
566 // cout << "Channel string = " << channel_str << endl;
568 channel_options_list.push_back( type + "," + channel_str );
574 // Parse --wp=ID[,alt]
575 bool FGOptions::parse_wp( const string& arg ) {
579 int pos = arg.find( "@" );
580 if ( pos != string::npos ) {
581 id = arg.substr( 0, pos );
582 alt_str = arg.substr( pos + 1 );
583 // cout << "id str = " << id << " alt str = " << alt_str << endl;
584 alt = atof( alt_str.c_str() );
585 if ( units == FG_UNITS_FEET ) {
586 alt *= FEET_TO_METER;
593 if ( fgFindAirportID( id, &a ) ) {
594 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
595 globals->get_route()->add_waypoint( wp );
604 // Parse --flight-plan=[file]
605 bool FGOptions::parse_flightplan(const string& arg)
607 fg_gzifstream infile(arg.c_str());
613 #ifdef GETLINE_NEEDS_TERMINATOR
614 getline( infile, line, '\n' );
615 #elif defined( macintosh )
616 getline( infile, line, '\r' );
618 getline( infile, line );
620 if ( infile.eof() ) {
630 // Parse a single option
631 int FGOptions::parse_option( const string& arg ) {
633 if ( (arg == "--help") || (arg == "-h") ) {
634 // help/usage request
635 return(FG_OPTIONS_HELP);
636 } else if ( arg == "--disable-game-mode") {
638 } else if ( arg == "--enable-game-mode" ) {
640 } else if ( arg == "--disable-splash-screen" ) {
641 splash_screen = false;
642 } else if ( arg == "--enable-splash-screen" ) {
643 splash_screen = true;
644 } else if ( arg == "--disable-intro-music" ) {
646 } else if ( arg == "--enable-intro-music" ) {
648 } else if ( arg == "--disable-mouse-pointer" ) {
650 } else if ( arg == "--enable-mouse-pointer" ) {
652 } else if ( arg == "--disable-freeze" ) {
653 globals->set_freeze( false );
654 } else if ( arg == "--enable-freeze" ) {
655 globals->set_freeze( true );
656 } else if ( arg == "--disable-anti-alias-hud" ) {
657 anti_alias_hud = false;
658 } else if ( arg == "--enable-anti-alias-hud" ) {
659 anti_alias_hud = true;
660 } else if ( arg.find( "--control=") != string::npos ) {
661 parse_control( arg.substr(10) );
662 } else if ( arg == "--disable-auto-coordination" ) {
663 auto_coordination = FG_AUTO_COORD_DISABLED;
664 } else if ( arg == "--enable-auto-coordination" ) {
665 auto_coordination = FG_AUTO_COORD_ENABLED;
666 } else if ( arg == "--disable-hud" ) {
668 current_properties.setBoolValue("/sim/hud/visibility", false);
669 } else if ( arg == "--enable-hud" ) {
671 current_properties.setBoolValue("/sim/hud/visibility", true);
672 } else if ( arg == "--disable-panel" ) {
673 panel_status = false;
674 current_properties.setBoolValue("/sim/panel/visibility", false);
675 if ( current_panel != NULL )
676 current_panel->setVisibility(false);
677 } else if ( arg == "--enable-panel" ) {
679 current_properties.setBoolValue("/sim/panel/visibility", true);
680 if ( current_panel != NULL )
681 current_panel->setVisibility(true);
682 } else if ( arg == "--disable-sound" ) {
684 } else if ( arg == "--enable-sound" ) {
686 } else if ( arg.find( "--airport-id=") != string::npos ) {
687 airport_id = arg.substr( 13 );
688 current_properties.setStringValue("/position/airport-id", airport_id);
689 } else if ( arg.find( "--lon=" ) != string::npos ) {
690 lon = parse_degree( arg.substr(6) );
692 current_properties.setDoubleValue("/position/longitude", lon);
693 current_properties.setStringValue("/position/airport-id", airport_id);
694 } else if ( arg.find( "--lat=" ) != string::npos ) {
695 lat = parse_degree( arg.substr(6) );
697 current_properties.setDoubleValue("/position/latitude", lat);
698 current_properties.setStringValue("/position/airport-id", airport_id);
699 } else if ( arg.find( "--altitude=" ) != string::npos ) {
700 if ( units == FG_UNITS_FEET ) {
701 altitude = atof( arg.substr(11) ) * FEET_TO_METER;
703 altitude = atof( arg.substr(11) );
705 current_properties.setDoubleValue("/position/altitude", altitude);
706 } else if ( arg.find( "--uBody=" ) != string::npos ) {
708 if ( units == FG_UNITS_FEET ) {
709 uBody = atof( arg.substr(8) );
711 uBody = atof( arg.substr(8) ) * FEET_TO_METER;
713 //current_properties.setDoubleValue("/velocities/speed-north", uBody);
714 } else if ( arg.find( "--vBody=" ) != string::npos ) {
716 if ( units == FG_UNITS_FEET ) {
717 vBody = atof( arg.substr(8) );
719 vBody = atof( arg.substr(8) ) * FEET_TO_METER;
721 //current_properties.setDoubleValue("/velocities/speed-east", vBody);
722 } else if ( arg.find( "--wBody=" ) != string::npos ) {
724 if ( units == FG_UNITS_FEET ) {
725 wBody = atof( arg.substr(8) );
727 wBody = atof( arg.substr(8) ) * FEET_TO_METER;
729 } else if ( arg.find( "--vNorth=" ) != string::npos ) {
731 if ( units == FG_UNITS_FEET ) {
732 vNorth = atof( arg.substr(9) );
734 vNorth = atof( arg.substr(9) ) * FEET_TO_METER;
736 current_properties.setDoubleValue("/velocities/speed-north", vNorth);
737 } else if ( arg.find( "--vEast=" ) != string::npos ) {
739 if ( units == FG_UNITS_FEET ) {
740 vEast = atof( arg.substr(8) );
742 vEast = atof( arg.substr(8) ) * FEET_TO_METER;
744 current_properties.setDoubleValue("/velocities/speed-east", vEast);
745 } else if ( arg.find( "--vDown=" ) != string::npos ) {
747 if ( units == FG_UNITS_FEET ) {
748 vDown = atof( arg.substr(8) );
750 vDown = atof( arg.substr(8) ) * FEET_TO_METER;
752 current_properties.setDoubleValue("/velocities/speed-down", vDown);
753 } else if ( arg.find( "--vc=" ) != string::npos) {
755 vkcas=atof( arg.substr(5) );
756 cout << "Got vc: " << vkcas << endl;
757 } else if ( arg.find( "--mach=" ) != string::npos) {
759 mach=atof( arg.substr(7) );
760 } else if ( arg.find( "--heading=" ) != string::npos ) {
761 heading = atof( arg.substr(10) );
762 current_properties.setDoubleValue("/orientation/heading", heading);
763 } else if ( arg.find( "--roll=" ) != string::npos ) {
764 roll = atof( arg.substr(7) );
765 current_properties.setDoubleValue("/orientation/roll", roll);
766 } else if ( arg.find( "--pitch=" ) != string::npos ) {
767 pitch = atof( arg.substr(8) );
768 current_properties.setDoubleValue("/orientation/pitch", pitch);
769 } else if ( arg.find( "--fg-root=" ) != string::npos ) {
770 fg_root = arg.substr( 10 );
771 } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
772 fg_scenery = arg.substr( 13 );
773 } else if ( arg.find( "--fdm=" ) != string::npos ) {
774 flight_model = parse_fdm( arg.substr(6) );
775 current_properties.setIntValue("/sim/flight-model", flight_model);
776 if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
781 } else if ( arg.find( "--aircraft=" ) != string::npos ) {
782 aircraft = arg.substr(11);
783 current_properties.setStringValue("/sim/aircraft", aircraft);
784 } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
785 aircraft_dir = arg.substr(15); // (UIUC)
786 } else if ( arg.find( "--model-hz=" ) != string::npos ) {
787 model_hz = atoi( arg.substr(11) );
788 } else if ( arg.find( "--speed=" ) != string::npos ) {
789 speed_up = atoi( arg.substr(8) );
790 } else if ( arg.find( "--notrim") != string::npos) {
792 } else if ( arg == "--fog-disable" ) {
793 fog = FG_FOG_DISABLED;
794 } else if ( arg == "--fog-fastest" ) {
795 fog = FG_FOG_FASTEST;
796 } else if ( arg == "--fog-nicest" ) {
798 } else if ( arg == "--disable-clouds" ) {
800 } else if ( arg == "--enable-clouds" ) {
802 } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
803 if ( units == FG_UNITS_FEET ) {
804 clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
806 clouds_asl = atof( arg.substr(13) );
808 } else if ( arg.find( "--fov=" ) != string::npos ) {
809 parse_fov( arg.substr(6) );
810 } else if ( arg == "--disable-fullscreen" ) {
812 } else if ( arg== "--enable-fullscreen") {
814 } else if ( arg == "--shading-flat") {
816 } else if ( arg == "--shading-smooth") {
818 } else if ( arg == "--disable-skyblend") {
820 } else if ( arg== "--enable-skyblend" ) {
822 } else if ( arg == "--disable-textures" ) {
824 } else if ( arg == "--enable-textures" ) {
826 } else if ( arg == "--disable-wireframe" ) {
828 } else if ( arg == "--enable-wireframe" ) {
830 } else if ( arg.find( "--geometry=" ) != string::npos ) {
831 bool geometry_ok = true;
832 string geometry = arg.substr( 11 );
833 string::size_type i = geometry.find('x');
835 if (i != string::npos) {
836 xsize = atoi(geometry.substr(0, i));
837 ysize = atoi(geometry.substr(i+1));
838 // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
843 if ( xsize <= 0 || ysize <= 0 ) {
849 if ( !geometry_ok ) {
850 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
851 FG_LOG( FG_GENERAL, FG_ALERT,
852 "Setting geometry to " << xsize << 'x' << ysize << '\n');
854 } else if ( arg.find( "--bpp=" ) != string::npos ) {
855 string bits_per_pix = arg.substr( 6 );
856 if ( bits_per_pix == "16" ) {
858 } else if ( bits_per_pix == "24" ) {
860 } else if ( bits_per_pix == "32" ) {
863 } else if ( arg == "--units-feet" ) {
864 units = FG_UNITS_FEET;
865 } else if ( arg == "--units-meters" ) {
866 units = FG_UNITS_METERS;
867 } else if ( arg.find( "--time-offset" ) != string::npos ) {
868 time_offset = parse_time_offset( (arg.substr(14)) );
869 //time_offset_type = FG_TIME_SYS_OFFSET;
870 } else if ( arg.find( "--time-match-real") != string::npos ) {
871 //time_offset = parse_time_offset(arg.substr(18));
872 time_offset_type = FG_TIME_SYS_OFFSET;
873 } else if ( arg.find( "--time-match-local") != string::npos ) {
874 //time_offset = parse_time_offset(arg.substr(18));
875 time_offset_type = FG_TIME_LAT_OFFSET;
876 } else if ( arg.find( "--start-date-sys=") != string::npos ) {
877 time_offset = parse_date( (arg.substr(17)) );
878 time_offset_type = FG_TIME_SYS_ABSOLUTE;
879 } else if ( arg.find( "--start-date-lat=") != string::npos ) {
880 time_offset = parse_date( (arg.substr(17)) );
881 time_offset_type = FG_TIME_LAT_ABSOLUTE;
882 } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
883 time_offset = parse_date( (arg.substr(17)) );
884 time_offset_type = FG_TIME_GMT_ABSOLUTE;
886 } else if ( arg == "--hud-tris" ) {
888 } else if ( arg == "--hud-culled" ) {
890 } else if ( arg.find( "--native=" ) != string::npos ) {
891 parse_channel( "native", arg.substr(9) );
892 } else if ( arg.find( "--garmin=" ) != string::npos ) {
893 parse_channel( "garmin", arg.substr(9) );
894 } else if ( arg.find( "--nmea=" ) != string::npos ) {
895 parse_channel( "nmea", arg.substr(7) );
896 } else if ( arg.find( "--props=" ) != string::npos ) {
897 parse_channel( "props", arg.substr(8) );
898 } else if ( arg.find( "--pve=" ) != string::npos ) {
899 parse_channel( "pve", arg.substr(6) );
900 } else if ( arg.find( "--ray=" ) != string::npos ) {
901 parse_channel( "ray", arg.substr(6) );
902 } else if ( arg.find( "--rul=" ) != string::npos ) {
903 parse_channel( "rul", arg.substr(6) );
904 } else if ( arg.find( "--joyclient=" ) != string::npos ) {
905 parse_channel( "joyclient", arg.substr(12) );
906 #ifdef FG_NETWORK_OLK
907 } else if ( arg == "--disable-network-olk" ) {
909 } else if ( arg== "--enable-network-olk") {
911 } else if ( arg == "--net-hud" ) {
913 } else if ( arg.find( "--net-id=") != string::npos ) {
914 net_id = arg.substr( 9 );
916 } else if ( arg.find( "--prop:" ) == 0 ) {
917 string assign = arg.substr(7);
918 int pos = assign.find('=');
919 if (pos == arg.npos || pos == 0) {
920 FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
921 return FG_OPTIONS_ERROR;
923 string name = assign.substr(0, pos);
924 string value = assign.substr(pos + 1);
925 current_properties.setStringValue(name.c_str(), value);
926 FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
927 << name << " to \"" << value << '"');
928 // $$$ begin - added VS Renganathan, 14 Oct 2K
929 // for multi-window outside window imagery
930 } else if ( arg.find( "--view-offset=" ) != string::npos ) {
931 string woffset = arg.substr( 14 );
932 if ( woffset == "LEFT" ) {
933 default_view_offset = M_PI * 0.25;
934 } else if ( woffset == "RIGHT" ) {
935 default_view_offset = M_PI * 1.75;
936 } else if ( woffset == "CENTER" ) {
937 default_view_offset = 0.00;
939 default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD;
941 FGViewerRPH *pilot_view =
942 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
943 pilot_view->set_view_offset( default_view_offset );
944 pilot_view->set_goal_view_offset( default_view_offset );
945 // $$$ end - added VS Renganathan, 14 Oct 2K
946 } else if ( arg.find( "--wp=" ) != string::npos ) {
947 parse_wp( arg.substr( 5 ) );
948 } else if ( arg.find( "--flight-plan=") != string::npos) {
949 parse_flightplan ( arg.substr (14) );
951 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
952 return FG_OPTIONS_ERROR;
955 return FG_OPTIONS_OK;
959 // Scan the command line options for an fg_root definition and set
961 int FGOptions::scan_command_line_for_root( int argc, char **argv ) {
964 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
967 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
969 string arg = argv[i];
970 if ( arg.find( "--fg-root=" ) != string::npos ) {
971 fg_root = arg.substr( 10 );
977 return FG_OPTIONS_OK;
981 // Scan the config file for an fg_root definition and set just that.
982 int FGOptions::scan_config_file_for_root( const string& path ) {
983 fg_gzifstream in( path );
985 return(FG_OPTIONS_ERROR);
987 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
991 while ( ! in.eof() ) {
994 while ( in.get(c) && c != '\0' ) {
999 #ifdef GETLINE_NEEDS_TERMINATOR
1000 getline( in, line, '\n' );
1001 #elif defined( macintosh )
1002 getline( in, line, '\r' );
1004 getline( in, line );
1007 if ( line.find( "--fg-root=" ) != string::npos ) {
1008 fg_root = line.substr( 10 );
1014 return FG_OPTIONS_OK;
1018 // Parse the command line options
1019 int FGOptions::parse_command_line( int argc, char **argv ) {
1023 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
1025 while ( i < argc ) {
1026 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
1028 result = parse_option(argv[i]);
1029 if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
1036 return FG_OPTIONS_OK;
1040 // Parse config file options
1041 int FGOptions::parse_config_file( const string& path ) {
1042 fg_gzifstream in( path );
1043 if ( !in.is_open() )
1044 return(FG_OPTIONS_ERROR);
1046 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
1050 while ( ! in.eof() ) {
1053 while ( in.get(c) && c != '\0' ) {
1058 #ifdef GETLINE_NEEDS_TERMINATOR
1059 getline( in, line, '\n' );
1060 #elif defined( macintosh )
1061 getline( in, line, '\r' );
1063 getline( in, line );
1066 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1067 FG_LOG( FG_GENERAL, FG_ALERT,
1068 "Config file parse error: " << path << " '"
1075 return FG_OPTIONS_OK;
1079 // Print usage message
1080 void FGOptions::usage ( void ) {
1081 cout << "Usage: fg [ options ... ]" << endl;
1084 cout << "General Options:" << endl;
1085 cout << "\t--help -h: print usage" << endl;
1086 cout << "\t--fg-root=path: specify the root path for all the data files"
1088 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
1090 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1091 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
1092 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1093 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1094 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1095 cout << "\t--disable-intro-music: disable introduction music" << endl;
1096 cout << "\t--enable-intro-music: enable introduction music" << endl;
1097 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1098 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1100 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1101 cout << "\t--disable-freeze: start out in an running state" << endl;
1102 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1103 cout << "\t--control=mode: primary control mode "
1104 << "(joystick, keyboard, mouse)" << endl;
1107 cout << "Features:" << endl;
1108 cout << "\t--disable-hud: disable heads up display" << endl;
1109 cout << "\t--enable-hud: enable heads up display" << endl;
1110 cout << "\t--disable-panel: disable instrument panel" << endl;
1111 cout << "\t--enable-panel: enable instrumetn panel" << endl;
1112 cout << "\t--disable-sound: disable sound effects" << endl;
1113 cout << "\t--enable-sound: enable sound effects" << endl;
1114 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1115 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1118 cout << "Flight Model:" << endl;
1119 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1120 cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1122 cout << "\t--aircraft=abcd: aircraft model to load" << endl;
1123 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1125 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1126 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1129 cout <<"Aircraft model directory:" << endl;
1130 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1133 cout << "Initial Position and Orientation:" << endl;
1134 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1136 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1138 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1140 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1141 cout << "\t\t(unless --units-meters specified" << endl;
1142 cout << "\t--heading=degrees: heading (yaw) angle in degress (Psi)"
1144 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1145 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1146 cout << "\t--uBody=feet per second: velocity along the body X axis"
1148 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1150 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1152 cout << "\t\t(unless --units-meters specified" << endl;
1153 cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1154 cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1157 cout << "Rendering Options:" << endl;
1158 cout << "\t--fog-disable: disable fog/haze" << endl;
1159 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1160 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1161 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1162 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1163 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1164 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1166 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1167 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1168 cout << "\t--shading-flat: enable flat shading" << endl;
1169 cout << "\t--shading-smooth: enable smooth shading" << endl;
1170 cout << "\t--disable-skyblend: disable sky blending" << endl;
1171 cout << "\t--enable-skyblend: enable sky blending" << endl;
1172 cout << "\t--disable-textures: disable textures" << endl;
1173 cout << "\t--enable-textures: enable textures" << endl;
1174 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1175 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1176 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1178 cout << "\t--view-offset=xxx: set the default forward view direction"
1180 cout << "\t\tas an offset from straight ahead. Allowable values are"
1182 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1185 cout << "Scenery Options:" << endl;
1186 cout << "\t--tile-radius=n: specify tile radius, must be 1 - 4" << endl;
1189 cout << "Hud Options:" << endl;
1190 cout << "\t--units-feet: Hud displays units in feet" << endl;
1191 cout << "\t--units-meters: Hud displays units in meters" << endl;
1192 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1193 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1197 cout << "Time Options:" << endl;
1198 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1199 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1200 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1201 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1202 << "\t\tFlightGear time" << endl;
1203 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1204 << "\t\tdate/time. Uses your system time " << endl;
1205 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1206 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1207 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1208 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1209 #ifdef FG_NETWORK_OLK
1212 cout << "Network Options:" << endl;
1213 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1214 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1215 cout << "\t--net-hud: Hud displays network info" << endl;
1216 cout << "\t--net-id=name: specify your own callsign" << endl;
1220 cout << "Route/Way Point Options:" << endl;
1221 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1222 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1224 cout << "\t\tinstances of --wp=" << endl;
1225 cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;
1230 FGOptions::~FGOptions( void ) {