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 #include <simgear/compiler.h>
30 #include <math.h> // rint()
32 #include <stdlib.h> // atof(), atoi()
37 #include <simgear/misc/fgstream.hxx>
39 // #include <Include/general.hxx>
40 // #include <Airports/simple.hxx>
41 // #include <Cockpit/cockpit.hxx>
42 // #include <FDM/flight.hxx>
43 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
45 # include <NetworkOLK/network.h>
48 #include "globals.hxx"
49 #include "fg_init.hxx"
50 #include "fg_props.hxx"
51 #include "options.hxx"
54 FG_USING_NAMESPACE(std);
57 #define NEW_DEFAULT_MODEL_HZ 120
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() );
91 * Set a few fail-safe default property values.
93 * These should all be set in $FG_ROOT/preferences.xml, but just
94 * in case, we provide some initial sane values here. This method
95 * should be invoked *before* reading any init files.
100 // set a possibly independent location for scenery data
101 char *envp = ::getenv( "FG_SCENERY" );
103 if ( envp != NULL ) {
104 // fg_root could be anywhere, so default to environmental
105 // variable $FG_ROOT if it is set.
106 globals->set_fg_scenery(envp);
108 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
109 globals->set_fg_scenery("");
111 // Position (Globe, AZ)
112 fgSetDouble("/position/longitude", -110.6642444);
113 fgSetDouble("/position/latitude", 33.3528917);
114 fgSetDouble("/position/altitude", -9999.0);
117 fgSetDouble("/orientation/heading", 270);
118 fgSetDouble("/orientation/roll", 0);
119 fgSetDouble("/orientation/pitch", 0.424);
122 fgSetString("/sim/startup/speed-set", "knots");
123 fgSetDouble("/velocities/uBody", 0.0);
124 fgSetDouble("/velocities/vBody", 0.0);
125 fgSetDouble("/velocities/wBody", 0.0);
126 fgSetDouble("/velocities/speed-north", 0.0);
127 fgSetDouble("/velocities/speed-east", 0.0);
128 fgSetDouble("/velocities/speed-down", 0.0);
129 fgSetDouble("/velocities/airspeed", 0.0);
130 fgSetDouble("/velocities/mach", 0.0);
133 fgSetBool("/sim/startup/game-mode", false);
134 fgSetBool("/sim/startup/splash-screen", true);
135 fgSetBool("/sim/startup/intro-music", true);
136 fgSetString("/sim/startup/mouse-pointer", "disabled");
137 fgSetString("/sim/control-mode", "joystick");
138 fgSetBool("/sim/auto-coordination", false);
141 fgSetBool("/sim/hud/visibility", false);
142 fgSetBool("/sim/panel/visibility", true);
143 fgSetBool("/sim/sound", true);
144 fgSetBool("/sim/hud/antialiased", false);
146 // Flight Model options
147 fgSetString("/sim/flight-model", "larcsim");
148 fgSetString("/sim/aircraft", "c172");
149 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
150 fgSetInt("/sim/speed-up", 1);
151 fgSetBool("/sim/startup/trim", false);
152 fgSetBool("/sim/startup/onground", true);
155 fgSetString("/sim/rendering/fog", "nicest");
156 fgSetBool("/environment/clouds/status", true);
157 fgSetDouble("/environment/clouds/altitude", 5000);
158 fgSetBool("/sim/startup/fullscreen", false);
159 fgSetBool("/sim/rendering/shading", true);
160 fgSetBool("/sim/rendering/skyblend", true);
161 fgSetBool("/sim/rendering/textures", true);
162 fgSetBool("/sim/rendering/wireframe", false);
163 fgSetInt("/sim/startup/xsize", 800);
164 fgSetInt("/sim/startup/ysize", 600);
165 fgSetInt("/sim/rendering/bits-per-pixel", 16);
166 fgSetString("/sim/view-mode", "pilot");
167 fgSetDouble("/sim/startup/view-offset", 0);
168 fgSetDouble("/environment/visibility", 20000);
171 fgSetString("/sim/startup/units", "feet");
172 fgSetString("/sim/hud/frame-stat-type", "tris");
175 fgSetInt("/sim/startup/time-offset", 0);
176 fgSetString("/sim/startup/time-offset-type", "system-offset");
178 fgSetBool("/sim/networking/network-olk", false);
179 fgSetString("/sim/networking/call-sign", "Johnny");
183 parse_time(const string& time_in) {
184 char *time_str, num[256];
185 double hours, minutes, seconds;
190 time_str = (char *)time_in.c_str();
192 // printf("parse_time(): %s\n", time_str);
195 if ( strlen(time_str) ) {
196 if ( time_str[0] == '+' ) {
199 } else if ( time_str[0] == '-' ) {
204 // printf("sign = %d\n", sign);
207 if ( strlen(time_str) ) {
209 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
210 num[i] = time_str[0];
214 if ( time_str[0] == ':' ) {
219 // printf("hours = %.2lf\n", hours);
225 if ( strlen(time_str) ) {
227 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
228 num[i] = time_str[0];
232 if ( time_str[0] == ':' ) {
237 // printf("minutes = %.2lf\n", minutes);
239 result += minutes / 60.0;
243 if ( strlen(time_str) ) {
245 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
246 num[i] = time_str[0];
252 // printf("seconds = %.2lf\n", seconds);
254 result += seconds / 3600.0;
257 return(sign * result);
262 parse_date( const string& date)
265 char * date_str, num[256];
267 // initialize to zero
274 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
275 date_str = (char *)date.c_str();
277 if ( strlen(date_str) ) {
279 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
280 num[i] = date_str[0];
284 if ( date_str[0] == ':' ) {
288 gmt.tm_year = atoi(num) - 1900;
291 if ( strlen(date_str) ) {
293 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
294 num[i] = date_str[0];
298 if ( date_str[0] == ':' ) {
302 gmt.tm_mon = atoi(num) -1;
305 if ( strlen(date_str) ) {
307 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
308 num[i] = date_str[0];
312 if ( date_str[0] == ':' ) {
316 gmt.tm_mday = atoi(num);
319 if ( strlen(date_str) ) {
321 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
322 num[i] = date_str[0];
326 if ( date_str[0] == ':' ) {
330 gmt.tm_hour = atoi(num);
333 if ( strlen(date_str) ) {
335 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
336 num[i] = date_str[0];
340 if ( date_str[0] == ':' ) {
344 gmt.tm_min = atoi(num);
347 if ( strlen(date_str) ) {
349 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
350 num[i] = date_str[0];
354 if ( date_str[0] == ':' ) {
358 gmt.tm_sec = atoi(num);
360 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
361 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
362 //printf ("Date is %s\n", ctime(&theTime));
363 //printf ("in seconds that is %d\n", theTime);
369 /// parse degree in the form of [+/-]hhh:mm:ss
371 parse_degree( const string& degree_str) {
372 double result = parse_time( degree_str );
374 // printf("Degree = %.4f\n", result);
380 // parse time offset command line option
382 parse_time_offset( const string& time_str) {
385 // printf("time offset = %s\n", time_str);
388 result = (int)rint(parse_time(time_str) * 3600.0);
390 result = (int)(parse_time(time_str) * 3600.0);
393 // printf("parse_time_offset(): %d\n", result);
399 // Parse --fov=x.xx type option
401 parse_fov( const string& arg ) {
402 double fov = atof(arg);
404 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
405 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
407 fgSetDouble("/sim/field-of-view", fov);
409 // printf("parse_fov(): result = %.4f\n", fov);
415 // Parse I/O channel option
417 // Format is "--protocol=medium,direction,hz,medium_options,..."
419 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
420 // medium = { serial, socket, file, etc. }
421 // direction = { in, out, bi }
422 // hz = number of times to process channel per second (floating
423 // point values are ok.
425 // Serial example "--nmea=serial,dir,hz,device,baud" where
427 // device = OS device name of serial line to be open()'ed
428 // baud = {300, 1200, 2400, ..., 230400}
430 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
432 // machine = machine name or ip address if client (leave empty if server)
433 // port = port, leave empty to let system choose
434 // style = tcp or udp
436 // File example "--garmin=file,dir,hz,filename" where
438 // filename = file system file name
441 parse_channel( const string& type, const string& channel_str ) {
442 // cout << "Channel string = " << channel_str << endl;
444 globals->get_channel_options_list().push_back( type + "," + channel_str );
450 // Parse --wp=ID[,alt]
452 parse_wp( const string& arg ) {
456 int pos = arg.find( "@" );
457 if ( pos != string::npos ) {
458 id = arg.substr( 0, pos );
459 alt_str = arg.substr( pos + 1 );
460 // cout << "id str = " << id << " alt str = " << alt_str << endl;
461 alt = atof( alt_str.c_str() );
462 if ( fgGetString("/sim/startup/units") == "feet" ) {
463 alt *= FEET_TO_METER;
470 if ( fgFindAirportID( id, &a ) ) {
471 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
472 globals->get_route()->add_waypoint( wp );
481 // Parse --flight-plan=[file]
483 parse_flightplan(const string& arg)
485 fg_gzifstream infile(arg.c_str());
491 #ifdef GETLINE_NEEDS_TERMINATOR
492 getline( infile, line, '\n' );
493 #elif defined( macintosh )
494 getline( infile, line, '\r' );
496 getline( infile, line );
498 if ( infile.eof() ) {
508 // Parse a single option
510 parse_option (const string& arg)
513 if ( (arg == "--help") || (arg == "-h") ) {
514 // help/usage request
515 return(FG_OPTIONS_HELP);
516 } else if ( arg == "--disable-game-mode") {
517 fgSetBool("/sim/startup/game-mode", false);
518 } else if ( arg == "--enable-game-mode" ) {
519 fgSetBool("/sim/startup/game-mode", true);
520 } else if ( arg == "--disable-splash-screen" ) {
521 fgSetBool("/sim/startup/splash-screen", false);
522 } else if ( arg == "--enable-splash-screen" ) {
523 fgSetBool("/sim/startup/splash-screen", true);
524 } else if ( arg == "--disable-intro-music" ) {
525 fgSetBool("/sim/startup/intro-music", false);
526 } else if ( arg == "--enable-intro-music" ) {
527 fgSetBool("/sim/startup/intro-music", true);
528 } else if ( arg == "--disable-mouse-pointer" ) {
529 fgSetString("/sim/startup/mouse-pointer", "disabled");
530 } else if ( arg == "--enable-mouse-pointer" ) {
531 fgSetString("/sim/startup/mouse-pointer", "enabled");
532 } else if ( arg == "--disable-freeze" ) {
533 fgSetBool("/sim/freeze", false);
534 } else if ( arg == "--enable-freeze" ) {
535 fgSetBool("/sim/freeze", true);
536 } else if ( arg == "--disable-anti-alias-hud" ) {
537 fgSetBool("/sim/hud/antialiased", false);
538 } else if ( arg == "--enable-anti-alias-hud" ) {
539 fgSetBool("/sim/hud/antialiased", true);
540 } else if ( arg.find( "--control=") != string::npos ) {
541 fgSetString("/sim/control-mode", arg.substr(10));
542 } else if ( arg == "--disable-auto-coordination" ) {
543 fgSetBool("/sim/auto-coordination", false);
544 } else if ( arg == "--enable-auto-coordination" ) {
545 fgSetBool("/sim/auto-coordination", true);
546 } else if ( arg == "--disable-hud" ) {
547 fgSetBool("/sim/hud/visibility", false);
548 } else if ( arg == "--enable-hud" ) {
549 fgSetBool("/sim/hud/visibility", true);
550 } else if ( arg == "--disable-panel" ) {
551 fgSetBool("/sim/panel/visibility", false);
552 } else if ( arg == "--enable-panel" ) {
553 fgSetBool("/sim/panel/visibility", true);
554 } else if ( arg == "--disable-sound" ) {
555 fgSetBool("/sim/sound", false);
556 } else if ( arg == "--enable-sound" ) {
557 fgSetBool("/sim/sound", true);
558 } else if ( arg.find( "--airport-id=") != string::npos ) {
559 // NB: changed property name!!!
560 fgSetString("/sim/startup/airport-id", arg.substr(13));
561 } else if ( arg.find( "--lon=" ) != string::npos ) {
562 fgSetDouble("/position/longitude",
563 parse_degree(arg.substr(6)));
564 fgSetString("/position/airport-id", "");
565 } else if ( arg.find( "--lat=" ) != string::npos ) {
566 fgSetDouble("/position/latitude",
567 parse_degree(arg.substr(6)));
568 fgSetString("/position/airport-id", "");
569 } else if ( arg.find( "--altitude=" ) != string::npos ) {
570 fgSetBool("/sim/startup/onground", false);
571 if ( fgGetString("/sim/startup/units") == "feet" )
572 fgSetDouble("/position/altitude", atof(arg.substr(11)));
574 fgSetDouble("/position/altitude",
575 atof(arg.substr(11)) * METER_TO_FEET);
576 } else if ( arg.find( "--uBody=" ) != string::npos ) {
577 fgSetString("/sim/startup/speed-set", "UVW");
578 // FIXME: the units are totally confused here
579 if ( fgGetString("/sim/startup/units") == "feet" )
580 fgSetDouble("/velocities/uBody", atof(arg.substr(8)));
582 fgSetDouble("/velocities/uBody",
583 atof(arg.substr(8)) * FEET_TO_METER);
584 } else if ( arg.find( "--vBody=" ) != string::npos ) {
585 fgSetString("/sim/startup/speed-set", "UVW");
586 // FIXME: the units are totally confused here
587 if ( fgGetString("/sim/startup/units") == "feet" )
588 fgSetDouble("/velocities/vBody", atof(arg.substr(8)));
590 fgSetDouble("/velocities/vBody",
591 atof(arg.substr(8)) * FEET_TO_METER);
592 } else if ( arg.find( "--wBody=" ) != string::npos ) {
593 fgSetString("/sim/startup/speed-set", "UVW");
594 // FIXME: the units are totally confused here
595 if ( fgGetString("/sim/startup/units") == "feet" )
596 fgSetDouble("/velocities/wBody", atof(arg.substr(8)));
598 fgSetDouble("/velocities/wBody",
599 atof(arg.substr(8)) * FEET_TO_METER);
600 } else if ( arg.find( "--vNorth=" ) != string::npos ) {
601 fgSetString("/sim/startup/speed-set", "NED");
602 // FIXME: the units are totally confused here
603 if ( fgGetString("/sim/startup/units") == "feet" )
604 fgSetDouble("/velocities/speed-north", atof(arg.substr(8)));
606 fgSetDouble("/velocities/speed-north",
607 atof(arg.substr(8)) * FEET_TO_METER);
608 } else if ( arg.find( "--vEast=" ) != string::npos ) {
609 fgSetString("/sim/startup/speed-set", "NED");
610 // FIXME: the units are totally confused here
611 if ( fgGetString("/sim/startup/units") == "feet" )
612 fgSetDouble("/velocities/speed-east", atof(arg.substr(8)));
614 fgSetDouble("/velocities/speed-east",
615 atof(arg.substr(8)) * FEET_TO_METER);
616 } else if ( arg.find( "--vDown=" ) != string::npos ) {
617 fgSetString("/sim/startup/speed-set", "NED");
618 // FIXME: the units are totally confused here
619 if ( fgGetString("/sim/startup/units") == "feet" )
620 fgSetDouble("/velocities/speed-down", atof(arg.substr(8)));
622 fgSetDouble("/velocities/speed-down",
623 atof(arg.substr(8)) * FEET_TO_METER);
624 } else if ( arg.find( "--vc=" ) != string::npos) {
625 fgSetString("/sim/startup/speed-set", "knots");
626 fgSetDouble("/velocities/airspeed", atof(arg.substr(5)));
627 } else if ( arg.find( "--mach=" ) != string::npos) {
628 fgSetString("/sim/startup/speed-set", "mach");
629 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
630 } else if ( arg.find( "--heading=" ) != string::npos ) {
631 fgSetDouble("/orientation/heading", atof(arg.substr(10)));
632 } else if ( arg.find( "--roll=" ) != string::npos ) {
633 fgSetDouble("/orientation/roll", atof(arg.substr(7)));
634 } else if ( arg.find( "--pitch=" ) != string::npos ) {
635 fgSetDouble("/orientation/pitch", atof(arg.substr(8)));
636 } else if ( arg.find( "--fg-root=" ) != string::npos ) {
637 globals->set_fg_root(arg.substr( 10 ));
638 } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
639 globals->set_fg_scenery(arg.substr( 13 ));
640 } else if ( arg.find( "--fdm=" ) != string::npos ) {
641 fgSetString("/sim/flight-model", arg.substr(6));
642 } else if ( arg.find( "--aircraft=" ) != string::npos ) {
643 fgSetString("/sim/aircraft", arg.substr(11));
644 } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
645 fgSetString("/sim/aircraft-dir", arg.substr(15));
646 } else if ( arg.find( "--model-hz=" ) != string::npos ) {
647 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
648 } else if ( arg.find( "--speed=" ) != string::npos ) {
649 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
650 } else if ( arg.find( "--trim") != string::npos) {
651 fgSetBool("/sim/startup/trim", true);
652 } else if ( arg.find( "--notrim") != string::npos) {
653 fgSetBool("/sim/startup/trim", false);
654 } else if ( arg.find( "--on-ground") != string::npos) {
655 fgSetBool("/sim/startup/onground", true);
656 } else if ( arg.find( "--in-air") != string::npos) {
657 fgSetBool("/sim/startup/onground", false);
658 } else if ( arg == "--fog-disable" ) {
659 fgSetString("/sim/rendering/fog", "disabled");
660 } else if ( arg == "--fog-fastest" ) {
661 fgSetString("/sim/rendering/fog", "fastest");
662 } else if ( arg == "--fog-nicest" ) {
663 fgSetString("/sim/fog", "nicest");
664 } else if ( arg == "--disable-clouds" ) {
665 fgSetBool("/environment/clouds/status", false);
666 } else if ( arg == "--enable-clouds" ) {
667 fgSetBool("/environment/clouds/status", true);
668 } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
669 // FIXME: check units
670 if ( fgGetString("/sim/startup/units") == "feet" )
671 fgSetDouble("/environment/clouds/altitude",
672 atof(arg.substr(13)) * FEET_TO_METER);
674 fgSetDouble("/environment/clouds/altitude",
675 atof(arg.substr(13)));
676 } else if ( arg.find( "--fov=" ) != string::npos ) {
677 parse_fov( arg.substr(6) );
678 } else if ( arg == "--disable-fullscreen" ) {
679 fgSetBool("/sim/startup/fullscreen", false);
680 } else if ( arg== "--enable-fullscreen") {
681 fgSetBool("/sim/startup/fullscreen", true);
682 } else if ( arg == "--shading-flat") {
683 fgSetBool("/sim/rendering/shading", false);
684 } else if ( arg == "--shading-smooth") {
685 fgSetBool("/sim/rendering/shading", true);
686 } else if ( arg == "--disable-skyblend") {
687 fgSetBool("/sim/rendering/skyblend", false);
688 } else if ( arg== "--enable-skyblend" ) {
689 fgSetBool("/sim/rendering/skyblend", true);
690 } else if ( arg == "--disable-textures" ) {
691 fgSetBool("/sim/rendering/textures", false);
692 } else if ( arg == "--enable-textures" ) {
693 fgSetBool("/sim/rendering/textures", true);
694 } else if ( arg == "--disable-wireframe" ) {
695 fgSetBool("/sim/rendering/wireframe", false);
696 } else if ( arg == "--enable-wireframe" ) {
697 fgSetBool("/sim/rendering/wireframe", true);
698 } else if ( arg.find( "--geometry=" ) != string::npos ) {
699 bool geometry_ok = true;
700 int xsize = 0, ysize = 0;
701 string geometry = arg.substr( 11 );
702 string::size_type i = geometry.find('x');
704 if (i != string::npos) {
705 xsize = atoi(geometry.substr(0, i));
706 ysize = atoi(geometry.substr(i+1));
711 if ( xsize <= 0 || ysize <= 0 ) {
717 if ( !geometry_ok ) {
718 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
719 FG_LOG( FG_GENERAL, FG_ALERT,
720 "Setting geometry to " << xsize << 'x' << ysize << '\n');
722 FG_LOG( FG_GENERAL, FG_INFO,
723 "Setting geometry to " << xsize << 'x' << ysize << '\n');
724 fgSetInt("/sim/startup/xsize", xsize);
725 fgSetInt("/sim/startup/ysize", ysize);
727 } else if ( arg.find( "--bpp=" ) != string::npos ) {
728 string bits_per_pix = arg.substr( 6 );
729 if ( bits_per_pix == "16" ) {
730 fgSetInt("/sim/rendering/bits-per-pixel", 16);
731 } else if ( bits_per_pix == "24" ) {
732 fgSetInt("/sim/rendering/bits-per-pixel", 24);
733 } else if ( bits_per_pix == "32" ) {
734 fgSetInt("/sim/rendering/bits-per-pixel", 32);
736 FG_LOG(FG_GENERAL, FG_ALERT, "Unsupported bpp " << bits_per_pix);
738 } else if ( arg == "--units-feet" ) {
739 fgSetString("/sim/startup/units", "feet");
740 } else if ( arg == "--units-meters" ) {
741 fgSetString("/sim/startup/units", "meters");
742 } else if ( arg.find( "--time-offset" ) != string::npos ) {
743 fgSetInt("/sim/startup/time-offset",
744 parse_time_offset( (arg.substr(14)) ));
745 } else if ( arg.find( "--time-match-real") != string::npos ) {
746 fgSetString("/sim/startup/time-offset_type",
748 } else if ( arg.find( "--time-match-local") != string::npos ) {
749 fgSetString("/sim/startup/time-offset_type",
751 } else if ( arg.find( "--start-date-sys=") != string::npos ) {
752 fgSetInt("/sim/startup/time-offset",
753 parse_date((arg.substr(17))));
754 fgSetString("/sim/startup/time-offset-type", "system");
755 } else if ( arg.find( "--start-date-lat=") != string::npos ) {
756 fgSetInt("/sim/startup/time-offset",
757 parse_date((arg.substr(17))));
758 fgSetString("/sim/startup/time-offset-type",
760 } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
761 fgSetInt("/sim/startup/time-offset",
762 parse_date((arg.substr(17))));
763 fgSetString("/sim/startup/time-offset-type", "gmt");
764 } else if ( arg == "--hud-tris" ) {
765 fgSetString("/sim/hud/frame-stat-type", "tris");
766 } else if ( arg == "--hud-culled" ) {
767 fgSetString("/sim/hud/frame-stat-type", "culled");
768 } else if ( arg.find( "--native=" ) != string::npos ) {
769 parse_channel( "native", arg.substr(9) );
770 } else if ( arg.find( "--garmin=" ) != string::npos ) {
771 parse_channel( "garmin", arg.substr(9) );
772 } else if ( arg.find( "--nmea=" ) != string::npos ) {
773 parse_channel( "nmea", arg.substr(7) );
774 } else if ( arg.find( "--props=" ) != string::npos ) {
775 parse_channel( "props", arg.substr(8) );
776 } else if ( arg.find( "--pve=" ) != string::npos ) {
777 parse_channel( "pve", arg.substr(6) );
778 } else if ( arg.find( "--ray=" ) != string::npos ) {
779 parse_channel( "ray", arg.substr(6) );
780 } else if ( arg.find( "--rul=" ) != string::npos ) {
781 parse_channel( "rul", arg.substr(6) );
782 } else if ( arg.find( "--joyclient=" ) != string::npos ) {
783 parse_channel( "joyclient", arg.substr(12) );
784 #ifdef FG_NETWORK_OLK
785 } else if ( arg == "--disable-network-olk" ) {
786 fgSetBool("/sim/networking/olk", false);
787 } else if ( arg== "--enable-network-olk") {
788 fgSetBool("/sim/networking/olk", true);
789 } else if ( arg == "--net-hud" ) {
790 fgSetBool("/sim/hud/net-display", true);
791 net_hud_display = 1; // FIXME
792 } else if ( arg.find( "--net-id=") != string::npos ) {
793 fgSetString("sim/networking/call-sign", arg.substr(9));
795 } else if ( arg.find( "--prop:" ) == 0 ) {
796 string assign = arg.substr(7);
797 int pos = assign.find('=');
798 if (pos == arg.npos || pos == 0) {
799 FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
800 return FG_OPTIONS_ERROR;
802 string name = assign.substr(0, pos);
803 string value = assign.substr(pos + 1);
804 fgSetString(name.c_str(), value);
805 FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
806 << name << " to \"" << value << '"');
807 // $$$ begin - added VS Renganathan, 14 Oct 2K
808 // for multi-window outside window imagery
809 } else if ( arg.find( "--view-offset=" ) != string::npos ) {
810 string woffset = arg.substr( 14 );
811 double default_view_offset = 0.0;
812 if ( woffset == "LEFT" ) {
813 default_view_offset = FG_PI * 0.25;
814 } else if ( woffset == "RIGHT" ) {
815 default_view_offset = FG_PI * 1.75;
816 } else if ( woffset == "CENTER" ) {
817 default_view_offset = 0.00;
819 default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD;
821 FGViewerRPH *pilot_view =
822 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
823 pilot_view->set_view_offset( default_view_offset );
824 pilot_view->set_goal_view_offset( default_view_offset );
825 fgSetDouble("/sim/startup/view-offset", default_view_offset);
826 // $$$ end - added VS Renganathan, 14 Oct 2K
827 } else if ( arg.find( "--visibility=" ) != string::npos ) {
828 fgSetDouble("/environment/visibility", atof(arg.substr(13)));
829 } else if ( arg.find( "--visibility-miles=" ) != string::npos ) {
830 double visibility = atof(arg.substr(19)) * 5280.0 * FEET_TO_METER;
831 fgSetDouble("/environment/visibility", visibility);
832 } else if ( arg.find( "--wind=" ) == 0 ) {
833 string val = arg.substr(7);
834 int pos = val.find('@');
835 if (pos == string::npos) {
836 FG_LOG(FG_GENERAL, FG_ALERT, "bad wind value " << val);
837 return FG_OPTIONS_ERROR;
839 double dir = atof(val.substr(0,pos).c_str());
840 double speed = atof(val.substr(pos+1).c_str());
841 FG_LOG(FG_GENERAL, FG_INFO, "WIND: " << dir << '@' <<
842 speed << " knots" << endl);
844 speed *= NM_TO_METER * METER_TO_FEET * (1.0/3600);
849 fgSetDouble("/environment/wind-north",
851 fgSetDouble("/environment/wind-east",
853 } else if ( arg.find( "--wp=" ) != string::npos ) {
854 parse_wp( arg.substr( 5 ) );
855 } else if ( arg.find( "--flight-plan=") != string::npos) {
856 parse_flightplan ( arg.substr (14) );
858 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
859 return FG_OPTIONS_ERROR;
862 return FG_OPTIONS_OK;
866 // Scan the command line options for an fg_root definition and set
869 fgScanForRoot (int argc, char **argv)
873 FG_LOG(FG_GENERAL, FG_INFO, "Scanning for root: command line");
876 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
878 string arg = argv[i];
879 if ( arg.find( "--fg-root=" ) != string::npos ) {
880 return arg.substr( 10 );
890 // Scan the config file for an fg_root definition and set just that.
892 fgScanForRoot (const string& path)
894 fg_gzifstream in( path );
898 FG_LOG( FG_GENERAL, FG_INFO, "Scanning for root: " << path );
902 while ( ! in.eof() ) {
905 while ( in.get(c) && c != '\0' ) {
910 #ifdef GETLINE_NEEDS_TERMINATOR
911 getline( in, line, '\n' );
912 #elif defined( macintosh )
913 getline( in, line, '\r' );
918 if ( line.find( "--fg-root=" ) != string::npos ) {
919 return line.substr( 10 );
929 // Parse the command line options
931 fgParseOptions (int argc, char **argv) {
935 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
938 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
940 result = parse_option(argv[i]);
941 if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
951 // Parse config file options
953 fgParseOptions (const string& path) {
954 fg_gzifstream in( path );
958 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
962 while ( ! in.eof() ) {
965 while ( in.get(c) && c != '\0' ) {
970 #ifdef GETLINE_NEEDS_TERMINATOR
971 getline( in, line, '\n' );
972 #elif defined( macintosh )
973 getline( in, line, '\r' );
978 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
979 FG_LOG( FG_GENERAL, FG_ALERT,
980 "Config file parse error: " << path << " '"
990 // Print usage message
994 cout << "Usage: fg [ options ... ]" << endl;
997 cout << "General Options:" << endl;
998 cout << "\t--help -h: print usage" << endl;
999 cout << "\t--fg-root=path: specify the root path for all the data files"
1001 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
1003 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1004 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
1005 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1006 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1007 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1008 cout << "\t--disable-intro-music: disable introduction music" << endl;
1009 cout << "\t--enable-intro-music: enable introduction music" << endl;
1010 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1011 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1013 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1014 cout << "\t--disable-freeze: start out in an running state" << endl;
1015 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1016 cout << "\t--control=mode: primary control mode "
1017 << "(joystick, keyboard, mouse)" << endl;
1020 cout << "Features:" << endl;
1021 cout << "\t--disable-hud: disable heads up display" << endl;
1022 cout << "\t--enable-hud: enable heads up display" << endl;
1023 cout << "\t--disable-panel: disable instrument panel" << endl;
1024 cout << "\t--enable-panel: enable instrumetn panel" << endl;
1025 cout << "\t--disable-sound: disable sound effects" << endl;
1026 cout << "\t--enable-sound: enable sound effects" << endl;
1027 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1028 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1031 cout << "Flight Model:" << endl;
1032 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1033 cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1035 cout << "\t--aircraft=abcd: aircraft model to load" << endl;
1036 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1038 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1039 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1040 cout << "\t--on-ground: Start up at ground level (default)" << endl;
1041 cout << "\t--in-air: Start up in air (implied by specifying an initial"
1042 << " altitude above ground level." << endl;
1043 cout << "\t--wind=DIR@SPEED: specify wind coming from DIR (degrees) at SPEED (knots)" << endl;
1047 cout <<"Aircraft model directory:" << endl;
1048 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1051 cout << "Initial Position and Orientation:" << endl;
1052 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1054 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1056 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1058 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1059 cout << "\t\t(unless --units-meters specified" << endl;
1060 cout << "\t--heading=degrees: heading (yaw) angle in degress (Psi)"
1062 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1063 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1064 cout << "\t--uBody=feet per second: velocity along the body X axis"
1066 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1068 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1070 cout << "\t\t(unless --units-meters specified" << endl;
1071 cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1072 cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1075 cout << "Rendering Options:" << endl;
1076 cout << "\t--fog-disable: disable fog/haze" << endl;
1077 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1078 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1079 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1080 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1081 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1082 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1084 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1085 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1086 cout << "\t--shading-flat: enable flat shading" << endl;
1087 cout << "\t--shading-smooth: enable smooth shading" << endl;
1088 cout << "\t--disable-skyblend: disable sky blending" << endl;
1089 cout << "\t--enable-skyblend: enable sky blending" << endl;
1090 cout << "\t--disable-textures: disable textures" << endl;
1091 cout << "\t--enable-textures: enable textures" << endl;
1092 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1093 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1094 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1096 cout << "\t--view-offset=xxx: set the default forward view direction"
1098 cout << "\t\tas an offset from straight ahead. Allowable values are"
1100 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1101 cout << "\t--visibility=xxx: specify initial visibility in meters" << endl;
1102 cout << "\t--visibility-miles=xxx: specify initial visibility in miles"
1106 cout << "Scenery Options:" << endl;
1107 cout << "\t--tile-radius=n: specify tile radius, must be 1 - 4" << endl;
1110 cout << "Hud Options:" << endl;
1111 cout << "\t--units-feet: Hud displays units in feet" << endl;
1112 cout << "\t--units-meters: Hud displays units in meters" << endl;
1113 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1114 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1118 cout << "Time Options:" << endl;
1119 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1120 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1121 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1122 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1123 << "\t\tFlightGear time" << endl;
1124 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1125 << "\t\tdate/time. Uses your system time " << endl;
1126 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1127 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1128 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1129 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1130 #ifdef FG_NETWORK_OLK
1133 cout << "Network Options:" << endl;
1134 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1135 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1136 cout << "\t--net-hud: Hud displays network info" << endl;
1137 cout << "\t--net-id=name: specify your own callsign" << endl;
1141 cout << "Route/Way Point Options:" << endl;
1142 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1143 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1145 cout << "\t\tinstances of --wp=" << endl;
1146 cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;