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),
192 view_mode(FG_VIEW_PILOT),
193 default_view_offset(0),
199 units(FG_UNITS_FEET),
207 // set initial values/defaults
208 time_offset_type = FG_TIME_SYS_OFFSET;
209 char* envp = ::getenv( "FG_ROOT" );
211 if ( envp != NULL ) {
212 // fg_root could be anywhere, so default to environmental
213 // variable $FG_ROOT if it is set.
216 // Otherwise, default to a random compiled-in location if
217 // $FG_ROOT is not set. This can still be overridden from the
218 // command line or a config file.
221 fg_root = "\\FlightGear";
222 #elif defined( macintosh )
229 // set a possibly independent location for scenery data
230 envp = ::getenv( "FG_SCENERY" );
232 if ( envp != NULL ) {
233 // fg_root could be anywhere, so default to environmental
234 // variable $FG_ROOT if it is set.
237 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
241 airport_id = "KPAO"; // default airport id
242 net_id = "Johnney"; // default pilot's name
244 // initialize port config string list
245 channel_options_list.clear();
249 FGOptions::toggle_panel() {
251 bool freeze = globals->get_freeze();
254 globals->set_freeze(true);
257 panel_status = false;
258 if ( current_panel != NULL )
259 current_panel->setVisibility(false);
262 if ( current_panel != NULL )
263 current_panel->setVisibility(true);
266 fgReshape( xsize, ysize);
269 globals->set_freeze( false );
273 FGOptions::parse_time(const string& time_in) {
274 char *time_str, num[256];
275 double hours, minutes, seconds;
280 time_str = (char *)time_in.c_str();
282 // printf("parse_time(): %s\n", time_str);
285 if ( strlen(time_str) ) {
286 if ( time_str[0] == '+' ) {
289 } else if ( time_str[0] == '-' ) {
294 // printf("sign = %d\n", sign);
297 if ( strlen(time_str) ) {
299 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
300 num[i] = time_str[0];
304 if ( time_str[0] == ':' ) {
309 // printf("hours = %.2lf\n", hours);
315 if ( strlen(time_str) ) {
317 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
318 num[i] = time_str[0];
322 if ( time_str[0] == ':' ) {
327 // printf("minutes = %.2lf\n", minutes);
329 result += minutes / 60.0;
333 if ( strlen(time_str) ) {
335 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
336 num[i] = time_str[0];
342 // printf("seconds = %.2lf\n", seconds);
344 result += seconds / 3600.0;
347 return(sign * result);
351 long int FGOptions::parse_date( const string& date)
354 char * date_str, num[256];
356 // initialize to zero
363 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
364 date_str = (char *)date.c_str();
366 if ( strlen(date_str) ) {
368 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
369 num[i] = date_str[0];
373 if ( date_str[0] == ':' ) {
377 gmt.tm_year = atoi(num) - 1900;
380 if ( strlen(date_str) ) {
382 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
383 num[i] = date_str[0];
387 if ( date_str[0] == ':' ) {
391 gmt.tm_mon = atoi(num) -1;
394 if ( strlen(date_str) ) {
396 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
397 num[i] = date_str[0];
401 if ( date_str[0] == ':' ) {
405 gmt.tm_mday = atoi(num);
408 if ( strlen(date_str) ) {
410 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
411 num[i] = date_str[0];
415 if ( date_str[0] == ':' ) {
419 gmt.tm_hour = atoi(num);
422 if ( strlen(date_str) ) {
424 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
425 num[i] = date_str[0];
429 if ( date_str[0] == ':' ) {
433 gmt.tm_min = atoi(num);
436 if ( strlen(date_str) ) {
438 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
439 num[i] = date_str[0];
443 if ( date_str[0] == ':' ) {
447 gmt.tm_sec = atoi(num);
449 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
450 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
451 //printf ("Date is %s\n", ctime(&theTime));
452 //printf ("in seconds that is %d\n", theTime);
458 // parse degree in the form of [+/-]hhh:mm:ss
459 void FGOptions::parse_control( const string& mode ) {
460 if ( mode == "joystick" ) {
461 control_mode = FG_JOYSTICK;
462 } else if ( mode == "mouse" ) {
463 control_mode = FG_MOUSE;
465 control_mode = FG_KEYBOARD;
470 /// parse degree in the form of [+/-]hhh:mm:ss
472 FGOptions::parse_degree( const string& degree_str) {
473 double result = parse_time( degree_str );
475 // printf("Degree = %.4f\n", result);
481 // parse time offset command line option
483 FGOptions::parse_time_offset( const string& time_str) {
486 // printf("time offset = %s\n", time_str);
489 result = (int)rint(parse_time(time_str) * 3600.0);
491 result = (int)(parse_time(time_str) * 3600.0);
494 // printf("parse_time_offset(): %d\n", result);
500 // Parse --tile-diameter=n type option
503 FGOptions::parse_tile_radius( const string& arg ) {
504 int radius = atoi( arg );
506 if ( radius < FG_RADIUS_MIN ) { radius = FG_RADIUS_MIN; }
507 if ( radius > FG_RADIUS_MAX ) { radius = FG_RADIUS_MAX; }
509 // printf("parse_tile_radius(): radius = %d\n", radius);
515 // Parse --fdm=abcdefg type option
517 FGOptions::parse_fdm( const string& fm ) {
518 // cout << "fdm = " << fm << endl;
521 return FGInterface::FG_ADA;
522 } else if ( fm == "balloon" ) {
523 return FGInterface::FG_BALLOONSIM;
524 } else if ( fm == "external" ) {
525 return FGInterface::FG_EXTERNAL;
526 } else if ( fm == "jsb" ) {
527 return FGInterface::FG_JSBSIM;
528 } else if ( (fm == "larcsim") || (fm == "LaRCsim") ) {
529 return FGInterface::FG_LARCSIM;
530 } else if ( fm == "magic" ) {
531 return FGInterface::FG_MAGICCARPET;
533 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown fdm = " << fm );
537 // we'll never get here, but it makes the compiler happy.
542 // Parse --fov=x.xx type option
544 FGOptions::parse_fov( const string& arg ) {
545 double fov = atof(arg);
547 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
548 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
550 // printf("parse_fov(): result = %.4f\n", fov);
556 // Parse I/O channel option
558 // Format is "--protocol=medium,direction,hz,medium_options,..."
560 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
561 // medium = { serial, socket, file, etc. }
562 // direction = { in, out, bi }
563 // hz = number of times to process channel per second (floating
564 // point values are ok.
566 // Serial example "--nmea=serial,dir,hz,device,baud" where
568 // device = OS device name of serial line to be open()'ed
569 // baud = {300, 1200, 2400, ..., 230400}
571 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
573 // machine = machine name or ip address if client (leave empty if server)
574 // port = port, leave empty to let system choose
575 // style = tcp or udp
577 // File example "--garmin=file,dir,hz,filename" where
579 // filename = file system file name
582 FGOptions::parse_channel( const string& type, const string& channel_str ) {
583 // cout << "Channel string = " << channel_str << endl;
585 channel_options_list.push_back( type + "," + channel_str );
591 // Parse --wp=ID[,alt]
592 bool FGOptions::parse_wp( const string& arg ) {
596 int pos = arg.find( "@" );
597 if ( pos != string::npos ) {
598 id = arg.substr( 0, pos );
599 alt_str = arg.substr( pos + 1 );
600 // cout << "id str = " << id << " alt str = " << alt_str << endl;
601 alt = atof( alt_str.c_str() );
602 if ( units == FG_UNITS_FEET ) {
603 alt *= FEET_TO_METER;
610 if ( fgFindAirportID( id, &a ) ) {
611 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
612 globals->get_route()->add_waypoint( wp );
621 // Parse a single option
622 int FGOptions::parse_option( const string& arg ) {
624 if ( (arg == "--help") || (arg == "-h") ) {
625 // help/usage request
626 return(FG_OPTIONS_HELP);
627 } else if ( arg == "--disable-game-mode") {
629 } else if ( arg == "--enable-game-mode" ) {
631 } else if ( arg == "--disable-splash-screen" ) {
632 splash_screen = false;
633 } else if ( arg == "--enable-splash-screen" ) {
634 splash_screen = true;
635 } else if ( arg == "--disable-intro-music" ) {
637 } else if ( arg == "--enable-intro-music" ) {
639 } else if ( arg == "--disable-mouse-pointer" ) {
641 } else if ( arg == "--enable-mouse-pointer" ) {
643 } else if ( arg == "--disable-freeze" ) {
644 globals->set_freeze( false );
645 } else if ( arg == "--enable-freeze" ) {
646 globals->set_freeze( true );
647 } else if ( arg == "--disable-anti-alias-hud" ) {
648 anti_alias_hud = false;
649 } else if ( arg == "--enable-anti-alias-hud" ) {
650 anti_alias_hud = true;
651 } else if ( arg.find( "--control=") != string::npos ) {
652 parse_control( arg.substr(10) );
653 } else if ( arg == "--disable-auto-coordination" ) {
654 auto_coordination = FG_AUTO_COORD_DISABLED;
655 } else if ( arg == "--enable-auto-coordination" ) {
656 auto_coordination = FG_AUTO_COORD_ENABLED;
657 } else if ( arg == "--disable-hud" ) {
659 current_properties.setBoolValue("/sim/hud/visibility", false);
660 } else if ( arg == "--enable-hud" ) {
662 current_properties.setBoolValue("/sim/hud/visibility", true);
663 } else if ( arg == "--disable-panel" ) {
664 panel_status = false;
665 current_properties.setBoolValue("/sim/panel/visibility", false);
666 if ( current_panel != NULL )
667 current_panel->setVisibility(false);
668 } else if ( arg == "--enable-panel" ) {
670 current_properties.setBoolValue("/sim/panel/visibility", true);
671 if ( current_panel != NULL )
672 current_panel->setVisibility(true);
673 // fov *= 0.4232; /* NO!!! */
674 } else if ( arg == "--disable-sound" ) {
676 } else if ( arg == "--enable-sound" ) {
678 } else if ( arg.find( "--airport-id=") != string::npos ) {
679 airport_id = arg.substr( 13 );
680 current_properties.setStringValue("/position/airport-id", airport_id);
681 } else if ( arg.find( "--lon=" ) != string::npos ) {
682 lon = parse_degree( arg.substr(6) );
684 current_properties.setDoubleValue("/position/longitude", lon);
685 current_properties.setStringValue("/position/airport-id", airport_id);
686 } else if ( arg.find( "--lat=" ) != string::npos ) {
687 lat = parse_degree( arg.substr(6) );
689 current_properties.setDoubleValue("/position/latitude", lat);
690 current_properties.setStringValue("/position/airport-id", airport_id);
691 } else if ( arg.find( "--altitude=" ) != string::npos ) {
692 if ( units == FG_UNITS_FEET ) {
693 altitude = atof( arg.substr(11) ) * FEET_TO_METER;
695 altitude = atof( arg.substr(11) );
697 current_properties.setDoubleValue("/position/altitude", altitude);
698 } else if ( arg.find( "--uBody=" ) != string::npos ) {
700 if ( units == FG_UNITS_FEET ) {
701 uBody = atof( arg.substr(8) );
703 uBody = atof( arg.substr(8) ) * FEET_TO_METER;
705 //current_properties.setDoubleValue("/velocities/speed-north", uBody);
706 } else if ( arg.find( "--vBody=" ) != string::npos ) {
708 if ( units == FG_UNITS_FEET ) {
709 vBody = atof( arg.substr(8) );
711 vBody = atof( arg.substr(8) ) * FEET_TO_METER;
713 //current_properties.setDoubleValue("/velocities/speed-east", vBody);
714 } else if ( arg.find( "--wBody=" ) != string::npos ) {
716 if ( units == FG_UNITS_FEET ) {
717 wBody = atof( arg.substr(8) );
719 wBody = atof( arg.substr(8) ) * FEET_TO_METER;
721 } else if ( arg.find( "--vNorth=" ) != string::npos ) {
723 if ( units == FG_UNITS_FEET ) {
724 vNorth = atof( arg.substr(9) );
726 vNorth = atof( arg.substr(9) ) * FEET_TO_METER;
728 current_properties.setDoubleValue("/velocities/speed-north", vNorth);
729 } else if ( arg.find( "--vEast=" ) != string::npos ) {
731 if ( units == FG_UNITS_FEET ) {
732 vEast = atof( arg.substr(8) );
734 vEast = atof( arg.substr(8) ) * FEET_TO_METER;
736 current_properties.setDoubleValue("/velocities/speed-east", vEast);
737 } else if ( arg.find( "--vDown=" ) != string::npos ) {
739 if ( units == FG_UNITS_FEET ) {
740 vDown = atof( arg.substr(8) );
742 vDown = atof( arg.substr(8) ) * FEET_TO_METER;
744 current_properties.setDoubleValue("/velocities/speed-down", vDown);
745 } else if ( arg.find( "--vc=" ) != string::npos) {
747 vkcas=atof( arg.substr(5) );
748 cout << "Got vc: " << vkcas << endl;
749 } else if ( arg.find( "--mach=" ) != string::npos) {
751 mach=atof( arg.substr(7) );
752 } else if ( arg.find( "--heading=" ) != string::npos ) {
753 heading = atof( arg.substr(10) );
754 current_properties.setDoubleValue("/orientation/heading", heading);
755 } else if ( arg.find( "--roll=" ) != string::npos ) {
756 roll = atof( arg.substr(7) );
757 current_properties.setDoubleValue("/orientation/roll", roll);
758 } else if ( arg.find( "--pitch=" ) != string::npos ) {
759 pitch = atof( arg.substr(8) );
760 current_properties.setDoubleValue("/orientation/pitch", pitch);
761 } else if ( arg.find( "--fg-root=" ) != string::npos ) {
762 fg_root = arg.substr( 10 );
763 } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
764 fg_scenery = arg.substr( 13 );
765 } else if ( arg.find( "--fdm=" ) != string::npos ) {
766 flight_model = parse_fdm( arg.substr(6) );
767 current_properties.setIntValue("/sim/flight-model", flight_model);
768 if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
773 } else if ( arg.find( "--aircraft=" ) != string::npos ) {
774 aircraft = arg.substr(11);
775 current_properties.setStringValue("/sim/aircraft", aircraft);
776 } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
777 aircraft_dir = arg.substr(15); // (UIUC)
778 } else if ( arg.find( "--model-hz=" ) != string::npos ) {
779 model_hz = atoi( arg.substr(11) );
780 } else if ( arg.find( "--speed=" ) != string::npos ) {
781 speed_up = atoi( arg.substr(8) );
782 } else if ( arg.find( "--notrim") != string::npos) {
784 } else if ( arg == "--fog-disable" ) {
785 fog = FG_FOG_DISABLED;
786 } else if ( arg == "--fog-fastest" ) {
787 fog = FG_FOG_FASTEST;
788 } else if ( arg == "--fog-nicest" ) {
790 } else if ( arg == "--disable-clouds" ) {
792 } else if ( arg == "--enable-clouds" ) {
794 } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
795 if ( units == FG_UNITS_FEET ) {
796 clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
798 clouds_asl = atof( arg.substr(13) );
800 } else if ( arg.find( "--fov=" ) != string::npos ) {
801 fov = parse_fov( arg.substr(6) );
802 } else if ( arg == "--disable-fullscreen" ) {
804 } else if ( arg== "--enable-fullscreen") {
806 } else if ( arg == "--shading-flat") {
808 } else if ( arg == "--shading-smooth") {
810 } else if ( arg == "--disable-skyblend") {
812 } else if ( arg== "--enable-skyblend" ) {
814 } else if ( arg == "--disable-textures" ) {
816 } else if ( arg == "--enable-textures" ) {
818 } else if ( arg == "--disable-wireframe" ) {
820 } else if ( arg == "--enable-wireframe" ) {
822 } else if ( arg.find( "--geometry=" ) != string::npos ) {
823 bool geometry_ok = true;
824 string geometry = arg.substr( 11 );
825 string::size_type i = geometry.find('x');
827 if (i != string::npos) {
828 xsize = atoi(geometry.substr(0, i));
829 ysize = atoi(geometry.substr(i+1));
830 // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
835 if ( xsize <= 0 || ysize <= 0 ) {
841 if ( !geometry_ok ) {
842 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
843 FG_LOG( FG_GENERAL, FG_ALERT,
844 "Setting geometry to " << xsize << 'x' << ysize << '\n');
846 } else if ( arg.find( "--bpp=" ) != string::npos ) {
847 string bits_per_pix = arg.substr( 6 );
848 if ( bits_per_pix == "16" ) {
850 } else if ( bits_per_pix == "24" ) {
852 } else if ( bits_per_pix == "32" ) {
855 } else if ( arg == "--units-feet" ) {
856 units = FG_UNITS_FEET;
857 } else if ( arg == "--units-meters" ) {
858 units = FG_UNITS_METERS;
859 } else if ( arg.find( "--tile-radius=" ) != string::npos ) {
860 tile_radius = parse_tile_radius( arg.substr(14) );
861 tile_diameter = tile_radius * 2 + 1;
862 } else if ( arg.find( "--time-offset" ) != string::npos ) {
863 time_offset = parse_time_offset( (arg.substr(14)) );
864 //time_offset_type = FG_TIME_SYS_OFFSET;
865 } else if ( arg.find( "--time-match-real") != string::npos ) {
866 //time_offset = parse_time_offset(arg.substr(18));
867 time_offset_type = FG_TIME_SYS_OFFSET;
868 } else if ( arg.find( "--time-match-local") != string::npos ) {
869 //time_offset = parse_time_offset(arg.substr(18));
870 time_offset_type = FG_TIME_LAT_OFFSET;
871 } else if ( arg.find( "--start-date-sys=") != string::npos ) {
872 time_offset = parse_date( (arg.substr(17)) );
873 time_offset_type = FG_TIME_SYS_ABSOLUTE;
874 } else if ( arg.find( "--start-date-lat=") != string::npos ) {
875 time_offset = parse_date( (arg.substr(17)) );
876 time_offset_type = FG_TIME_LAT_ABSOLUTE;
877 } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
878 time_offset = parse_date( (arg.substr(17)) );
879 time_offset_type = FG_TIME_GMT_ABSOLUTE;
881 } else if ( arg == "--hud-tris" ) {
883 } else if ( arg == "--hud-culled" ) {
885 } else if ( arg.find( "--native=" ) != string::npos ) {
886 parse_channel( "native", arg.substr(9) );
887 } else if ( arg.find( "--garmin=" ) != string::npos ) {
888 parse_channel( "garmin", arg.substr(9) );
889 } else if ( arg.find( "--nmea=" ) != string::npos ) {
890 parse_channel( "nmea", arg.substr(7) );
891 } else if ( arg.find( "--props=" ) != string::npos ) {
892 parse_channel( "props", arg.substr(8) );
893 } else if ( arg.find( "--pve=" ) != string::npos ) {
894 parse_channel( "pve", arg.substr(6) );
895 } else if ( arg.find( "--ray=" ) != string::npos ) {
896 parse_channel( "ray", arg.substr(6) );
897 } else if ( arg.find( "--rul=" ) != string::npos ) {
898 parse_channel( "rul", arg.substr(6) );
899 } else if ( arg.find( "--joyclient=" ) != string::npos ) {
900 parse_channel( "joyclient", arg.substr(12) );
901 #ifdef FG_NETWORK_OLK
902 } else if ( arg == "--disable-network-olk" ) {
904 } else if ( arg== "--enable-network-olk") {
906 } else if ( arg == "--net-hud" ) {
908 } else if ( arg.find( "--net-id=") != string::npos ) {
909 net_id = arg.substr( 9 );
911 } else if ( arg.find( "--prop:" ) == 0 ) {
912 string assign = arg.substr(7);
913 int pos = assign.find('=');
914 if (pos == arg.npos || pos == 0) {
915 FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
916 return FG_OPTIONS_ERROR;
918 string name = assign.substr(0, pos);
919 string value = assign.substr(pos + 1);
920 current_properties.setStringValue(name.c_str(), value);
921 FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
922 << name << " to \"" << value << '"');
923 // $$$ begin - added VS Renganathan, 14 Oct 2K
924 // for multi-window outside window imagery
925 } else if ( arg.find( "--view-offset=" ) != string::npos ) {
926 string woffset = arg.substr( 14 );
927 if ( woffset == "LEFT" ) {
928 default_view_offset = M_PI * 0.25;
929 } else if ( woffset == "RIGHT" ) {
930 default_view_offset = M_PI * 1.75;
931 } else if ( woffset == "CENTER" ) {
932 default_view_offset = 0.00;
934 default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD;
936 FGViewerRPH *pilot_view =
937 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
938 pilot_view->set_view_offset( default_view_offset );
939 pilot_view->set_goal_view_offset( default_view_offset );
940 // $$$ end - added VS Renganathan, 14 Oct 2K
941 } else if ( arg.find( "--wp=" ) != string::npos ) {
942 parse_wp( arg.substr( 5 ) );
944 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
945 return FG_OPTIONS_ERROR;
948 return FG_OPTIONS_OK;
952 // Scan the command line options for an fg_root definition and set
954 int FGOptions::scan_command_line_for_root( int argc, char **argv ) {
957 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
960 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
962 string arg = argv[i];
963 if ( arg.find( "--fg-root=" ) != string::npos ) {
964 fg_root = arg.substr( 10 );
970 return FG_OPTIONS_OK;
974 // Scan the config file for an fg_root definition and set just that.
975 int FGOptions::scan_config_file_for_root( const string& path ) {
976 fg_gzifstream in( path );
978 return(FG_OPTIONS_ERROR);
980 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
984 while ( ! in.eof() ) {
987 while ( in.get(c) && c != '\0' ) {
992 #ifdef GETLINE_NEEDS_TERMINATOR
993 getline( in, line, '\n' );
994 #elif defined( macintosh )
995 getline( in, line, '\r' );
1000 if ( line.find( "--fg-root=" ) != string::npos ) {
1001 fg_root = line.substr( 10 );
1007 return FG_OPTIONS_OK;
1011 // Parse the command line options
1012 int FGOptions::parse_command_line( int argc, char **argv ) {
1016 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
1018 while ( i < argc ) {
1019 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
1021 result = parse_option(argv[i]);
1022 if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
1029 return FG_OPTIONS_OK;
1033 // Parse config file options
1034 int FGOptions::parse_config_file( const string& path ) {
1035 fg_gzifstream in( path );
1036 if ( !in.is_open() )
1037 return(FG_OPTIONS_ERROR);
1039 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
1043 while ( ! in.eof() ) {
1046 while ( in.get(c) && c != '\0' ) {
1051 #ifdef GETLINE_NEEDS_TERMINATOR
1052 getline( in, line, '\n' );
1053 #elif defined( macintosh )
1054 getline( in, line, '\r' );
1056 getline( in, line );
1059 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1060 FG_LOG( FG_GENERAL, FG_ALERT,
1061 "Config file parse error: " << path << " '"
1068 return FG_OPTIONS_OK;
1072 // Print usage message
1073 void FGOptions::usage ( void ) {
1074 cout << "Usage: fg [ options ... ]" << endl;
1077 cout << "General Options:" << endl;
1078 cout << "\t--help -h: print usage" << endl;
1079 cout << "\t--fg-root=path: specify the root path for all the data files"
1081 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
1083 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1084 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
1085 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1086 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1087 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1088 cout << "\t--disable-intro-music: disable introduction music" << endl;
1089 cout << "\t--enable-intro-music: enable introduction music" << endl;
1090 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1091 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1093 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1094 cout << "\t--disable-freeze: start out in an running state" << endl;
1095 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1096 cout << "\t--control=mode: primary control mode "
1097 << "(joystick, keyboard, mouse)" << endl;
1100 cout << "Features:" << endl;
1101 cout << "\t--disable-hud: disable heads up display" << endl;
1102 cout << "\t--enable-hud: enable heads up display" << endl;
1103 cout << "\t--disable-panel: disable instrument panel" << endl;
1104 cout << "\t--enable-panel: enable instrumetn panel" << endl;
1105 cout << "\t--disable-sound: disable sound effects" << endl;
1106 cout << "\t--enable-sound: enable sound effects" << endl;
1107 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1108 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1111 cout << "Flight Model:" << endl;
1112 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1113 cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1115 cout << "\t--aircraft=abcd: aircraft model to load" << endl;
1116 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1118 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1119 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1122 cout <<"Aircraft model directory:" << endl;
1123 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1126 cout << "Initial Position and Orientation:" << endl;
1127 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1129 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1131 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1133 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1134 cout << "\t\t(unless --units-meters specified" << endl;
1135 cout << "\t--heading=degrees: heading (yaw) angle in degress (Psi)"
1137 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1138 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1139 cout << "\t--uBody=feet per second: velocity along the body X axis"
1141 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1143 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1145 cout << "\t\t(unless --units-meters specified" << endl;
1146 cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1147 cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1150 cout << "Rendering Options:" << endl;
1151 cout << "\t--fog-disable: disable fog/haze" << endl;
1152 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1153 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1154 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1155 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1156 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1157 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1159 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1160 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1161 cout << "\t--shading-flat: enable flat shading" << endl;
1162 cout << "\t--shading-smooth: enable smooth shading" << endl;
1163 cout << "\t--disable-skyblend: disable sky blending" << endl;
1164 cout << "\t--enable-skyblend: enable sky blending" << endl;
1165 cout << "\t--disable-textures: disable textures" << endl;
1166 cout << "\t--enable-textures: enable textures" << endl;
1167 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1168 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1169 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1171 cout << "\t--view-offset=xxx: set the default forward view direction"
1173 cout << "\t\tas an offset from straight ahead. Allowable values are"
1175 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1178 cout << "Scenery Options:" << endl;
1179 cout << "\t--tile-radius=n: specify tile radius, must be 1 - 4" << endl;
1182 cout << "Hud Options:" << endl;
1183 cout << "\t--units-feet: Hud displays units in feet" << endl;
1184 cout << "\t--units-meters: Hud displays units in meters" << endl;
1185 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1186 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1190 cout << "Time Options:" << endl;
1191 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1192 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1193 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1194 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1195 << "\t\tFlightGear time" << endl;
1196 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1197 << "\t\tdate/time. Uses your system time " << endl;
1198 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1199 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1200 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1201 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1202 #ifdef FG_NETWORK_OLK
1205 cout << "Network Options:" << endl;
1206 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1207 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1208 cout << "\t--net-hud: Hud displays network info" << endl;
1209 cout << "\t--net-id=name: specify your own callsign" << endl;
1213 cout << "Route/Way Point Options:" << endl;
1214 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1215 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1217 cout << "\t\tinstances of --wp=" << endl;
1222 FGOptions::~FGOptions( void ) {