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>
31 #if defined(FX) && defined(XMESA)
32 bool global_fullscreen = true;
35 #include <math.h> // rint()
37 #include <stdlib.h> // atof(), atoi()
42 #include <simgear/misc/fgstream.hxx>
44 // #include <Include/general.hxx>
45 // #include <Airports/simple.hxx>
46 // #include <Cockpit/cockpit.hxx>
47 // #include <FDM/flight.hxx>
48 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
50 # include <NetworkOLK/network.h>
53 #include "globals.hxx"
54 #include "fg_init.hxx"
55 #include "fg_props.hxx"
56 #include "options.hxx"
59 FG_USING_NAMESPACE(std);
62 #define NEW_DEFAULT_MODEL_HZ 120
72 atof( const string& str )
76 // -dw- if ::atof is called, then we get an infinite loop
77 return std::atof( str.c_str() );
79 return ::atof( str.c_str() );
84 atoi( const string& str )
87 // -dw- if ::atoi is called, then we get an infinite loop
88 return std::atoi( str.c_str() );
90 return ::atoi( str.c_str() );
96 * Set a few fail-safe default property values.
98 * These should all be set in $FG_ROOT/preferences.xml, but just
99 * in case, we provide some initial sane values here. This method
100 * should be invoked *before* reading any init files.
105 // set a possibly independent location for scenery data
106 char *envp = ::getenv( "FG_SCENERY" );
108 if ( envp != NULL ) {
109 // fg_root could be anywhere, so default to environmental
110 // variable $FG_ROOT if it is set.
111 globals->set_fg_scenery(envp);
113 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
114 globals->set_fg_scenery("");
116 // Position (Globe, AZ)
117 fgSetDouble("/position/longitude", -110.6642444);
118 fgSetDouble("/position/latitude", 33.3528917);
119 fgSetDouble("/position/altitude", -9999.0);
122 fgSetDouble("/orientation/heading", 270);
123 fgSetDouble("/orientation/roll", 0);
124 fgSetDouble("/orientation/pitch", 0.424);
127 fgSetString("/sim/startup/speed-set", "knots");
128 fgSetDouble("/velocities/uBody", 0.0);
129 fgSetDouble("/velocities/vBody", 0.0);
130 fgSetDouble("/velocities/wBody", 0.0);
131 fgSetDouble("/velocities/speed-north", 0.0);
132 fgSetDouble("/velocities/speed-east", 0.0);
133 fgSetDouble("/velocities/speed-down", 0.0);
134 fgSetDouble("/velocities/airspeed", 0.0);
135 fgSetDouble("/velocities/mach", 0.0);
138 fgSetBool("/sim/startup/game-mode", false);
139 fgSetBool("/sim/startup/splash-screen", true);
140 fgSetBool("/sim/startup/intro-music", true);
141 // we want mouse-pointer to have an undefined value if nothing is
142 // specified so we can do the right thing for voodoo-1/2 cards.
143 // fgSetString("/sim/startup/mouse-pointer", "disabled");
144 fgSetString("/sim/control-mode", "joystick");
145 fgSetBool("/sim/auto-coordination", false);
148 fgSetBool("/sim/hud/visibility", false);
149 fgSetBool("/sim/panel/visibility", true);
150 fgSetBool("/sim/sound", true);
151 fgSetBool("/sim/hud/antialiased", false);
153 // Flight Model options
154 fgSetString("/sim/flight-model", "larcsim");
155 fgSetString("/sim/aircraft", "c172");
156 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
157 fgSetInt("/sim/speed-up", 1);
158 fgSetBool("/sim/startup/trim", false);
159 fgSetBool("/sim/startup/onground", true);
162 fgSetString("/sim/rendering/fog", "nicest");
163 fgSetBool("/environment/clouds/status", true);
164 fgSetDouble("/environment/clouds/altitude", 5000);
165 fgSetBool("/sim/startup/fullscreen", false);
166 fgSetBool("/sim/rendering/shading", true);
167 fgSetBool("/sim/rendering/skyblend", true);
168 fgSetBool("/sim/rendering/textures", true);
169 fgSetBool("/sim/rendering/wireframe", false);
170 fgSetInt("/sim/startup/xsize", 800);
171 fgSetInt("/sim/startup/ysize", 600);
172 fgSetInt("/sim/rendering/bits-per-pixel", 16);
173 fgSetString("/sim/view-mode", "pilot");
174 fgSetDouble("/sim/startup/view-offset", 0);
175 fgSetDouble("/environment/visibility", 20000);
178 fgSetString("/sim/startup/units", "feet");
179 fgSetString("/sim/hud/frame-stat-type", "tris");
182 fgSetInt("/sim/startup/time-offset", 0);
183 fgSetString("/sim/startup/time-offset-type", "system-offset");
185 fgSetBool("/sim/networking/network-olk", false);
186 fgSetString("/sim/networking/call-sign", "Johnny");
190 parse_time(const string& time_in) {
191 char *time_str, num[256];
192 double hours, minutes, seconds;
197 time_str = (char *)time_in.c_str();
199 // printf("parse_time(): %s\n", time_str);
202 if ( strlen(time_str) ) {
203 if ( time_str[0] == '+' ) {
206 } else if ( time_str[0] == '-' ) {
211 // printf("sign = %d\n", sign);
214 if ( strlen(time_str) ) {
216 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
217 num[i] = time_str[0];
221 if ( time_str[0] == ':' ) {
226 // printf("hours = %.2lf\n", hours);
232 if ( strlen(time_str) ) {
234 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
235 num[i] = time_str[0];
239 if ( time_str[0] == ':' ) {
244 // printf("minutes = %.2lf\n", minutes);
246 result += minutes / 60.0;
250 if ( strlen(time_str) ) {
252 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
253 num[i] = time_str[0];
259 // printf("seconds = %.2lf\n", seconds);
261 result += seconds / 3600.0;
264 return(sign * result);
269 parse_date( const string& date)
272 char * date_str, num[256];
274 // initialize to zero
281 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
282 date_str = (char *)date.c_str();
284 if ( strlen(date_str) ) {
286 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
287 num[i] = date_str[0];
291 if ( date_str[0] == ':' ) {
295 gmt.tm_year = atoi(num) - 1900;
298 if ( strlen(date_str) ) {
300 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
301 num[i] = date_str[0];
305 if ( date_str[0] == ':' ) {
309 gmt.tm_mon = atoi(num) -1;
312 if ( strlen(date_str) ) {
314 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
315 num[i] = date_str[0];
319 if ( date_str[0] == ':' ) {
323 gmt.tm_mday = atoi(num);
326 if ( strlen(date_str) ) {
328 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
329 num[i] = date_str[0];
333 if ( date_str[0] == ':' ) {
337 gmt.tm_hour = atoi(num);
340 if ( strlen(date_str) ) {
342 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
343 num[i] = date_str[0];
347 if ( date_str[0] == ':' ) {
351 gmt.tm_min = atoi(num);
354 if ( strlen(date_str) ) {
356 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
357 num[i] = date_str[0];
361 if ( date_str[0] == ':' ) {
365 gmt.tm_sec = atoi(num);
367 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
368 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
369 //printf ("Date is %s\n", ctime(&theTime));
370 //printf ("in seconds that is %d\n", theTime);
376 /// parse degree in the form of [+/-]hhh:mm:ss
378 parse_degree( const string& degree_str) {
379 double result = parse_time( degree_str );
381 // printf("Degree = %.4f\n", result);
387 // parse time offset command line option
389 parse_time_offset( const string& time_str) {
392 // printf("time offset = %s\n", time_str);
395 result = (int)rint(parse_time(time_str) * 3600.0);
397 result = (int)(parse_time(time_str) * 3600.0);
400 // printf("parse_time_offset(): %d\n", result);
406 // Parse --fov=x.xx type option
408 parse_fov( const string& arg ) {
409 double fov = atof(arg);
411 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
412 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
414 fgSetDouble("/sim/field-of-view", fov);
416 // printf("parse_fov(): result = %.4f\n", fov);
422 // Parse I/O channel option
424 // Format is "--protocol=medium,direction,hz,medium_options,..."
426 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
427 // medium = { serial, socket, file, etc. }
428 // direction = { in, out, bi }
429 // hz = number of times to process channel per second (floating
430 // point values are ok.
432 // Serial example "--nmea=serial,dir,hz,device,baud" where
434 // device = OS device name of serial line to be open()'ed
435 // baud = {300, 1200, 2400, ..., 230400}
437 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
439 // machine = machine name or ip address if client (leave empty if server)
440 // port = port, leave empty to let system choose
441 // style = tcp or udp
443 // File example "--garmin=file,dir,hz,filename" where
445 // filename = file system file name
448 parse_channel( const string& type, const string& channel_str ) {
449 // cout << "Channel string = " << channel_str << endl;
451 globals->get_channel_options_list()->push_back( type + "," + channel_str );
457 // Parse --wp=ID[,alt]
459 parse_wp( const string& arg ) {
463 int pos = arg.find( "@" );
464 if ( pos != string::npos ) {
465 id = arg.substr( 0, pos );
466 alt_str = arg.substr( pos + 1 );
467 // cout << "id str = " << id << " alt str = " << alt_str << endl;
468 alt = atof( alt_str.c_str() );
469 if ( fgGetString("/sim/startup/units") == "feet" ) {
470 alt *= FEET_TO_METER;
477 if ( fgFindAirportID( id, &a ) ) {
478 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
479 globals->get_route()->add_waypoint( wp );
488 // Parse --flight-plan=[file]
490 parse_flightplan(const string& arg)
492 fg_gzifstream infile(arg.c_str());
498 #ifdef GETLINE_NEEDS_TERMINATOR
499 getline( infile, line, '\n' );
500 #elif defined( macintosh )
501 getline( infile, line, '\r' );
503 getline( infile, line );
505 if ( infile.eof() ) {
515 // Parse a single option
517 parse_option (const string& arg)
520 if ( (arg == "--help") || (arg == "-h") ) {
521 // help/usage request
522 return(FG_OPTIONS_HELP);
523 } else if ( arg == "--disable-game-mode") {
524 fgSetBool("/sim/startup/game-mode", false);
525 } else if ( arg == "--enable-game-mode" ) {
526 fgSetBool("/sim/startup/game-mode", true);
527 } else if ( arg == "--disable-splash-screen" ) {
528 fgSetBool("/sim/startup/splash-screen", false);
529 } else if ( arg == "--enable-splash-screen" ) {
530 fgSetBool("/sim/startup/splash-screen", true);
531 } else if ( arg == "--disable-intro-music" ) {
532 fgSetBool("/sim/startup/intro-music", false);
533 } else if ( arg == "--enable-intro-music" ) {
534 fgSetBool("/sim/startup/intro-music", true);
535 } else if ( arg == "--disable-mouse-pointer" ) {
536 fgSetString("/sim/startup/mouse-pointer", "disabled");
537 } else if ( arg == "--enable-mouse-pointer" ) {
538 fgSetString("/sim/startup/mouse-pointer", "enabled");
539 } else if ( arg == "--disable-freeze" ) {
540 globals->set_freeze(false);
541 } else if ( arg == "--enable-freeze" ) {
542 globals->set_freeze(true);
543 } else if ( arg == "--disable-anti-alias-hud" ) {
544 fgSetBool("/sim/hud/antialiased", false);
545 } else if ( arg == "--enable-anti-alias-hud" ) {
546 fgSetBool("/sim/hud/antialiased", true);
547 } else if ( arg.find( "--control=") != string::npos ) {
548 fgSetString("/sim/control-mode", arg.substr(10));
549 } else if ( arg == "--disable-auto-coordination" ) {
550 fgSetBool("/sim/auto-coordination", false);
551 } else if ( arg == "--enable-auto-coordination" ) {
552 fgSetBool("/sim/auto-coordination", true);
553 } else if ( arg == "--disable-hud" ) {
554 fgSetBool("/sim/hud/visibility", false);
555 } else if ( arg == "--enable-hud" ) {
556 fgSetBool("/sim/hud/visibility", true);
557 } else if ( arg == "--disable-panel" ) {
558 fgSetBool("/sim/panel/visibility", false);
559 } else if ( arg == "--enable-panel" ) {
560 fgSetBool("/sim/panel/visibility", true);
561 } else if ( arg == "--disable-sound" ) {
562 fgSetBool("/sim/sound", false);
563 } else if ( arg == "--enable-sound" ) {
564 fgSetBool("/sim/sound", true);
565 } else if ( arg.find( "--airport-id=") != string::npos ) {
566 // NB: changed property name!!!
567 fgSetString("/sim/startup/airport-id", arg.substr(13));
568 } else if ( arg.find( "--lon=" ) != string::npos ) {
569 fgSetDouble("/position/longitude",
570 parse_degree(arg.substr(6)));
571 fgSetString("/sim/startup/airport-id", "");
572 } else if ( arg.find( "--lat=" ) != string::npos ) {
573 fgSetDouble("/position/latitude",
574 parse_degree(arg.substr(6)));
575 fgSetString("/sim/startup/airport-id", "");
576 } else if ( arg.find( "--altitude=" ) != string::npos ) {
577 fgSetBool("/sim/startup/onground", false);
578 if ( fgGetString("/sim/startup/units") == "feet" )
579 fgSetDouble("/position/altitude", atof(arg.substr(11)));
581 fgSetDouble("/position/altitude",
582 atof(arg.substr(11)) * METER_TO_FEET);
583 } else if ( arg.find( "--uBody=" ) != string::npos ) {
584 fgSetString("/sim/startup/speed-set", "UVW");
585 // FIXME: the units are totally confused here
586 if ( fgGetString("/sim/startup/units") == "feet" )
587 fgSetDouble("/velocities/uBody", atof(arg.substr(8)));
589 fgSetDouble("/velocities/uBody",
590 atof(arg.substr(8)) * FEET_TO_METER);
591 } else if ( arg.find( "--vBody=" ) != string::npos ) {
592 fgSetString("/sim/startup/speed-set", "UVW");
593 // FIXME: the units are totally confused here
594 if ( fgGetString("/sim/startup/units") == "feet" )
595 fgSetDouble("/velocities/vBody", atof(arg.substr(8)));
597 fgSetDouble("/velocities/vBody",
598 atof(arg.substr(8)) * FEET_TO_METER);
599 } else if ( arg.find( "--wBody=" ) != string::npos ) {
600 fgSetString("/sim/startup/speed-set", "UVW");
601 // FIXME: the units are totally confused here
602 if ( fgGetString("/sim/startup/units") == "feet" )
603 fgSetDouble("/velocities/wBody", atof(arg.substr(8)));
605 fgSetDouble("/velocities/wBody",
606 atof(arg.substr(8)) * FEET_TO_METER);
607 } else if ( arg.find( "--vNorth=" ) != string::npos ) {
608 fgSetString("/sim/startup/speed-set", "NED");
609 // FIXME: the units are totally confused here
610 if ( fgGetString("/sim/startup/units") == "feet" )
611 fgSetDouble("/velocities/speed-north", atof(arg.substr(8)));
613 fgSetDouble("/velocities/speed-north",
614 atof(arg.substr(8)) * FEET_TO_METER);
615 } else if ( arg.find( "--vEast=" ) != string::npos ) {
616 fgSetString("/sim/startup/speed-set", "NED");
617 // FIXME: the units are totally confused here
618 if ( fgGetString("/sim/startup/units") == "feet" )
619 fgSetDouble("/velocities/speed-east", atof(arg.substr(8)));
621 fgSetDouble("/velocities/speed-east",
622 atof(arg.substr(8)) * FEET_TO_METER);
623 } else if ( arg.find( "--vDown=" ) != string::npos ) {
624 fgSetString("/sim/startup/speed-set", "NED");
625 // FIXME: the units are totally confused here
626 if ( fgGetString("/sim/startup/units") == "feet" )
627 fgSetDouble("/velocities/speed-down", atof(arg.substr(8)));
629 fgSetDouble("/velocities/speed-down",
630 atof(arg.substr(8)) * FEET_TO_METER);
631 } else if ( arg.find( "--vc=" ) != string::npos) {
632 fgSetString("/sim/startup/speed-set", "knots");
633 fgSetDouble("/velocities/airspeed", atof(arg.substr(5)));
634 } else if ( arg.find( "--mach=" ) != string::npos) {
635 fgSetString("/sim/startup/speed-set", "mach");
636 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
637 } else if ( arg.find( "--heading=" ) != string::npos ) {
638 fgSetDouble("/orientation/heading", atof(arg.substr(10)));
639 } else if ( arg.find( "--roll=" ) != string::npos ) {
640 fgSetDouble("/orientation/roll", atof(arg.substr(7)));
641 } else if ( arg.find( "--pitch=" ) != string::npos ) {
642 fgSetDouble("/orientation/pitch", atof(arg.substr(8)));
643 } else if ( arg.find( "--fg-root=" ) != string::npos ) {
644 globals->set_fg_root(arg.substr( 10 ));
645 } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
646 globals->set_fg_scenery(arg.substr( 13 ));
647 } else if ( arg.find( "--fdm=" ) != string::npos ) {
648 fgSetString("/sim/flight-model", arg.substr(6));
649 } else if ( arg.find( "--aircraft=" ) != string::npos ) {
650 fgSetString("/sim/aircraft", arg.substr(11));
651 } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
652 fgSetString("/sim/aircraft-dir", arg.substr(15));
653 } else if ( arg.find( "--model-hz=" ) != string::npos ) {
654 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
655 } else if ( arg.find( "--speed=" ) != string::npos ) {
656 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
657 } else if ( arg.find( "--trim") != string::npos) {
658 fgSetBool("/sim/startup/trim", true);
659 } else if ( arg.find( "--notrim") != string::npos) {
660 fgSetBool("/sim/startup/trim", false);
661 } else if ( arg.find( "--on-ground") != string::npos) {
662 fgSetBool("/sim/startup/onground", true);
663 } else if ( arg.find( "--in-air") != string::npos) {
664 fgSetBool("/sim/startup/onground", false);
665 } else if ( arg == "--fog-disable" ) {
666 fgSetString("/sim/rendering/fog", "disabled");
667 } else if ( arg == "--fog-fastest" ) {
668 fgSetString("/sim/rendering/fog", "fastest");
669 } else if ( arg == "--fog-nicest" ) {
670 fgSetString("/sim/fog", "nicest");
671 } else if ( arg == "--disable-clouds" ) {
672 fgSetBool("/environment/clouds/status", false);
673 } else if ( arg == "--enable-clouds" ) {
674 fgSetBool("/environment/clouds/status", true);
675 } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
676 // FIXME: check units
677 if ( fgGetString("/sim/startup/units") == "feet" )
678 fgSetDouble("/environment/clouds/altitude",
679 atof(arg.substr(13)) * FEET_TO_METER);
681 fgSetDouble("/environment/clouds/altitude",
682 atof(arg.substr(13)));
683 } else if ( arg.find( "--fov=" ) != string::npos ) {
684 parse_fov( arg.substr(6) );
685 } else if ( arg == "--disable-fullscreen" ) {
686 fgSetBool("/sim/startup/fullscreen", false);
687 } else if ( arg== "--enable-fullscreen") {
688 fgSetBool("/sim/startup/fullscreen", true);
689 } else if ( arg == "--shading-flat") {
690 fgSetBool("/sim/rendering/shading", false);
691 } else if ( arg == "--shading-smooth") {
692 fgSetBool("/sim/rendering/shading", true);
693 } else if ( arg == "--disable-skyblend") {
694 fgSetBool("/sim/rendering/skyblend", false);
695 } else if ( arg== "--enable-skyblend" ) {
696 fgSetBool("/sim/rendering/skyblend", true);
697 } else if ( arg == "--disable-textures" ) {
698 fgSetBool("/sim/rendering/textures", false);
699 } else if ( arg == "--enable-textures" ) {
700 fgSetBool("/sim/rendering/textures", true);
701 } else if ( arg == "--disable-wireframe" ) {
702 fgSetBool("/sim/rendering/wireframe", false);
703 } else if ( arg == "--enable-wireframe" ) {
704 fgSetBool("/sim/rendering/wireframe", true);
705 } else if ( arg.find( "--geometry=" ) != string::npos ) {
706 bool geometry_ok = true;
707 int xsize = 0, ysize = 0;
708 string geometry = arg.substr( 11 );
709 string::size_type i = geometry.find('x');
711 if (i != string::npos) {
712 xsize = atoi(geometry.substr(0, i));
713 ysize = atoi(geometry.substr(i+1));
718 if ( xsize <= 0 || ysize <= 0 ) {
724 if ( !geometry_ok ) {
725 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
726 FG_LOG( FG_GENERAL, FG_ALERT,
727 "Setting geometry to " << xsize << 'x' << ysize << '\n');
729 FG_LOG( FG_GENERAL, FG_INFO,
730 "Setting geometry to " << xsize << 'x' << ysize << '\n');
731 fgSetInt("/sim/startup/xsize", xsize);
732 fgSetInt("/sim/startup/ysize", ysize);
734 } else if ( arg.find( "--bpp=" ) != string::npos ) {
735 string bits_per_pix = arg.substr( 6 );
736 if ( bits_per_pix == "16" ) {
737 fgSetInt("/sim/rendering/bits-per-pixel", 16);
738 } else if ( bits_per_pix == "24" ) {
739 fgSetInt("/sim/rendering/bits-per-pixel", 24);
740 } else if ( bits_per_pix == "32" ) {
741 fgSetInt("/sim/rendering/bits-per-pixel", 32);
743 FG_LOG(FG_GENERAL, FG_ALERT, "Unsupported bpp " << bits_per_pix);
745 } else if ( arg == "--units-feet" ) {
746 fgSetString("/sim/startup/units", "feet");
747 } else if ( arg == "--units-meters" ) {
748 fgSetString("/sim/startup/units", "meters");
749 } else if ( arg.find( "--time-offset" ) != string::npos ) {
750 fgSetInt("/sim/startup/time-offset",
751 parse_time_offset( (arg.substr(14)) ));
752 } else if ( arg.find( "--time-match-real") != string::npos ) {
753 fgSetString("/sim/startup/time-offset_type",
755 } else if ( arg.find( "--time-match-local") != string::npos ) {
756 fgSetString("/sim/startup/time-offset_type",
758 } else if ( arg.find( "--start-date-sys=") != string::npos ) {
759 fgSetInt("/sim/startup/time-offset",
760 parse_date((arg.substr(17))));
761 fgSetString("/sim/startup/time-offset-type", "system");
762 } else if ( arg.find( "--start-date-lat=") != string::npos ) {
763 fgSetInt("/sim/startup/time-offset",
764 parse_date((arg.substr(17))));
765 fgSetString("/sim/startup/time-offset-type",
767 } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
768 fgSetInt("/sim/startup/time-offset",
769 parse_date((arg.substr(17))));
770 fgSetString("/sim/startup/time-offset-type", "gmt");
771 } else if ( arg == "--hud-tris" ) {
772 fgSetString("/sim/hud/frame-stat-type", "tris");
773 } else if ( arg == "--hud-culled" ) {
774 fgSetString("/sim/hud/frame-stat-type", "culled");
775 } else if ( arg.find( "--atlas=" ) != string::npos ) {
776 parse_channel( "atlas", arg.substr(8) );
777 } else if ( arg.find( "--native=" ) != string::npos ) {
778 parse_channel( "native", arg.substr(9) );
779 } else if ( arg.find( "--garmin=" ) != string::npos ) {
780 parse_channel( "garmin", arg.substr(9) );
781 } else if ( arg.find( "--nmea=" ) != string::npos ) {
782 parse_channel( "nmea", arg.substr(7) );
783 } else if ( arg.find( "--props=" ) != string::npos ) {
784 parse_channel( "props", arg.substr(8) );
785 } else if ( arg.find( "--pve=" ) != string::npos ) {
786 parse_channel( "pve", arg.substr(6) );
787 } else if ( arg.find( "--ray=" ) != string::npos ) {
788 parse_channel( "ray", arg.substr(6) );
789 } else if ( arg.find( "--rul=" ) != string::npos ) {
790 parse_channel( "rul", arg.substr(6) );
791 } else if ( arg.find( "--joyclient=" ) != string::npos ) {
792 parse_channel( "joyclient", arg.substr(12) );
793 #ifdef FG_NETWORK_OLK
794 } else if ( arg == "--disable-network-olk" ) {
795 fgSetBool("/sim/networking/olk", false);
796 } else if ( arg== "--enable-network-olk") {
797 fgSetBool("/sim/networking/olk", true);
798 } else if ( arg == "--net-hud" ) {
799 fgSetBool("/sim/hud/net-display", true);
800 net_hud_display = 1; // FIXME
801 } else if ( arg.find( "--net-id=") != string::npos ) {
802 fgSetString("sim/networking/call-sign", arg.substr(9));
804 } else if ( arg.find( "--prop:" ) == 0 ) {
805 string assign = arg.substr(7);
806 int pos = assign.find('=');
807 if (pos == arg.npos || pos == 0) {
808 FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
809 return FG_OPTIONS_ERROR;
811 string name = assign.substr(0, pos);
812 string value = assign.substr(pos + 1);
813 fgSetString(name.c_str(), value);
814 // FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
815 // << name << " to \"" << value << '"');
816 // $$$ begin - added VS Renganathan, 14 Oct 2K
817 // for multi-window outside window imagery
818 } else if ( arg.find( "--view-offset=" ) != string::npos ) {
819 string woffset = arg.substr( 14 );
820 double default_view_offset = 0.0;
821 if ( woffset == "LEFT" ) {
822 default_view_offset = FG_PI * 0.25;
823 } else if ( woffset == "RIGHT" ) {
824 default_view_offset = FG_PI * 1.75;
825 } else if ( woffset == "CENTER" ) {
826 default_view_offset = 0.00;
828 default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD;
830 FGViewerRPH *pilot_view =
831 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
832 pilot_view->set_view_offset( default_view_offset );
833 pilot_view->set_goal_view_offset( default_view_offset );
834 fgSetDouble("/sim/startup/view-offset", default_view_offset);
835 // $$$ end - added VS Renganathan, 14 Oct 2K
836 } else if ( arg.find( "--visibility=" ) != string::npos ) {
837 fgSetDouble("/environment/visibility", atof(arg.substr(13)));
838 } else if ( arg.find( "--visibility-miles=" ) != string::npos ) {
839 double visibility = atof(arg.substr(19)) * 5280.0 * FEET_TO_METER;
840 fgSetDouble("/environment/visibility", visibility);
841 } else if ( arg.find( "--wind=" ) == 0 ) {
842 string val = arg.substr(7);
843 int pos = val.find('@');
844 if (pos == string::npos) {
845 FG_LOG(FG_GENERAL, FG_ALERT, "bad wind value " << val);
846 return FG_OPTIONS_ERROR;
848 double dir = atof(val.substr(0,pos).c_str());
849 double speed = atof(val.substr(pos+1).c_str());
850 FG_LOG(FG_GENERAL, FG_INFO, "WIND: " << dir << '@' <<
851 speed << " knots" << endl);
853 speed *= NM_TO_METER * METER_TO_FEET * (1.0/3600);
858 fgSetDouble("/environment/wind-north",
860 fgSetDouble("/environment/wind-east",
862 } else if ( arg.find( "--wp=" ) != string::npos ) {
863 parse_wp( arg.substr( 5 ) );
864 } else if ( arg.find( "--flight-plan=") != string::npos) {
865 parse_flightplan ( arg.substr (14) );
867 FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
868 return FG_OPTIONS_ERROR;
871 return FG_OPTIONS_OK;
875 // Scan the command line options for an fg_root definition and set
878 fgScanForRoot (int argc, char **argv)
882 FG_LOG(FG_GENERAL, FG_INFO, "Scanning for root: command line");
885 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
887 string arg = argv[i];
888 if ( arg.find( "--fg-root=" ) != string::npos ) {
889 return arg.substr( 10 );
899 // Scan the config file for an fg_root definition and set just that.
901 fgScanForRoot (const string& path)
903 fg_gzifstream in( path );
907 FG_LOG( FG_GENERAL, FG_INFO, "Scanning for root: " << path );
911 while ( ! in.eof() ) {
914 while ( in.get(c) && c != '\0' ) {
919 #ifdef GETLINE_NEEDS_TERMINATOR
920 getline( in, line, '\n' );
921 #elif defined( macintosh )
922 getline( in, line, '\r' );
927 if ( line.find( "--fg-root=" ) != string::npos ) {
928 return line.substr( 10 );
938 // Parse the command line options
940 fgParseOptions (int argc, char **argv) {
944 FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
947 FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
949 result = parse_option(argv[i]);
950 if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
960 // Parse config file options
962 fgParseOptions (const string& path) {
963 fg_gzifstream in( path );
967 FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
971 while ( ! in.eof() ) {
974 while ( in.get(c) && c != '\0' ) {
979 #ifdef GETLINE_NEEDS_TERMINATOR
980 getline( in, line, '\n' );
981 #elif defined( macintosh )
982 getline( in, line, '\r' );
987 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
988 FG_LOG( FG_GENERAL, FG_ALERT,
989 "Config file parse error: " << path << " '"
999 // Print usage message
1003 cout << "Usage: fgfs [ options ... ]" << endl;
1006 cout << "General Options:" << endl;
1007 cout << "\t--help -h: print usage" << endl;
1008 cout << "\t--fg-root=path: specify the root path for all the data files"
1010 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
1012 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1013 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
1014 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1015 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1016 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1017 cout << "\t--disable-intro-music: disable introduction music" << endl;
1018 cout << "\t--enable-intro-music: enable introduction music" << endl;
1019 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1020 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1022 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1023 cout << "\t--disable-freeze: start out in an running state" << endl;
1024 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1025 cout << "\t--control=mode: primary control mode "
1026 << "(joystick, keyboard, mouse)" << endl;
1029 cout << "Features:" << endl;
1030 cout << "\t--disable-hud: disable heads up display" << endl;
1031 cout << "\t--enable-hud: enable heads up display" << endl;
1032 cout << "\t--disable-panel: disable instrument panel" << endl;
1033 cout << "\t--enable-panel: enable instrumetn panel" << endl;
1034 cout << "\t--disable-sound: disable sound effects" << endl;
1035 cout << "\t--enable-sound: enable sound effects" << endl;
1036 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1037 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1040 cout << "Flight Model:" << endl;
1041 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1042 cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1044 cout << "\t--aircraft=abcd: aircraft model to load" << endl;
1045 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1047 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1048 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1049 cout << "\t--on-ground: Start up at ground level (default)" << endl;
1050 cout << "\t--in-air: Start up in air (implied by specifying an initial"
1051 << " altitude above ground level." << endl;
1052 cout << "\t--wind=DIR@SPEED: specify wind coming from DIR (degrees) at SPEED (knots)" << endl;
1056 cout <<"Aircraft model directory:" << endl;
1057 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1060 cout << "Initial Position and Orientation:" << endl;
1061 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1063 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1065 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1067 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1068 cout << "\t\t(unless --units-meters specified" << endl;
1069 cout << "\t--heading=degrees: heading (yaw) angle in degress (Psi)"
1071 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1072 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1073 cout << "\t--uBody=feet per second: velocity along the body X axis"
1075 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1077 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1079 cout << "\t\t(unless --units-meters specified" << endl;
1080 cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1081 cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1084 cout << "Rendering Options:" << endl;
1085 cout << "\t--fog-disable: disable fog/haze" << endl;
1086 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1087 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1088 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1089 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1090 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1091 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1093 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1094 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1095 cout << "\t--shading-flat: enable flat shading" << endl;
1096 cout << "\t--shading-smooth: enable smooth shading" << endl;
1097 cout << "\t--disable-skyblend: disable sky blending" << endl;
1098 cout << "\t--enable-skyblend: enable sky blending" << endl;
1099 cout << "\t--disable-textures: disable textures" << endl;
1100 cout << "\t--enable-textures: enable textures" << endl;
1101 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1102 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1103 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1105 cout << "\t--view-offset=xxx: set the default forward view direction"
1107 cout << "\t\tas an offset from straight ahead. Allowable values are"
1109 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1110 cout << "\t--visibility=xxx: specify initial visibility in meters" << endl;
1111 cout << "\t--visibility-miles=xxx: specify initial visibility in miles"
1115 cout << "Scenery Options:" << endl;
1116 cout << "\t--tile-radius=n: specify tile radius, must be 1 - 4" << endl;
1119 cout << "Hud Options:" << endl;
1120 cout << "\t--units-feet: Hud displays units in feet" << endl;
1121 cout << "\t--units-meters: Hud displays units in meters" << endl;
1122 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1123 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1127 cout << "Time Options:" << endl;
1128 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1129 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1130 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1131 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1132 << "\t\tFlightGear time" << endl;
1133 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1134 << "\t\tdate/time. Uses your system time " << endl;
1135 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1136 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1137 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1138 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1139 #ifdef FG_NETWORK_OLK
1142 cout << "Network Options:" << endl;
1143 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1144 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1145 cout << "\t--net-hud: Hud displays network info" << endl;
1146 cout << "\t--net-id=name: specify your own callsign" << endl;
1150 cout << "Route/Way Point Options:" << endl;
1151 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1152 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1154 cout << "\t\tinstances of --wp=" << endl;
1155 cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;