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>
29 #include <simgear/misc/exception.hxx>
31 #include <math.h> // rint()
33 #include <stdlib.h> // atof(), atoi()
34 #include <string.h> // strcmp()
40 #include <simgear/math/sg_random.h>
41 #include <simgear/misc/sgstream.hxx>
42 #include <simgear/misc/sg_path.hxx>
43 #include <simgear/route/route.hxx>
44 #include <simgear/route/waypoint.hxx>
46 // #include <Include/general.hxx>
47 // #include <Airports/simple.hxx>
48 // #include <Cockpit/cockpit.hxx>
49 // #include <FDM/flight.hxx>
50 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
52 # include <NetworkOLK/network.h>
57 #include "globals.hxx"
58 #include "fg_init.hxx"
59 #include "fg_props.hxx"
60 #include "options.hxx"
61 #include "viewmgr.hxx"
64 SG_USING_NAMESPACE(std);
67 #define NEW_DEFAULT_MODEL_HZ 120
74 FG_OPTIONS_VERBOSE_HELP = 3,
75 FG_OPTIONS_SHOW_AIRCRAFT = 4
79 atof( const string& str )
83 // -dw- if ::atof is called, then we get an infinite loop
84 return std::atof( str.c_str() );
86 return ::atof( str.c_str() );
91 atoi( const string& str )
94 // -dw- if ::atoi is called, then we get an infinite loop
95 return std::atoi( str.c_str() );
97 return ::atoi( str.c_str() );
103 * Set a few fail-safe default property values.
105 * These should all be set in $FG_ROOT/preferences.xml, but just
106 * in case, we provide some initial sane values here. This method
107 * should be invoked *before* reading any init files.
112 // set a possibly independent location for scenery data
113 char *envp = ::getenv( "FG_SCENERY" );
115 if ( envp != NULL ) {
116 // fg_root could be anywhere, so default to environmental
117 // variable $FG_ROOT if it is set.
118 globals->set_fg_scenery(envp);
120 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
121 globals->set_fg_scenery("");
123 // Position (deliberately out of range)
124 fgSetDouble("/position/longitude-deg", 9999.0);
125 fgSetDouble("/position/latitude-deg", 9999.0);
126 fgSetDouble("/position/altitude-ft", -9999.0);
129 fgSetDouble("/orientation/heading-deg", 270);
130 fgSetDouble("/orientation/roll-deg", 0);
131 fgSetDouble("/orientation/pitch-deg", 0.424);
134 fgSetString("/sim/startup/speed-set", "knots");
135 fgSetDouble("/velocities/uBody-fps", 0.0);
136 fgSetDouble("/velocities/vBody-fps", 0.0);
137 fgSetDouble("/velocities/wBody-fps", 0.0);
138 fgSetDouble("/velocities/speed-north-fps", 0.0);
139 fgSetDouble("/velocities/speed-east-fps", 0.0);
140 fgSetDouble("/velocities/speed-down-fps", 0.0);
141 fgSetDouble("/velocities/airspeed-kt", 0.0);
142 fgSetDouble("/velocities/mach", 0.0);
145 fgSetBool("/sim/startup/game-mode", false);
146 fgSetBool("/sim/startup/splash-screen", true);
147 fgSetBool("/sim/startup/intro-music", true);
148 // we want mouse-pointer to have an undefined value if nothing is
149 // specified so we can do the right thing for voodoo-1/2 cards.
150 // fgSetString("/sim/startup/mouse-pointer", "disabled");
151 fgSetString("/sim/control-mode", "joystick");
152 fgSetBool("/sim/auto-coordination", false);
154 fgSetString("/sim/startup/browser-app", "netscape");
156 fgSetString("/sim/startup/browser-app", "webrun.bat");
159 fgSetBool("/sim/hud/visibility", false);
160 fgSetBool("/sim/panel/visibility", true);
161 fgSetBool("/sim/sound/audible", true);
162 fgSetBool("/sim/hud/antialiased", false);
164 // Flight Model options
165 fgSetString("/sim/flight-model", "jsb");
166 fgSetString("/sim/aero", "c172");
167 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
168 fgSetInt("/sim/speed-up", 1);
169 fgSetBool("/sim/startup/trim", false);
170 fgSetBool("/sim/startup/onground", true);
173 fgSetString("/sim/rendering/fog", "nicest");
174 fgSetBool("/environment/clouds/status", true);
175 fgSetBool("/sim/startup/fullscreen", false);
176 fgSetBool("/sim/rendering/shading", true);
177 fgSetBool("/sim/rendering/skyblend", true);
178 fgSetBool("/sim/rendering/textures", true);
179 fgSetBool("/sim/rendering/wireframe", false);
180 fgSetInt("/sim/startup/xsize", 800);
181 fgSetInt("/sim/startup/ysize", 600);
182 fgSetInt("/sim/rendering/bits-per-pixel", 16);
183 fgSetString("/sim/view-mode", "pilot");
184 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
185 fgSetDouble("/environment/visibility-m", 20000);
188 fgSetString("/sim/startup/units", "feet");
189 fgSetString("/sim/hud/frame-stat-type", "tris");
192 fgSetInt("/sim/startup/time-offset", 0);
193 fgSetString("/sim/startup/time-offset-type", "system-offset");
194 fgSetLong("/sim/time/cur-time-override", 0);
196 fgSetBool("/sim/networking/network-olk", false);
197 fgSetString("/sim/networking/call-sign", "Johnny");
200 fgSetBool("/sim/freeze/master", false);
201 fgSetBool("/sim/freeze/position", false);
202 fgSetBool("/sim/freeze/clock", false);
203 fgSetBool("/sim/freeze/fuel", false);
208 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
209 double * speed, double * gust)
211 string::size_type pos = wind.find('@');
212 if (pos == string::npos)
214 string dir = wind.substr(0, pos);
215 string spd = wind.substr(pos+1);
217 if (pos == string::npos) {
218 *min_hdg = *max_hdg = atof(dir.c_str());
220 *min_hdg = atof(dir.substr(0,pos).c_str());
221 *max_hdg = atof(dir.substr(pos+1).c_str());
224 if (pos == string::npos) {
225 *speed = *gust = atof(spd.c_str());
227 *speed = atof(spd.substr(0,pos).c_str());
228 *gust = atof(spd.substr(pos+1).c_str());
233 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
235 parse_time(const string& time_in) {
236 char *time_str, num[256];
237 double hours, minutes, seconds;
242 time_str = (char *)time_in.c_str();
244 // printf("parse_time(): %s\n", time_str);
247 if ( strlen(time_str) ) {
248 if ( time_str[0] == '+' ) {
251 } else if ( time_str[0] == '-' ) {
256 // printf("sign = %d\n", sign);
259 if ( strlen(time_str) ) {
261 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
262 num[i] = time_str[0];
266 if ( time_str[0] == ':' ) {
271 // printf("hours = %.2lf\n", hours);
277 if ( strlen(time_str) ) {
279 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
280 num[i] = time_str[0];
284 if ( time_str[0] == ':' ) {
289 // printf("minutes = %.2lf\n", minutes);
291 result += minutes / 60.0;
295 if ( strlen(time_str) ) {
297 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
298 num[i] = time_str[0];
304 // printf("seconds = %.2lf\n", seconds);
306 result += seconds / 3600.0;
309 return(sign * result);
313 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
315 parse_date( const string& date)
318 char * date_str, num[256];
320 // initialize to zero
327 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
328 date_str = (char *)date.c_str();
330 if ( strlen(date_str) ) {
332 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
333 num[i] = date_str[0];
337 if ( date_str[0] == ':' ) {
341 gmt.tm_year = atoi(num) - 1900;
344 if ( strlen(date_str) ) {
346 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
347 num[i] = date_str[0];
351 if ( date_str[0] == ':' ) {
355 gmt.tm_mon = atoi(num) -1;
358 if ( strlen(date_str) ) {
360 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
361 num[i] = date_str[0];
365 if ( date_str[0] == ':' ) {
369 gmt.tm_mday = atoi(num);
372 if ( strlen(date_str) ) {
374 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
375 num[i] = date_str[0];
379 if ( date_str[0] == ':' ) {
383 gmt.tm_hour = atoi(num);
386 if ( strlen(date_str) ) {
388 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
389 num[i] = date_str[0];
393 if ( date_str[0] == ':' ) {
397 gmt.tm_min = atoi(num);
400 if ( strlen(date_str) ) {
402 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
403 num[i] = date_str[0];
407 if ( date_str[0] == ':' ) {
411 gmt.tm_sec = atoi(num);
413 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
414 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
415 //printf ("Date is %s\n", ctime(&theTime));
416 //printf ("in seconds that is %d\n", theTime);
422 // parse angle in the form of [+/-]ddd:mm:ss into degrees
424 parse_degree( const string& degree_str) {
425 double result = parse_time( degree_str );
427 // printf("Degree = %.4f\n", result);
433 // parse time offset string into seconds
435 parse_time_offset( const string& time_str) {
438 // printf("time offset = %s\n", time_str);
441 result = (int)rint(parse_time(time_str) * 3600.0);
443 result = (int)(parse_time(time_str) * 3600.0);
446 // printf("parse_time_offset(): %d\n", result);
452 // Parse --fov=x.xx type option
454 parse_fov( const string& arg ) {
455 double fov = atof(arg);
457 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
458 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
460 fgSetDouble("/sim/current-view/field-of-view", fov);
462 // printf("parse_fov(): result = %.4f\n", fov);
468 // Parse I/O channel option
470 // Format is "--protocol=medium,direction,hz,medium_options,..."
472 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
473 // medium = { serial, socket, file, etc. }
474 // direction = { in, out, bi }
475 // hz = number of times to process channel per second (floating
476 // point values are ok.
478 // Serial example "--nmea=serial,dir,hz,device,baud" where
480 // device = OS device name of serial line to be open()'ed
481 // baud = {300, 1200, 2400, ..., 230400}
483 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
485 // machine = machine name or ip address if client (leave empty if server)
486 // port = port, leave empty to let system choose
487 // style = tcp or udp
489 // File example "--garmin=file,dir,hz,filename" where
491 // filename = file system file name
494 add_channel( const string& type, const string& channel_str ) {
495 // cout << "Channel string = " << channel_str << endl;
497 globals->get_channel_options_list()->push_back( type + "," + channel_str );
504 setup_wind (double min_hdg, double max_hdg, double speed, double gust)
506 fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
507 fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
508 fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
509 fgSetDouble("/environment/wind-speed-kt", speed);
510 fgSetDouble("/environment/params/base-wind-speed-kt", speed);
511 fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
513 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
514 speed << " knots" << endl);
518 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
519 while (min_hdg > 360)
523 min_hdg *= SGD_DEGREES_TO_RADIANS;
524 fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
525 fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
526 #endif // FG_WEATHERCM
530 // Parse --wp=ID[@alt]
532 parse_wp( const string& arg ) {
536 string::size_type pos = arg.find( "@" );
537 if ( pos != string::npos ) {
538 id = arg.substr( 0, pos );
539 alt_str = arg.substr( pos + 1 );
540 // cout << "id str = " << id << " alt str = " << alt_str << endl;
541 alt = atof( alt_str.c_str() );
542 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
543 alt *= SG_FEET_TO_METER;
550 if ( fgFindAirportID( id, &a ) ) {
551 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
552 globals->get_route()->add_waypoint( wp );
561 // Parse --flight-plan=[file]
563 parse_flightplan(const string& arg)
565 sg_gzifstream in(arg.c_str());
566 if ( !in.is_open() ) {
572 #if defined( macintosh )
573 getline( in, line, '\r' );
575 getline( in, line, '\n' );
578 // catch extraneous (DOS) line ending character
579 if ( line[line.length() - 1] < 32 ) {
580 line = line.substr( 0, line.length()-1 );
593 // Parse a single option
595 parse_option (const string& arg)
598 if ( (arg == "--help") || (arg == "-h") ) {
599 // help/usage request
600 return(FG_OPTIONS_HELP);
601 } else if ( (arg == "--verbose") || (arg == "-v") ) {
602 // verbose help/usage request
603 return(FG_OPTIONS_VERBOSE_HELP);
604 } else if ( arg == "--disable-game-mode") {
605 fgSetBool("/sim/startup/game-mode", false);
606 } else if ( arg == "--enable-game-mode" ) {
607 fgSetBool("/sim/startup/game-mode", true);
608 } else if ( arg == "--disable-splash-screen" ) {
609 fgSetBool("/sim/startup/splash-screen", false);
610 } else if ( arg == "--enable-splash-screen" ) {
611 fgSetBool("/sim/startup/splash-screen", true);
612 } else if ( arg == "--disable-intro-music" ) {
613 fgSetBool("/sim/startup/intro-music", false);
614 } else if ( arg == "--enable-intro-music" ) {
615 fgSetBool("/sim/startup/intro-music", true);
616 } else if ( arg == "--disable-mouse-pointer" ) {
617 fgSetString("/sim/startup/mouse-pointer", "disabled");
618 } else if ( arg == "--enable-mouse-pointer" ) {
619 fgSetString("/sim/startup/mouse-pointer", "enabled");
620 } else if ( arg == "--disable-random-objects" ) {
621 fgSetBool("/sim/rendering/random-objects", false);
622 } else if ( arg == "--enable-random-objects" ) {
623 fgSetBool("/sim/rendering/random-objects", true);
624 } else if ( arg == "--disable-freeze" ) {
625 fgSetBool("/sim/freeze/master", false);
626 } else if ( arg == "--enable-freeze" ) {
627 fgSetBool("/sim/freeze/master", true);
628 } else if ( arg == "--disable-fuel-freeze" ) {
629 fgSetBool("/sim/freeze/fuel", false);
630 } else if ( arg == "--enable-fuel-freeze" ) {
631 fgSetBool("/sim/freeze/fuel", true);
632 } else if ( arg == "--disable-clock-freeze" ) {
633 fgSetBool("/sim/freeze/clock", false);
634 } else if ( arg == "--enable-clock-freeze" ) {
635 fgSetBool("/sim/freeze/clock", true);
636 } else if ( arg == "--disable-anti-alias-hud" ) {
637 fgSetBool("/sim/hud/antialiased", false);
638 } else if ( arg == "--enable-anti-alias-hud" ) {
639 fgSetBool("/sim/hud/antialiased", true);
640 } else if ( arg.find( "--control=") == 0 ) {
641 fgSetString("/sim/control-mode", arg.substr(10).c_str());
642 } else if ( arg == "--disable-auto-coordination" ) {
643 fgSetBool("/sim/auto-coordination", false);
644 } else if ( arg == "--enable-auto-coordination" ) {
645 fgSetBool("/sim/auto-coordination", true);
646 } else if ( arg.find( "--browser-app=") == 0 ) {
647 fgSetString("/sim/startup/browser-app", arg.substr(14).c_str());
648 } else if ( arg == "--disable-hud" ) {
649 fgSetBool("/sim/hud/visibility", false);
650 } else if ( arg == "--enable-hud" ) {
651 fgSetBool("/sim/hud/visibility", true);
652 } else if ( arg == "--disable-panel" ) {
653 fgSetBool("/sim/panel/visibility", false);
654 } else if ( arg == "--enable-panel" ) {
655 fgSetBool("/sim/panel/visibility", true);
656 } else if ( arg == "--disable-sound" ) {
657 fgSetBool("/sim/sound/audible", false);
658 } else if ( arg == "--enable-sound" ) {
659 fgSetBool("/sim/sound/audible", true);
660 } else if ( arg.find( "--airport-id=") == 0 ) {
661 // NB: changed property name!!!
662 fgSetString("/sim/startup/airport-id", arg.substr(13).c_str());
663 } else if ( arg.find( "--offset-distance=") == 0 ) {
664 fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
665 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
666 fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17)));
667 } else if ( arg.find( "--lon=" ) == 0 ) {
668 fgSetDouble("/position/longitude-deg",
669 parse_degree(arg.substr(6)));
670 fgSetString("/sim/startup/airport-id", "");
671 } else if ( arg.find( "--lat=" ) == 0 ) {
672 fgSetDouble("/position/latitude-deg",
673 parse_degree(arg.substr(6)));
674 fgSetString("/sim/startup/airport-id", "");
675 } else if ( arg.find( "--altitude=" ) == 0 ) {
676 fgSetBool("/sim/startup/onground", false);
677 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
678 fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
680 fgSetDouble("/position/altitude-ft",
681 atof(arg.substr(11)) * SG_METER_TO_FEET);
682 } else if ( arg.find( "--uBody=" ) == 0 ) {
683 fgSetString("/sim/startup/speed-set", "UVW");
684 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
685 fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
687 fgSetDouble("/velocities/uBody-fps",
688 atof(arg.substr(8)) * SG_METER_TO_FEET);
689 } else if ( arg.find( "--vBody=" ) == 0 ) {
690 fgSetString("/sim/startup/speed-set", "UVW");
691 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
692 fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
694 fgSetDouble("/velocities/vBody-fps",
695 atof(arg.substr(8)) * SG_METER_TO_FEET);
696 } else if ( arg.find( "--wBody=" ) == 0 ) {
697 fgSetString("/sim/startup/speed-set", "UVW");
698 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
699 fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
701 fgSetDouble("/velocities/wBody-fps",
702 atof(arg.substr(8)) * SG_METER_TO_FEET);
703 } else if ( arg.find( "--vNorth=" ) == 0 ) {
704 fgSetString("/sim/startup/speed-set", "NED");
705 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
706 fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
708 fgSetDouble("/velocities/speed-north-fps",
709 atof(arg.substr(9)) * SG_METER_TO_FEET);
710 } else if ( arg.find( "--vEast=" ) == 0 ) {
711 fgSetString("/sim/startup/speed-set", "NED");
712 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
713 fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
715 fgSetDouble("/velocities/speed-east-fps",
716 atof(arg.substr(8)) * SG_METER_TO_FEET);
717 } else if ( arg.find( "--vDown=" ) == 0 ) {
718 fgSetString("/sim/startup/speed-set", "NED");
719 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
720 fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
722 fgSetDouble("/velocities/speed-down-fps",
723 atof(arg.substr(8)) * SG_METER_TO_FEET);
724 } else if ( arg.find( "--vc=" ) == 0) {
725 fgSetString("/sim/startup/speed-set", "knots");
726 fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
727 } else if ( arg.find( "--mach=" ) == 0) {
728 fgSetString("/sim/startup/speed-set", "mach");
729 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
730 } else if ( arg.find( "--heading=" ) == 0 ) {
731 fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
732 } else if ( arg.find( "--roll=" ) == 0 ) {
733 fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
734 } else if ( arg.find( "--pitch=" ) == 0 ) {
735 fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
736 } else if ( arg.find( "--glideslope=" ) == 0 ) {
737 fgSetDouble("/velocities/glideslope", atof(arg.substr(13))
738 *SG_DEGREES_TO_RADIANS);
739 } else if ( arg.find( "--roc=" ) == 0 ) {
740 fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
741 } else if ( arg.find( "--fg-root=" ) == 0 ) {
742 globals->set_fg_root(arg.substr( 10 ));
743 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
744 globals->set_fg_scenery(arg.substr( 13 ));
745 } else if ( arg.find( "--fdm=" ) == 0 ) {
746 fgSetString("/sim/flight-model", arg.substr(6).c_str());
747 } else if ( arg.find( "--aero=" ) == 0 ) {
748 fgSetString("/sim/aero", arg.substr(7).c_str());
749 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
750 fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
751 } else if ( arg.find( "--show-aircraft") == 0) {
752 return(FG_OPTIONS_SHOW_AIRCRAFT);
753 } else if ( arg.find( "--model-hz=" ) == 0 ) {
754 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
755 } else if ( arg.find( "--speed=" ) == 0 ) {
756 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
757 } else if ( arg.find( "--trim") == 0) {
758 fgSetBool("/sim/startup/trim", true);
759 } else if ( arg.find( "--notrim") == 0) {
760 fgSetBool("/sim/startup/trim", false);
761 } else if ( arg.find( "--on-ground") == 0) {
762 fgSetBool("/sim/startup/onground", true);
763 } else if ( arg.find( "--in-air") == 0) {
764 fgSetBool("/sim/startup/onground", false);
765 } else if ( arg == "--fog-disable" ) {
766 fgSetString("/sim/rendering/fog", "disabled");
767 } else if ( arg == "--fog-fastest" ) {
768 fgSetString("/sim/rendering/fog", "fastest");
769 } else if ( arg == "--fog-nicest" ) {
770 fgSetString("/sim/fog", "nicest");
771 } else if ( arg == "--disable-clouds" ) {
772 fgSetBool("/environment/clouds/status", false);
773 } else if ( arg == "--enable-clouds" ) {
774 fgSetBool("/environment/clouds/status", true);
775 } else if ( arg == "--disable-clouds3d" ) {
776 fgSetBool("/sim/rendering/clouds3d", false);
777 } else if ( arg == "--enable-clouds3d" ) {
778 fgSetBool("/sim/rendering/clouds3d", true);
779 } else if ( arg.find( "--fov=" ) == 0 ) {
780 parse_fov( arg.substr(6) );
781 } else if ( arg == "--disable-fullscreen" ) {
782 fgSetBool("/sim/startup/fullscreen", false);
783 } else if ( arg== "--enable-fullscreen") {
784 fgSetBool("/sim/startup/fullscreen", true);
785 } else if ( arg == "--shading-flat") {
786 fgSetBool("/sim/rendering/shading", false);
787 } else if ( arg == "--shading-smooth") {
788 fgSetBool("/sim/rendering/shading", true);
789 } else if ( arg == "--disable-skyblend") {
790 fgSetBool("/sim/rendering/skyblend", false);
791 } else if ( arg== "--enable-skyblend" ) {
792 fgSetBool("/sim/rendering/skyblend", true);
793 } else if ( arg == "--disable-textures" ) {
794 fgSetBool("/sim/rendering/textures", false);
795 } else if ( arg == "--enable-textures" ) {
796 fgSetBool("/sim/rendering/textures", true);
797 } else if ( arg == "--disable-wireframe" ) {
798 fgSetBool("/sim/rendering/wireframe", false);
799 } else if ( arg == "--enable-wireframe" ) {
800 fgSetBool("/sim/rendering/wireframe", true);
801 } else if ( arg.find( "--geometry=" ) == 0 ) {
802 bool geometry_ok = true;
803 int xsize = 0, ysize = 0;
804 string geometry = arg.substr( 11 );
805 string::size_type i = geometry.find('x');
807 if (i != string::npos) {
808 xsize = atoi(geometry.substr(0, i));
809 ysize = atoi(geometry.substr(i+1));
814 if ( xsize <= 0 || ysize <= 0 ) {
820 if ( !geometry_ok ) {
821 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
822 SG_LOG( SG_GENERAL, SG_ALERT,
823 "Setting geometry to " << xsize << 'x' << ysize << '\n');
825 SG_LOG( SG_GENERAL, SG_INFO,
826 "Setting geometry to " << xsize << 'x' << ysize << '\n');
827 fgSetInt("/sim/startup/xsize", xsize);
828 fgSetInt("/sim/startup/ysize", ysize);
830 } else if ( arg.find( "--bpp=" ) == 0 ) {
831 string bits_per_pix = arg.substr( 6 );
832 if ( bits_per_pix == "16" ) {
833 fgSetInt("/sim/rendering/bits-per-pixel", 16);
834 } else if ( bits_per_pix == "24" ) {
835 fgSetInt("/sim/rendering/bits-per-pixel", 24);
836 } else if ( bits_per_pix == "32" ) {
837 fgSetInt("/sim/rendering/bits-per-pixel", 32);
839 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
841 } else if ( arg == "--units-feet" ) {
842 fgSetString("/sim/startup/units", "feet");
843 } else if ( arg == "--units-meters" ) {
844 fgSetString("/sim/startup/units", "meters");
845 } else if ( arg.find( "--time-offset" ) == 0 ) {
846 fgSetInt("/sim/startup/time-offset",
847 parse_time_offset( (arg.substr(14)) ));
848 fgSetString("/sim/startup/time-offset-type", "system-offset");
849 } else if ( arg.find( "--time-match-real") == 0 ) {
850 fgSetString("/sim/startup/time-offset-type", "system-offset");
851 } else if ( arg.find( "--time-match-local") == 0 ) {
852 fgSetString("/sim/startup/time-offset-type", "latitude-offset");
853 } else if ( arg.find( "--start-date-sys=") == 0 ) {
854 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
855 fgSetString("/sim/startup/time-offset-type", "system");
856 } else if ( arg.find( "--start-date-lat=") == 0 ) {
857 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
858 fgSetString("/sim/startup/time-offset-type", "latitude");
859 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
860 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
861 fgSetString("/sim/startup/time-offset-type", "gmt");
862 } else if ( arg == "--hud-tris" ) {
863 fgSetString("/sim/hud/frame-stat-type", "tris");
864 } else if ( arg == "--hud-culled" ) {
865 fgSetString("/sim/hud/frame-stat-type", "culled");
866 } else if ( arg.find( "--atc610x" ) == 0 ) {
867 add_channel( "atc610x", "dummy" );
868 } else if ( arg.find( "--atlas=" ) == 0 ) {
869 add_channel( "atlas", arg.substr(8) );
870 } else if ( arg.find( "--httpd=" ) == 0 ) {
871 add_channel( "httpd", arg.substr(8) );
872 #ifdef FG_JPEG_SERVER
873 } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
874 add_channel( "jpg-httpd", arg.substr(12) );
876 } else if ( arg.find( "--native=" ) == 0 ) {
877 add_channel( "native", arg.substr(9) );
878 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
879 add_channel( "native_ctrls", arg.substr(15) );
880 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
881 add_channel( "native_fdm", arg.substr(13) );
882 } else if ( arg.find( "--opengc=" ) == 0 ) {
884 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
885 add_channel( "opengc", arg.substr(9) );
886 } else if ( arg.find( "--garmin=" ) == 0 ) {
887 add_channel( "garmin", arg.substr(9) );
888 } else if ( arg.find( "--nmea=" ) == 0 ) {
889 add_channel( "nmea", arg.substr(7) );
890 } else if ( arg.find( "--props=" ) == 0 ) {
891 add_channel( "props", arg.substr(8) );
892 } else if ( arg.find( "--telnet=" ) == 0 ) {
893 add_channel( "telnet", arg.substr(9) );
894 } else if ( arg.find( "--pve=" ) == 0 ) {
895 add_channel( "pve", arg.substr(6) );
896 } else if ( arg.find( "--ray=" ) == 0 ) {
897 add_channel( "ray", arg.substr(6) );
898 } else if ( arg.find( "--rul=" ) == 0 ) {
899 add_channel( "rul", arg.substr(6) );
900 } else if ( arg.find( "--joyclient=" ) == 0 ) {
901 add_channel( "joyclient", arg.substr(12) );
902 #ifdef FG_NETWORK_OLK
903 } else if ( arg == "--disable-network-olk" ) {
904 fgSetBool("/sim/networking/olk", false);
905 } else if ( arg== "--enable-network-olk") {
906 fgSetBool("/sim/networking/olk", true);
907 } else if ( arg == "--net-hud" ) {
908 fgSetBool("/sim/hud/net-display", true);
909 net_hud_display = 1; // FIXME
910 } else if ( arg.find( "--net-id=") == 0 ) {
911 fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
913 } else if ( arg.find( "--prop:" ) == 0 ) {
914 string assign = arg.substr(7);
915 string::size_type pos = assign.find('=');
916 if ( pos == arg.npos || pos == 0 ) {
917 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
918 return FG_OPTIONS_ERROR;
920 string name = assign.substr(0, pos);
921 string value = assign.substr(pos + 1);
922 fgSetString(name.c_str(), value.c_str());
923 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
924 // << name << " to \"" << value << '"');
925 } else if ( arg.find("--trace-read=") == 0) {
926 string name = arg.substr(13);
927 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
928 fgGetNode(name.c_str(), true)
929 ->setAttribute(SGPropertyNode::TRACE_READ, true);
930 } else if ( arg.find("--trace-write=") == 0) {
931 string name = arg.substr(14);
932 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
933 fgGetNode(name.c_str(), true)
934 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
935 } else if ( arg.find( "--view-offset=" ) == 0 ) {
936 // $$$ begin - added VS Renganathan, 14 Oct 2K
937 // for multi-window outside window imagery
938 string woffset = arg.substr( 14 );
939 double default_view_offset = 0.0;
940 if ( woffset == "LEFT" ) {
941 default_view_offset = SGD_PI * 0.25;
942 } else if ( woffset == "RIGHT" ) {
943 default_view_offset = SGD_PI * 1.75;
944 } else if ( woffset == "CENTER" ) {
945 default_view_offset = 0.00;
947 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
949 /* apparently not used (CLO, 11 Jun 2002)
950 FGViewer *pilot_view =
951 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
952 // this will work without calls to the viewer...
953 fgSetDouble( "/sim/current-view/heading-offset-deg",
954 default_view_offset * SGD_RADIANS_TO_DEGREES );
955 // $$$ end - added VS Renganathan, 14 Oct 2K
956 } else if ( arg.find( "--visibility=" ) == 0 ) {
957 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
958 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
959 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
960 fgSetDouble("/environment/visibility-m", visibility);
961 } else if ( arg.find( "--random-wind" ) == 0 ) {
962 double min_hdg = sg_random() * 360.0;
963 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
964 double speed = 40 - sqrt(sg_random() * 1600.0);
965 double gust = speed + (10 - sqrt(sg_random() * 100));
966 setup_wind(min_hdg, max_hdg, speed, gust);
967 } else if ( arg.find( "--wind=" ) == 0 ) {
968 double min_hdg, max_hdg, speed, gust;
969 if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
970 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
971 return FG_OPTIONS_ERROR;
973 setup_wind(min_hdg, max_hdg, speed, gust);
974 } else if ( arg.find( "--wp=" ) == 0 ) {
975 parse_wp( arg.substr( 5 ) );
976 } else if ( arg.find( "--flight-plan=") == 0) {
977 parse_flightplan ( arg.substr (14) );
978 } else if ( arg.find( "--config=" ) == 0 ) {
979 string file = arg.substr(9);
981 readProperties(file, globals->get_props());
982 } catch (const sg_exception &e) {
983 string message = "Error loading config file: ";
984 message += e.getFormattedMessage();
985 SG_LOG(SG_INPUT, SG_ALERT, message);
988 } else if ( arg.find( "--aircraft=" ) == 0 ) {
989 // read in the top level aircraft definition file
990 SGPath apath( globals->get_fg_root() );
991 apath.append( "Aircraft" );
992 apath.append( arg.substr(11) );
993 apath.concat( "-set.xml" );
994 SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11)
995 << " from " << apath.str());
996 readProperties( apath.str(), globals->get_props() );
998 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
999 return FG_OPTIONS_ERROR;
1002 return FG_OPTIONS_OK;
1006 // Scan the command line options for an fg_root definition and set
1009 fgScanForRoot (int argc, char **argv)
1013 SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
1015 while ( i < argc ) {
1016 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
1018 string arg = argv[i];
1019 if ( arg.find( "--fg-root=" ) == 0 ) {
1020 return arg.substr( 10 );
1030 // Scan the config file for an fg_root definition and set just that.
1032 fgScanForRoot (const string& path)
1034 sg_gzifstream in( path );
1035 if ( !in.is_open() )
1038 SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
1042 while ( ! in.eof() ) {
1045 while ( in.get(c) && c != '\0' ) {
1050 #if defined( macintosh )
1051 getline( in, line, '\r' );
1053 getline( in, line, '\n' );
1056 // catch extraneous (DOS) line ending character
1057 if ( line[line.length() - 1] < 32 ) {
1058 line = line.substr( 0, line.length()-1 );
1061 if ( line.find( "--fg-root=" ) == 0 ) {
1062 return line.substr( 10 );
1072 // Parse the command line options
1074 fgParseArgs (int argc, char **argv)
1076 bool in_options = true;
1077 bool verbose = false;
1080 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1082 for (int i = 1; i < argc; i++) {
1083 string arg = argv[i];
1085 if (in_options && (arg.find('-') == 0)) {
1089 int result = parse_option(arg);
1090 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1093 else if (result == FG_OPTIONS_VERBOSE_HELP)
1096 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1103 SG_LOG(SG_GENERAL, SG_INFO,
1104 "Reading command-line property file " << arg);
1105 readProperties(arg, globals->get_props());
1114 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1118 // Parse config file options
1120 fgParseOptions (const string& path) {
1121 sg_gzifstream in( path );
1122 if ( !in.is_open() ) {
1126 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1130 while ( ! in.eof() ) {
1133 while ( in.get(c) && c != '\0' ) {
1138 #if defined( macintosh )
1139 getline( in, line, '\r' );
1141 getline( in, line, '\n' );
1144 // catch extraneous (DOS) line ending character
1145 if ( line[line.length() - 1] < 32 ) {
1146 line = line.substr( 0, line.length()-1 );
1149 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1150 cout << endl << "Config file parse error: " << path << " '"
1151 << line << "'" << endl;
1160 // Print usage message
1162 fgUsage (bool verbose)
1164 SGPropertyNode options_root;
1165 SGPath opath( globals->get_fg_root() );
1166 opath.append( "options.xml" );
1171 readProperties(opath.c_str(), &options_root);
1172 } catch (const sg_exception &ex) {
1173 cout << "Unable to read the help file." << endl;
1174 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1175 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1176 cout << "by adding --fg-root=path as a program argument." << endl;
1181 SGPropertyNode *options = options_root.getNode("options");
1183 SG_LOG( SG_GENERAL, SG_ALERT,
1184 "Error reading options.xml: <options> directive not found." );
1188 SGPropertyNode *usage = options->getNode("usage");
1190 cout << "Usage: " << usage->getStringValue() << endl;
1193 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1194 for (unsigned int j = 0; j < section.size(); j++) {
1197 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1198 for (unsigned int k = 0; k < option.size(); k++) {
1200 SGPropertyNode *name = option[k]->getNode("name");
1201 SGPropertyNode *short_name = option[k]->getNode("short");
1202 SGPropertyNode *key = option[k]->getNode("key");
1203 SGPropertyNode *arg = option[k]->getNode("arg");
1204 bool brief = option[k]->getNode("brief");
1206 if ((brief || verbose) && name) {
1207 string tmp = name->getStringValue();
1211 tmp.append(key->getStringValue());
1215 tmp.append(arg->getStringValue());
1219 tmp.append(short_name->getStringValue());
1223 if (tmp.size() <= 25) {
1224 snprintf(cstr, 96, " --%-27s", tmp.c_str());
1226 snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' ');
1230 SGPropertyNode *desc = option[k]->getNode("description");
1232 msg += desc->getStringValue();
1234 for ( unsigned int l = 1;
1235 (desc = option[k]->getNode("description", l, false));
1238 snprintf(cstr, 96, "\n%32c%s", ' ',
1239 desc->getStringValue());
1247 SGPropertyNode *name = section[j]->getNode("name");
1248 if (!msg.empty() && name) {
1249 cout << endl << name->getStringValue() << ":" << endl;
1257 cout << "For a complete list of options use --help --verbose" << endl;
1261 // Show available aircraft types
1262 void fgShowAircraft(void) {
1263 SGPath path( globals->get_fg_root() );
1264 path.append("Aircraft");
1269 dirp = ulOpenDir(path.c_str());
1271 cout << "Unable to open aircraft directory." << endl;
1275 cout << "Available aircraft:" << endl;
1276 while ((dire = ulReadDir(dirp)) != NULL) {
1279 if ((ptr = strstr(dire->d_name, "-set.xml")) && ptr[8] == '\0' ) {
1280 SGPath afile = path;
1281 afile.append(dire->d_name);
1285 SGPropertyNode root;
1287 readProperties(afile.str(), &root);
1292 SGPropertyNode *desc, *node = root.getNode("sim");
1294 desc = node->getNode("description");
1297 if (strlen(dire->d_name) <= 27)
1298 snprintf(cstr, 96, " %-27s %s", dire->d_name,
1299 (desc) ? desc->getStringValue() : "" );
1302 snprintf(cstr, 96, " %-27s\n%32c%s", dire->d_name, ' ',
1303 (desc) ? desc->getStringValue() : "" );
1305 cout << cstr << endl;