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);
154 fgSetString("/sim/rendering/fog", "nicest");
155 fgSetBool("/environment/clouds/status", true);
156 fgSetDouble("/environment/clouds/altitude", 5000);
157 fgSetBool("/sim/startup/fullscreen", false);
158 fgSetBool("/sim/rendering/shading", true);
159 fgSetBool("/sim/rendering/skyblend", true);
160 fgSetBool("/sim/rendering/textures", true);
161 fgSetBool("/sim/rendering/wireframe", false);
162 fgSetInt("/sim/startup/xsize", 800);
163 fgSetInt("/sim/startup/ysize", 600);
164 fgSetInt("/sim/rendering/bits-per-pixel", 16);
165 fgSetString("/sim/view-mode", "pilot");
166 fgSetDouble("/sim/startup/view-offset", 0);
167 fgSetDouble("/environment/visibility", 20000);
170 fgSetString("/sim/startup/units", "feet");
171 fgSetString("/sim/hud/frame-stat-type", "tris");
174 fgSetInt("/sim/startup/time-offset", 0);
175 fgSetString("/sim/startup/time-offset-type", "system-offset");
177 fgSetBool("/sim/networking/network-olk", false);
178 fgSetString("/sim/networking/call-sign", "Johnny");
182 parse_time(const string& time_in) {
183 char *time_str, num[256];
184 double hours, minutes, seconds;
189 time_str = (char *)time_in.c_str();
191 // printf("parse_time(): %s\n", time_str);
194 if ( strlen(time_str) ) {
195 if ( time_str[0] == '+' ) {
198 } else if ( time_str[0] == '-' ) {
203 // printf("sign = %d\n", sign);
206 if ( strlen(time_str) ) {
208 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
209 num[i] = time_str[0];
213 if ( time_str[0] == ':' ) {
218 // printf("hours = %.2lf\n", hours);
224 if ( strlen(time_str) ) {
226 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
227 num[i] = time_str[0];
231 if ( time_str[0] == ':' ) {
236 // printf("minutes = %.2lf\n", minutes);
238 result += minutes / 60.0;
242 if ( strlen(time_str) ) {
244 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
245 num[i] = time_str[0];
251 // printf("seconds = %.2lf\n", seconds);
253 result += seconds / 3600.0;
256 return(sign * result);
261 parse_date( const string& date)
264 char * date_str, num[256];
266 // initialize to zero
273 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
274 date_str = (char *)date.c_str();
276 if ( strlen(date_str) ) {
278 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
279 num[i] = date_str[0];
283 if ( date_str[0] == ':' ) {
287 gmt.tm_year = atoi(num) - 1900;
290 if ( strlen(date_str) ) {
292 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
293 num[i] = date_str[0];
297 if ( date_str[0] == ':' ) {
301 gmt.tm_mon = atoi(num) -1;
304 if ( strlen(date_str) ) {
306 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
307 num[i] = date_str[0];
311 if ( date_str[0] == ':' ) {
315 gmt.tm_mday = atoi(num);
318 if ( strlen(date_str) ) {
320 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
321 num[i] = date_str[0];
325 if ( date_str[0] == ':' ) {
329 gmt.tm_hour = atoi(num);
332 if ( strlen(date_str) ) {
334 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
335 num[i] = date_str[0];
339 if ( date_str[0] == ':' ) {
343 gmt.tm_min = atoi(num);
346 if ( strlen(date_str) ) {
348 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
349 num[i] = date_str[0];
353 if ( date_str[0] == ':' ) {
357 gmt.tm_sec = atoi(num);
359 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
360 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
361 //printf ("Date is %s\n", ctime(&theTime));
362 //printf ("in seconds that is %d\n", theTime);
368 /// parse degree in the form of [+/-]hhh:mm:ss
370 parse_degree( const string& degree_str) {
371 double result = parse_time( degree_str );
373 // printf("Degree = %.4f\n", result);
379 // parse time offset command line option
381 parse_time_offset( const string& time_str) {
384 // printf("time offset = %s\n", time_str);
387 result = (int)rint(parse_time(time_str) * 3600.0);
389 result = (int)(parse_time(time_str) * 3600.0);
392 // printf("parse_time_offset(): %d\n", result);
398 // Parse --fov=x.xx type option
400 parse_fov( const string& arg ) {
401 double fov = atof(arg);
403 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
404 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
406 fgSetDouble("/sim/field-of-view", fov);
408 // printf("parse_fov(): result = %.4f\n", fov);
414 // Parse I/O channel option
416 // Format is "--protocol=medium,direction,hz,medium_options,..."
418 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
419 // medium = { serial, socket, file, etc. }
420 // direction = { in, out, bi }
421 // hz = number of times to process channel per second (floating
422 // point values are ok.
424 // Serial example "--nmea=serial,dir,hz,device,baud" where
426 // device = OS device name of serial line to be open()'ed
427 // baud = {300, 1200, 2400, ..., 230400}
429 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
431 // machine = machine name or ip address if client (leave empty if server)
432 // port = port, leave empty to let system choose
433 // style = tcp or udp
435 // File example "--garmin=file,dir,hz,filename" where
437 // filename = file system file name
440 parse_channel( const string& type, const string& channel_str ) {
441 // cout << "Channel string = " << channel_str << endl;
443 globals->get_channel_options_list().push_back( type + "," + channel_str );
449 // Parse --wp=ID[,alt]
451 parse_wp( const string& arg ) {
455 int pos = arg.find( "@" );
456 if ( pos != string::npos ) {
457 id = arg.substr( 0, pos );
458 alt_str = arg.substr( pos + 1 );
459 // cout << "id str = " << id << " alt str = " << alt_str << endl;
460 alt = atof( alt_str.c_str() );
461 if ( fgGetString("/sim/startup/units") == "feet" ) {
462 alt *= FEET_TO_METER;
469 if ( fgFindAirportID( id, &a ) ) {
470 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
471 globals->get_route()->add_waypoint( wp );
480 // Parse --flight-plan=[file]
482 parse_flightplan(const string& arg)
484 fg_gzifstream infile(arg.c_str());
490 #ifdef GETLINE_NEEDS_TERMINATOR
491 getline( infile, line, '\n' );
492 #elif defined( macintosh )
493 getline( infile, line, '\r' );
495 getline( infile, line );
497 if ( infile.eof() ) {
507 // Parse a single option
509 parse_option (const string& arg)
512 if ( (arg == "--help") || (arg == "-h") ) {
513 // help/usage request
514 return(FG_OPTIONS_HELP);
515 } else if ( arg == "--disable-game-mode") {
516 fgSetBool("/sim/startup/game-mode", false);
517 } else if ( arg == "--enable-game-mode" ) {
518 fgSetBool("/sim/startup/game-mode", true);
519 } else if ( arg == "--disable-splash-screen" ) {
520 fgSetBool("/sim/startup/splash-screen", false);
521 } else if ( arg == "--enable-splash-screen" ) {
522 fgSetBool("/sim/startup/splash-screen", true);
523 } else if ( arg == "--disable-intro-music" ) {
524 fgSetBool("/sim/startup/intro-music", false);
525 } else if ( arg == "--enable-intro-music" ) {
526 fgSetBool("/sim/startup/intro-music", true);
527 } else if ( arg == "--disable-mouse-pointer" ) {
528 fgSetString("/sim/startup/mouse-pointer", "disabled");
529 } else if ( arg == "--enable-mouse-pointer" ) {
530 fgSetString("/sim/startup/mouse-pointer", "enabled");
531 } else if ( arg == "--disable-freeze" ) {
532 fgSetBool("/sim/freeze", false);
533 } else if ( arg == "--enable-freeze" ) {
534 fgSetBool("/sim/freeze", true);
535 } else if ( arg == "--disable-anti-alias-hud" ) {
536 fgSetBool("/sim/hud/antialiased", false);
537 } else if ( arg == "--enable-anti-alias-hud" ) {
538 fgSetBool("/sim/hud/antialiased", true);
539 } else if ( arg.find( "--control=") != string::npos ) {
540 fgSetString("/sim/control-mode", arg.substr(10));
541 } else if ( arg == "--disable-auto-coordination" ) {
542 fgSetBool("/sim/auto-coordination", false);
543 } else if ( arg == "--enable-auto-coordination" ) {
544 fgSetBool("/sim/auto-coordination", true);
545 } else if ( arg == "--disable-hud" ) {
546 fgSetBool("/sim/hud/visibility", false);
547 } else if ( arg == "--enable-hud" ) {
548 fgSetBool("/sim/hud/visibility", true);
549 } else if ( arg == "--disable-panel" ) {
550 fgSetBool("/sim/panel/visibility", false);
551 } else if ( arg == "--enable-panel" ) {
552 fgSetBool("/sim/panel/visibility", true);
553 } else if ( arg == "--disable-sound" ) {
554 fgSetBool("/sim/sound", false);
555 } else if ( arg == "--enable-sound" ) {
556 fgSetBool("/sim/sound", true);
557 } else if ( arg.find( "--airport-id=") != string::npos ) {
558 // NB: changed property name!!!
559 fgSetString("/sim/startup/airport-id", arg.substr(13));
560 } else if ( arg.find( "--lon=" ) != string::npos ) {
561 fgSetDouble("/position/longitude",
562 parse_degree(arg.substr(6)));
563 fgSetString("/position/airport-id", "");
564 } else if ( arg.find( "--lat=" ) != string::npos ) {
565 fgSetDouble("/position/latitude",
566 parse_degree(arg.substr(6)));
567 fgSetString("/position/airport-id", "");
568 } else if ( arg.find( "--altitude=" ) != string::npos ) {
569 if ( fgGetString("/sim/startup/units") == "feet" )
570 fgSetDouble("/position/altitude", atof(arg.substr(11)));
572 fgSetDouble("/position/altitude",
573 atof(arg.substr(11)) * METER_TO_FEET);
574 } else if ( arg.find( "--uBody=" ) != string::npos ) {
575 fgSetString("/sim/startup/speed-set", "UVW");
576 // FIXME: the units are totally confused here
577 if ( fgGetString("/sim/startup/units") == "feet" )
578 fgSetDouble("/velocities/uBody", atof(arg.substr(8)));
580 fgSetDouble("/velocities/uBody",
581 atof(arg.substr(8)) * FEET_TO_METER);
582 } else if ( arg.find( "--vBody=" ) != string::npos ) {
583 fgSetString("/sim/startup/speed-set", "UVW");
584 // FIXME: the units are totally confused here
585 if ( fgGetString("/sim/startup/units") == "feet" )
586 fgSetDouble("/velocities/vBody", atof(arg.substr(8)));
588 fgSetDouble("/velocities/vBody",
589 atof(arg.substr(8)) * FEET_TO_METER);
590 } else if ( arg.find( "--wBody=" ) != string::npos ) {
591 fgSetString("/sim/startup/speed-set", "UVW");
592 // FIXME: the units are totally confused here
593 if ( fgGetString("/sim/startup/units") == "feet" )
594 fgSetDouble("/velocities/wBody", atof(arg.substr(8)));
596 fgSetDouble("/velocities/wBody",
597 atof(arg.substr(8)) * FEET_TO_METER);
598 } else if ( arg.find( "--vNorth=" ) != string::npos ) {
599 fgSetString("/sim/startup/speed-set", "NED");
600 // FIXME: the units are totally confused here
601 if ( fgGetString("/sim/startup/units") == "feet" )
602 fgSetDouble("/velocities/speed-north", atof(arg.substr(8)));
604 fgSetDouble("/velocities/speed-north",
605 atof(arg.substr(8)) * FEET_TO_METER);
606 } else if ( arg.find( "--vEast=" ) != string::npos ) {
607 fgSetString("/sim/startup/speed-set", "NED");
608 // FIXME: the units are totally confused here
609 if ( fgGetString("/sim/startup/units") == "feet" )
610 fgSetDouble("/velocities/speed-east", atof(arg.substr(8)));
612 fgSetDouble("/velocities/speed-east",
613 atof(arg.substr(8)) * FEET_TO_METER);
614 } else if ( arg.find( "--vDown=" ) != string::npos ) {
615 fgSetString("/sim/startup/speed-set", "NED");
616 // FIXME: the units are totally confused here
617 if ( fgGetString("/sim/startup/units") == "feet" )
618 fgSetDouble("/velocities/speed-down", atof(arg.substr(8)));
620 fgSetDouble("/velocities/speed-down",
621 atof(arg.substr(8)) * FEET_TO_METER);
622 } else if ( arg.find( "--vc=" ) != string::npos) {
623 fgSetString("/sim/startup/speed-set", "knots");
624 fgSetDouble("/velocities/airspeed", atof(arg.substr(5)));
625 } else if ( arg.find( "--mach=" ) != string::npos) {
626 fgSetString("/sim/startup/speed-set", "mach");
627 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
628 } else if ( arg.find( "--heading=" ) != string::npos ) {
629 fgSetDouble("/orientation/heading", atof(arg.substr(10)));
630 } else if ( arg.find( "--roll=" ) != string::npos ) {
631 fgSetDouble("/orientation/roll", atof(arg.substr(7)));
632 } else if ( arg.find( "--pitch=" ) != string::npos ) {
633 fgSetDouble("/orientation/pitch", atof(arg.substr(8)));
634 } else if ( arg.find( "--fg-root=" ) != string::npos ) {
635 globals->set_fg_root(arg.substr( 10 ));
636 } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
637 globals->set_fg_scenery(arg.substr( 13 ));
638 } else if ( arg.find( "--fdm=" ) != string::npos ) {
639 fgSetString("/sim/flight-model", arg.substr(6));
640 } else if ( arg.find( "--aircraft=" ) != string::npos ) {
641 fgSetString("/sim/aircraft", arg.substr(11));
642 } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
643 fgSetString("/sim/aircraft-dir", arg.substr(15));
644 } else if ( arg.find( "--model-hz=" ) != string::npos ) {
645 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
646 } else if ( arg.find( "--speed=" ) != string::npos ) {
647 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
648 } else if ( arg.find( "--trim") != string::npos) {
649 fgSetInt("/sim/startup/trim", true);
650 } else if ( arg.find( "--notrim") != string::npos) {
651 fgSetInt("/sim/startup/trim", false);
652 } else if ( arg == "--fog-disable" ) {
653 fgSetString("/sim/rendering/fog", "disabled");
654 } else if ( arg == "--fog-fastest" ) {
655 fgSetString("/sim/rendering/fog", "fastest");
656 } else if ( arg == "--fog-nicest" ) {
657 fgSetString("/sim/fog", "nicest");
658 } else if ( arg == "--disable-clouds" ) {
659 fgSetBool("/environment/clouds/status", false);
660 } else if ( arg == "--enable-clouds" ) {
661 fgSetBool("/environment/clouds/status", true);
662 } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
663 // FIXME: check units
664 if ( fgGetString("/sim/startup/units") == "feet" )
665 fgSetDouble("/environment/clouds/altitude",
666 atof(arg.substr(13)) * FEET_TO_METER);
668 fgSetDouble("/environment/clouds/altitude",
669 atof(arg.substr(13)));
670 } else if ( arg.find( "--fov=" ) != string::npos ) {
671 parse_fov( arg.substr(6) );
672 } else if ( arg == "--disable-fullscreen" ) {
673 fgSetBool("/sim/startup/fullscreen", false);
674 } else if ( arg== "--enable-fullscreen") {
675 fgSetBool("/sim/startup/fullscreen", true);
676 } else if ( arg == "--shading-flat") {
677 fgSetBool("/sim/rendering/shading", false);
678 } else if ( arg == "--shading-smooth") {
679 fgSetBool("/sim/rendering/shading", true);
680 } else if ( arg == "--disable-skyblend") {
681 fgSetBool("/sim/rendering/skyblend", false);
682 } else if ( arg== "--enable-skyblend" ) {
683 fgSetBool("/sim/rendering/skyblend", true);
684 } else if ( arg == "--disable-textures" ) {
685 fgSetBool("/sim/rendering/textures", false);
686 } else if ( arg == "--enable-textures" ) {
687 fgSetBool("/sim/rendering/textures", true);
688 } else if ( arg == "--disable-wireframe" ) {
689 fgSetBool("/sim/rendering/wireframe", false);
690 } else if ( arg == "--enable-wireframe" ) {
691 fgSetBool("/sim/rendering/wireframe", true);
692 } else if ( arg.find( "--geometry=" ) != string::npos ) {
693 bool geometry_ok = true;
694 int xsize = 0, ysize = 0;
695 string geometry = arg.substr( 11 );
696 string::size_type i = geometry.find('x');
698 if (i != string::npos) {
699 xsize = atoi(geometry.substr(0, i));
700 ysize = atoi(geometry.substr(i+1));
705 if ( xsize <= 0 || ysize <= 0 ) {
711 if ( !geometry_ok ) {
712 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
713 FG_LOG( FG_GENERAL, FG_ALERT,
714 "Setting geometry to " << xsize << 'x' << ysize << '\n');
716 FG_LOG( FG_GENERAL, FG_INFO,
717 "Setting geometry to " << xsize << 'x' << ysize << '\n');
718 fgSetInt("/sim/startup/xsize", xsize);
719 fgSetInt("/sim/startup/ysize", ysize);
721 } else if ( arg.find( "--bpp=" ) != string::npos ) {
722 string bits_per_pix = arg.substr( 6 );
723 if ( bits_per_pix == "16" ) {
724 fgSetInt("/sim/rendering/bits-per-pixel", 16);
725 } else if ( bits_per_pix == "24" ) {
726 fgSetInt("/sim/rendering/bits-per-pixel", 24);
727 } else if ( bits_per_pix == "32" ) {
728 fgSetInt("/sim/rendering/bits-per-pixel", 32);
730 FG_LOG(FG_GENERAL, FG_ALERT, "Unsupported bpp " << bits_per_pix);
732 } else if ( arg == "--units-feet" ) {
733 fgSetString("/sim/startup/units", "feet");
734 } else if ( arg == "--units-meters" ) {
735 fgSetString("/sim/startup/units", "meters");
736 } else if ( arg.find( "--time-offset" ) != string::npos ) {
737 fgSetInt("/sim/startup/time-offset",
738 parse_time_offset( (arg.substr(14)) ));
739 } else if ( arg.find( "--time-match-real") != string::npos ) {
740 fgSetString("/sim/startup/time-offset_type",
742 } else if ( arg.find( "--time-match-local") != string::npos ) {
743 fgSetString("/sim/startup/time-offset_type",
745 } else if ( arg.find( "--start-date-sys=") != string::npos ) {
746 fgSetInt("/sim/startup/time-offset",
747 parse_date((arg.substr(17))));
748 fgSetString("/sim/startup/time-offset-type", "system");
749 } else if ( arg.find( "--start-date-lat=") != string::npos ) {
750 fgSetInt("/sim/startup/time-offset",
751 parse_date((arg.substr(17))));
752 fgSetString("/sim/startup/time-offset-type",
754 } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
755 fgSetInt("/sim/startup/time-offset",
756 parse_date((arg.substr(17))));
757 fgSetString("/sim/startup/time-offset-type", "gmt");
758 } else if ( arg == "--hud-tris" ) {
759 fgSetString("/sim/hud/frame-stat-type", "tris");
760 } else if ( arg == "--hud-culled" ) {
761 fgSetString("/sim/hud/frame-stat-type", "culled");
762 } else if ( arg.find( "--native=" ) != string::npos ) {
763 parse_channel( "native", arg.substr(9) );
764 } else if ( arg.find( "--garmin=" ) != string::npos ) {
765 parse_channel( "garmin", arg.substr(9) );
766 } else if ( arg.find( "--nmea=" ) != string::npos ) {
767 parse_channel( "nmea", arg.substr(7) );
768 } else if ( arg.find( "--props=" ) != string::npos ) {
769 parse_channel( "props", arg.substr(8) );
770 } else if ( arg.find( "--pve=" ) != string::npos ) {
771 parse_channel( "pve", arg.substr(6) );
772 } else if ( arg.find( "--ray=" ) != string::npos ) {
773 parse_channel( "ray", arg.substr(6) );
774 } else if ( arg.find( "--rul=" ) != string::npos ) {
775 parse_channel( "rul", arg.substr(6) );
776 } else if ( arg.find( "--joyclient=" ) != string::npos ) {
777 parse_channel( "joyclient", arg.substr(12) );
778 #ifdef FG_NETWORK_OLK
779 } else if ( arg == "--disable-network-olk" ) {
780 fgSetBool("/sim/networking/olk", false);
781 } else if ( arg== "--enable-network-olk") {
782 fgSetBool("/sim/networking/olk", true);
783 } else if ( arg == "--net-hud" ) {
784 fgSetBool("/sim/hud/net-display", true);
785 net_hud_display = 1; // FIXME
786 } else if ( arg.find( "--net-id=") != string::npos ) {
787 fgSetString("sim/networking/call-sign", arg.substr(9));
789 } else if ( arg.find( "--prop:" ) == 0 ) {
790 string assign = arg.substr(7);
791 int pos = assign.find('=');
792 if (pos == arg.npos || pos == 0) {
793 FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
794 return FG_OPTIONS_ERROR;
796 string name = assign.substr(0, pos);
797 string value = assign.substr(pos + 1);
798 fgSetString(name.c_str(), value);
799 FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
800 << name << " to \"" << value << '"');
801 // $$$ begin - added VS Renganathan, 14 Oct 2K
802 // for multi-window outside window imagery
803 } else if ( arg.find( "--view-offset=" ) != string::npos ) {
804 string woffset = arg.substr( 14 );
805 double default_view_offset = 0.0;
806 if ( woffset == "LEFT" ) {
807 default_view_offset = FG_PI * 0.25;
808 } else if ( woffset == "RIGHT" ) {
809 default_view_offset = FG_PI * 1.75;
810 } else if ( woffset == "CENTER" ) {
811 default_view_offset = 0.00;
813 default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD;
815 FGViewerRPH *pilot_view =
816 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
817 pilot_view->set_view_offset( default_view_offset );
818 pilot_view->set_goal_view_offset( default_view_offset );
819 fgSetDouble("/sim/startup/view-offset", default_view_offset);
820 // $$$ end - added VS Renganathan, 14 Oct 2K
821 } else if ( arg.find( "--visibility=" ) != string::npos ) {
822 fgSetDouble("/environment/visibility", atof(arg.substr(13)));
823 } else if ( arg.find( "--visibility-miles=" ) != string::npos ) {
824 double visibility = atof(arg.substr(19)) * 5280.0 * FEET_TO_METER;
825 fgSetDouble("/environment/visibility", visibility);
826 } else if ( arg.find( "--wind=" ) == 0 ) {
827 string val = arg.substr(7);
828 int pos = val.find('@');
829 if (pos == string::npos) {
830 FG_LOG(FG_GENERAL, FG_ALERT, "bad wind value " << val);
831 return FG_OPTIONS_ERROR;
833 double dir = atof(val.substr(0,pos).c_str());
834 double speed = atof(val.substr(pos+1).c_str());
835 FG_LOG(FG_GENERAL, FG_INFO, "WIND: " << dir << '@' <<
836 speed << " knots" << endl);
838 speed *= NM_TO_METER * METER_TO_FEET * (1.0/3600);
843 fgSetDouble("/environment/wind-north",
845 fgSetDouble("/environment/wind-east",
847 } else if ( arg.find( "--wp=" ) != string::npos ) {
848 parse_wp( arg.substr( 5 ) );
849 } else if ( arg.find( "--flight-plan=") != string::npos) {
850 parse_flightplan ( arg.substr (14) );
852 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
853 return FG_OPTIONS_ERROR;
856 return FG_OPTIONS_OK;
860 // Scan the command line options for an fg_root definition and set
863 fgScanForRoot (int argc, char **argv)
867 FG_LOG(FG_GENERAL, FG_INFO, "Scanning for root: command line");
870 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
872 string arg = argv[i];
873 if ( arg.find( "--fg-root=" ) != string::npos ) {
874 return arg.substr( 10 );
884 // Scan the config file for an fg_root definition and set just that.
886 fgScanForRoot (const string& path)
888 fg_gzifstream in( path );
892 FG_LOG( FG_GENERAL, FG_INFO, "Scanning for root: " << path );
896 while ( ! in.eof() ) {
899 while ( in.get(c) && c != '\0' ) {
904 #ifdef GETLINE_NEEDS_TERMINATOR
905 getline( in, line, '\n' );
906 #elif defined( macintosh )
907 getline( in, line, '\r' );
912 if ( line.find( "--fg-root=" ) != string::npos ) {
913 return line.substr( 10 );
923 // Parse the command line options
925 fgParseOptions (int argc, char **argv) {
929 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
932 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
934 result = parse_option(argv[i]);
935 if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
945 // Parse config file options
947 fgParseOptions (const string& path) {
948 fg_gzifstream in( path );
952 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
956 while ( ! in.eof() ) {
959 while ( in.get(c) && c != '\0' ) {
964 #ifdef GETLINE_NEEDS_TERMINATOR
965 getline( in, line, '\n' );
966 #elif defined( macintosh )
967 getline( in, line, '\r' );
972 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
973 FG_LOG( FG_GENERAL, FG_ALERT,
974 "Config file parse error: " << path << " '"
984 // Print usage message
988 cout << "Usage: fg [ options ... ]" << endl;
991 cout << "General Options:" << endl;
992 cout << "\t--help -h: print usage" << endl;
993 cout << "\t--fg-root=path: specify the root path for all the data files"
995 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
997 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
998 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
999 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1000 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1001 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1002 cout << "\t--disable-intro-music: disable introduction music" << endl;
1003 cout << "\t--enable-intro-music: enable introduction music" << endl;
1004 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1005 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1007 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1008 cout << "\t--disable-freeze: start out in an running state" << endl;
1009 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1010 cout << "\t--control=mode: primary control mode "
1011 << "(joystick, keyboard, mouse)" << endl;
1014 cout << "Features:" << endl;
1015 cout << "\t--disable-hud: disable heads up display" << endl;
1016 cout << "\t--enable-hud: enable heads up display" << endl;
1017 cout << "\t--disable-panel: disable instrument panel" << endl;
1018 cout << "\t--enable-panel: enable instrumetn panel" << endl;
1019 cout << "\t--disable-sound: disable sound effects" << endl;
1020 cout << "\t--enable-sound: enable sound effects" << endl;
1021 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1022 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1025 cout << "Flight Model:" << endl;
1026 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1027 cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1029 cout << "\t--aircraft=abcd: aircraft model to load" << endl;
1030 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1032 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1033 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1034 cout << "\t--wind=DIR@SPEED: specify wind coming from DIR (degrees) at SPEED (knots)" << endl;
1038 cout <<"Aircraft model directory:" << endl;
1039 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1042 cout << "Initial Position and Orientation:" << endl;
1043 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1045 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1047 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1049 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1050 cout << "\t\t(unless --units-meters specified" << endl;
1051 cout << "\t--heading=degrees: heading (yaw) angle in degress (Psi)"
1053 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1054 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1055 cout << "\t--uBody=feet per second: velocity along the body X axis"
1057 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1059 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1061 cout << "\t\t(unless --units-meters specified" << endl;
1062 cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1063 cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1066 cout << "Rendering Options:" << endl;
1067 cout << "\t--fog-disable: disable fog/haze" << endl;
1068 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1069 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1070 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1071 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1072 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1073 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1075 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1076 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1077 cout << "\t--shading-flat: enable flat shading" << endl;
1078 cout << "\t--shading-smooth: enable smooth shading" << endl;
1079 cout << "\t--disable-skyblend: disable sky blending" << endl;
1080 cout << "\t--enable-skyblend: enable sky blending" << endl;
1081 cout << "\t--disable-textures: disable textures" << endl;
1082 cout << "\t--enable-textures: enable textures" << endl;
1083 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1084 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1085 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1087 cout << "\t--view-offset=xxx: set the default forward view direction"
1089 cout << "\t\tas an offset from straight ahead. Allowable values are"
1091 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1092 cout << "\t--visibility=xxx: specify initial visibility in meters" << endl;
1093 cout << "\t--visibility-miles=xxx: specify initial visibility in miles"
1097 cout << "Scenery Options:" << endl;
1098 cout << "\t--tile-radius=n: specify tile radius, must be 1 - 4" << endl;
1101 cout << "Hud Options:" << endl;
1102 cout << "\t--units-feet: Hud displays units in feet" << endl;
1103 cout << "\t--units-meters: Hud displays units in meters" << endl;
1104 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1105 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1109 cout << "Time Options:" << endl;
1110 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1111 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1112 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1113 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1114 << "\t\tFlightGear time" << endl;
1115 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1116 << "\t\tdate/time. Uses your system time " << endl;
1117 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1118 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1119 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1120 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1121 #ifdef FG_NETWORK_OLK
1124 cout << "Network Options:" << endl;
1125 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1126 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1127 cout << "\t--net-hud: Hud displays network info" << endl;
1128 cout << "\t--net-id=name: specify your own callsign" << endl;
1132 cout << "Route/Way Point Options:" << endl;
1133 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1134 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1136 cout << "\t\tinstances of --wp=" << endl;
1137 cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;