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()
38 #include <simgear/misc/sgstream.hxx>
39 #include <simgear/misc/sg_path.hxx>
40 #include <simgear/route/route.hxx>
41 #include <simgear/route/waypoint.hxx>
43 // #include <Include/general.hxx>
44 // #include <Airports/simple.hxx>
45 // #include <Cockpit/cockpit.hxx>
46 // #include <FDM/flight.hxx>
47 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
49 # include <NetworkOLK/network.h>
54 #include "globals.hxx"
55 #include "fg_init.hxx"
56 #include "fg_props.hxx"
57 #include "options.hxx"
58 #include "viewmgr.hxx"
61 SG_USING_NAMESPACE(std);
64 #define NEW_DEFAULT_MODEL_HZ 120
74 atof( const string& str )
78 // -dw- if ::atof is called, then we get an infinite loop
79 return std::atof( str.c_str() );
81 return ::atof( str.c_str() );
86 atoi( const string& str )
89 // -dw- if ::atoi is called, then we get an infinite loop
90 return std::atoi( str.c_str() );
92 return ::atoi( str.c_str() );
98 * Set a few fail-safe default property values.
100 * These should all be set in $FG_ROOT/preferences.xml, but just
101 * in case, we provide some initial sane values here. This method
102 * should be invoked *before* reading any init files.
107 // set a possibly independent location for scenery data
108 char *envp = ::getenv( "FG_SCENERY" );
110 if ( envp != NULL ) {
111 // fg_root could be anywhere, so default to environmental
112 // variable $FG_ROOT if it is set.
113 globals->set_fg_scenery(envp);
115 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
116 globals->set_fg_scenery("");
118 // Position (deliberately out of range)
119 fgSetDouble("/position/longitude-deg", 9999.0);
120 fgSetDouble("/position/latitude-deg", 9999.0);
121 fgSetDouble("/position/altitude-ft", -9999.0);
124 fgSetDouble("/orientation/heading-deg", 270);
125 fgSetDouble("/orientation/roll-deg", 0);
126 fgSetDouble("/orientation/pitch-deg", 0.424);
129 fgSetString("/sim/startup/speed-set", "knots");
130 fgSetDouble("/velocities/uBody-fps", 0.0);
131 fgSetDouble("/velocities/vBody-fps", 0.0);
132 fgSetDouble("/velocities/wBody-fps", 0.0);
133 fgSetDouble("/velocities/speed-north-fps", 0.0);
134 fgSetDouble("/velocities/speed-east-fps", 0.0);
135 fgSetDouble("/velocities/speed-down-fps", 0.0);
136 fgSetDouble("/velocities/airspeed-kt", 0.0);
137 fgSetDouble("/velocities/mach", 0.0);
140 fgSetBool("/sim/startup/game-mode", false);
141 fgSetBool("/sim/startup/splash-screen", true);
142 fgSetBool("/sim/startup/intro-music", true);
143 // we want mouse-pointer to have an undefined value if nothing is
144 // specified so we can do the right thing for voodoo-1/2 cards.
145 // fgSetString("/sim/startup/mouse-pointer", "disabled");
146 fgSetString("/sim/control-mode", "joystick");
147 fgSetBool("/sim/auto-coordination", false);
149 fgSetString("/sim/startup/browser-app", "netscape");
151 fgSetString("/sim/startup/browser-app", "webrun.bat");
154 fgSetBool("/sim/hud/visibility", false);
155 fgSetBool("/sim/panel/visibility", true);
156 fgSetBool("/sim/sound/audible", true);
157 fgSetBool("/sim/hud/antialiased", false);
159 // Flight Model options
160 fgSetString("/sim/flight-model", "jsb");
161 fgSetString("/sim/aero", "c172");
162 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
163 fgSetInt("/sim/speed-up", 1);
164 fgSetBool("/sim/startup/trim", false);
165 fgSetBool("/sim/startup/onground", true);
168 fgSetString("/sim/rendering/fog", "nicest");
169 fgSetBool("/environment/clouds/status", true);
170 fgSetBool("/sim/startup/fullscreen", false);
171 fgSetBool("/sim/rendering/shading", true);
172 fgSetBool("/sim/rendering/skyblend", true);
173 fgSetBool("/sim/rendering/textures", true);
174 fgSetBool("/sim/rendering/wireframe", false);
175 fgSetInt("/sim/startup/xsize", 800);
176 fgSetInt("/sim/startup/ysize", 600);
177 fgSetInt("/sim/rendering/bits-per-pixel", 16);
178 fgSetString("/sim/view-mode", "pilot");
179 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
180 fgSetDouble("/environment/visibility-m", 20000);
183 fgSetString("/sim/startup/units", "feet");
184 fgSetString("/sim/hud/frame-stat-type", "tris");
187 fgSetInt("/sim/startup/time-offset", 0);
188 fgSetString("/sim/startup/time-offset-type", "system-offset");
189 fgSetLong("/sim/time/cur-time-override", 0);
191 fgSetBool("/sim/networking/network-olk", false);
192 fgSetString("/sim/networking/call-sign", "Johnny");
195 fgSetBool("/sim/freeze/master", false);
196 fgSetBool("/sim/freeze/position", false);
197 fgSetBool("/sim/freeze/clock", false);
198 fgSetBool("/sim/freeze/fuel", false);
203 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
204 double * speed, double * gust)
206 unsigned int pos = wind.find('@');
207 if (pos == string::npos)
209 string dir = wind.substr(0, pos);
210 string spd = wind.substr(pos+1);
212 if (pos == string::npos) {
213 *min_hdg = *max_hdg = atof(dir.c_str());
215 *min_hdg = atof(dir.substr(0,pos).c_str());
216 *max_hdg = atof(dir.substr(pos+1).c_str());
219 if (pos == string::npos) {
220 *speed = *gust = atof(spd.c_str());
222 *speed = atof(spd.substr(0,pos).c_str());
223 *gust = atof(spd.substr(pos+1).c_str());
228 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
230 parse_time(const string& time_in) {
231 char *time_str, num[256];
232 double hours, minutes, seconds;
237 time_str = (char *)time_in.c_str();
239 // printf("parse_time(): %s\n", time_str);
242 if ( strlen(time_str) ) {
243 if ( time_str[0] == '+' ) {
246 } else if ( time_str[0] == '-' ) {
251 // printf("sign = %d\n", sign);
254 if ( strlen(time_str) ) {
256 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
257 num[i] = time_str[0];
261 if ( time_str[0] == ':' ) {
266 // printf("hours = %.2lf\n", hours);
272 if ( strlen(time_str) ) {
274 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
275 num[i] = time_str[0];
279 if ( time_str[0] == ':' ) {
284 // printf("minutes = %.2lf\n", minutes);
286 result += minutes / 60.0;
290 if ( strlen(time_str) ) {
292 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
293 num[i] = time_str[0];
299 // printf("seconds = %.2lf\n", seconds);
301 result += seconds / 3600.0;
304 return(sign * result);
308 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
310 parse_date( const string& date)
313 char * date_str, num[256];
315 // initialize to zero
322 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
323 date_str = (char *)date.c_str();
325 if ( strlen(date_str) ) {
327 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
328 num[i] = date_str[0];
332 if ( date_str[0] == ':' ) {
336 gmt.tm_year = atoi(num) - 1900;
339 if ( strlen(date_str) ) {
341 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
342 num[i] = date_str[0];
346 if ( date_str[0] == ':' ) {
350 gmt.tm_mon = atoi(num) -1;
353 if ( strlen(date_str) ) {
355 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
356 num[i] = date_str[0];
360 if ( date_str[0] == ':' ) {
364 gmt.tm_mday = atoi(num);
367 if ( strlen(date_str) ) {
369 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
370 num[i] = date_str[0];
374 if ( date_str[0] == ':' ) {
378 gmt.tm_hour = atoi(num);
381 if ( strlen(date_str) ) {
383 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
384 num[i] = date_str[0];
388 if ( date_str[0] == ':' ) {
392 gmt.tm_min = atoi(num);
395 if ( strlen(date_str) ) {
397 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
398 num[i] = date_str[0];
402 if ( date_str[0] == ':' ) {
406 gmt.tm_sec = atoi(num);
408 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
409 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
410 //printf ("Date is %s\n", ctime(&theTime));
411 //printf ("in seconds that is %d\n", theTime);
417 // parse angle in the form of [+/-]ddd:mm:ss into degrees
419 parse_degree( const string& degree_str) {
420 double result = parse_time( degree_str );
422 // printf("Degree = %.4f\n", result);
428 // parse time offset string into seconds
430 parse_time_offset( const string& time_str) {
433 // printf("time offset = %s\n", time_str);
436 result = (int)rint(parse_time(time_str) * 3600.0);
438 result = (int)(parse_time(time_str) * 3600.0);
441 // printf("parse_time_offset(): %d\n", result);
447 // Parse --fov=x.xx type option
449 parse_fov( const string& arg ) {
450 double fov = atof(arg);
452 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
453 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
455 fgSetDouble("/sim/current-view/field-of-view", fov);
457 // printf("parse_fov(): result = %.4f\n", fov);
463 // Parse I/O channel option
465 // Format is "--protocol=medium,direction,hz,medium_options,..."
467 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
468 // medium = { serial, socket, file, etc. }
469 // direction = { in, out, bi }
470 // hz = number of times to process channel per second (floating
471 // point values are ok.
473 // Serial example "--nmea=serial,dir,hz,device,baud" where
475 // device = OS device name of serial line to be open()'ed
476 // baud = {300, 1200, 2400, ..., 230400}
478 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
480 // machine = machine name or ip address if client (leave empty if server)
481 // port = port, leave empty to let system choose
482 // style = tcp or udp
484 // File example "--garmin=file,dir,hz,filename" where
486 // filename = file system file name
489 add_channel( const string& type, const string& channel_str ) {
490 // cout << "Channel string = " << channel_str << endl;
492 globals->get_channel_options_list()->push_back( type + "," + channel_str );
498 // Parse --wp=ID[@alt]
500 parse_wp( const string& arg ) {
504 unsigned int pos = arg.find( "@" );
505 if ( pos != string::npos ) {
506 id = arg.substr( 0, pos );
507 alt_str = arg.substr( pos + 1 );
508 // cout << "id str = " << id << " alt str = " << alt_str << endl;
509 alt = atof( alt_str.c_str() );
510 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
511 alt *= SG_FEET_TO_METER;
518 if ( fgFindAirportID( id, &a ) ) {
519 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
520 globals->get_route()->add_waypoint( wp );
529 // Parse --flight-plan=[file]
531 parse_flightplan(const string& arg)
533 sg_gzifstream in(arg.c_str());
534 if ( !in.is_open() ) {
540 #if defined( macintosh )
541 getline( in, line, '\r' );
543 getline( in, line, '\n' );
546 // catch extraneous (DOS) line ending character
547 if ( line[line.length() - 1] < 32 ) {
548 line = line.substr( 0, line.length()-1 );
561 // Parse a single option
563 parse_option (const string& arg)
566 if ( (arg == "--help") || (arg == "-h") ) {
567 // help/usage request
568 return(FG_OPTIONS_HELP);
569 } else if ( arg == "--disable-game-mode") {
570 fgSetBool("/sim/startup/game-mode", false);
571 } else if ( arg == "--enable-game-mode" ) {
572 fgSetBool("/sim/startup/game-mode", true);
573 } else if ( arg == "--disable-splash-screen" ) {
574 fgSetBool("/sim/startup/splash-screen", false);
575 } else if ( arg == "--enable-splash-screen" ) {
576 fgSetBool("/sim/startup/splash-screen", true);
577 } else if ( arg == "--disable-intro-music" ) {
578 fgSetBool("/sim/startup/intro-music", false);
579 } else if ( arg == "--enable-intro-music" ) {
580 fgSetBool("/sim/startup/intro-music", true);
581 } else if ( arg == "--disable-mouse-pointer" ) {
582 fgSetString("/sim/startup/mouse-pointer", "disabled");
583 } else if ( arg == "--enable-mouse-pointer" ) {
584 fgSetString("/sim/startup/mouse-pointer", "enabled");
585 } else if ( arg == "--disable-freeze" ) {
586 fgSetBool("/sim/freeze/master", false);
587 } else if ( arg == "--enable-freeze" ) {
588 fgSetBool("/sim/freeze/master", true);
589 } else if ( arg == "--disable-fuel-freeze" ) {
590 fgSetBool("/sim/freeze/fuel", false);
591 } else if ( arg == "--enable-fuel-freeze" ) {
592 fgSetBool("/sim/freeze/fuel", true);
593 } else if ( arg == "--disable-clock-freeze" ) {
594 fgSetBool("/sim/freeze/clock", false);
595 } else if ( arg == "--enable-clock-freeze" ) {
596 fgSetBool("/sim/freeze/clock", true);
597 } else if ( arg == "--disable-anti-alias-hud" ) {
598 fgSetBool("/sim/hud/antialiased", false);
599 } else if ( arg == "--enable-anti-alias-hud" ) {
600 fgSetBool("/sim/hud/antialiased", true);
601 } else if ( arg.find( "--control=") == 0 ) {
602 fgSetString("/sim/control-mode", arg.substr(10).c_str());
603 } else if ( arg == "--disable-auto-coordination" ) {
604 fgSetBool("/sim/auto-coordination", false);
605 } else if ( arg == "--enable-auto-coordination" ) {
606 fgSetBool("/sim/auto-coordination", true);
607 } else if ( arg.find( "--browser-app=") == 0 ) {
608 fgSetString("/sim/startup/browser-app", arg.substr(14).c_str());
609 } else if ( arg == "--disable-hud" ) {
610 fgSetBool("/sim/hud/visibility", false);
611 } else if ( arg == "--enable-hud" ) {
612 fgSetBool("/sim/hud/visibility", true);
613 } else if ( arg == "--disable-panel" ) {
614 fgSetBool("/sim/panel/visibility", false);
615 } else if ( arg == "--enable-panel" ) {
616 fgSetBool("/sim/panel/visibility", true);
617 } else if ( arg == "--disable-sound" ) {
618 fgSetBool("/sim/sound/audible", false);
619 } else if ( arg == "--enable-sound" ) {
620 fgSetBool("/sim/sound/audible", true);
621 } else if ( arg.find( "--airport-id=") == 0 ) {
622 // NB: changed property name!!!
623 fgSetString("/sim/startup/airport-id", arg.substr(13).c_str());
624 } else if ( arg.find( "--offset-distance=") == 0 ) {
625 fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
626 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
627 fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17)));
628 } else if ( arg.find( "--lon=" ) == 0 ) {
629 fgSetDouble("/position/longitude-deg",
630 parse_degree(arg.substr(6)));
631 fgSetString("/sim/startup/airport-id", "");
632 } else if ( arg.find( "--lat=" ) == 0 ) {
633 fgSetDouble("/position/latitude-deg",
634 parse_degree(arg.substr(6)));
635 fgSetString("/sim/startup/airport-id", "");
636 } else if ( arg.find( "--altitude=" ) == 0 ) {
637 fgSetBool("/sim/startup/onground", false);
638 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
639 fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
641 fgSetDouble("/position/altitude-ft",
642 atof(arg.substr(11)) * SG_METER_TO_FEET);
643 } else if ( arg.find( "--uBody=" ) == 0 ) {
644 fgSetString("/sim/startup/speed-set", "UVW");
645 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
646 fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
648 fgSetDouble("/velocities/uBody-fps",
649 atof(arg.substr(8)) * SG_METER_TO_FEET);
650 } else if ( arg.find( "--vBody=" ) == 0 ) {
651 fgSetString("/sim/startup/speed-set", "UVW");
652 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
653 fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
655 fgSetDouble("/velocities/vBody-fps",
656 atof(arg.substr(8)) * SG_METER_TO_FEET);
657 } else if ( arg.find( "--wBody=" ) == 0 ) {
658 fgSetString("/sim/startup/speed-set", "UVW");
659 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
660 fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
662 fgSetDouble("/velocities/wBody-fps",
663 atof(arg.substr(8)) * SG_METER_TO_FEET);
664 } else if ( arg.find( "--vNorth=" ) == 0 ) {
665 fgSetString("/sim/startup/speed-set", "NED");
666 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
667 fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
669 fgSetDouble("/velocities/speed-north-fps",
670 atof(arg.substr(9)) * SG_METER_TO_FEET);
671 } else if ( arg.find( "--vEast=" ) == 0 ) {
672 fgSetString("/sim/startup/speed-set", "NED");
673 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
674 fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
676 fgSetDouble("/velocities/speed-east-fps",
677 atof(arg.substr(8)) * SG_METER_TO_FEET);
678 } else if ( arg.find( "--vDown=" ) == 0 ) {
679 fgSetString("/sim/startup/speed-set", "NED");
680 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
681 fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
683 fgSetDouble("/velocities/speed-down-fps",
684 atof(arg.substr(8)) * SG_METER_TO_FEET);
685 } else if ( arg.find( "--vc=" ) == 0) {
686 fgSetString("/sim/startup/speed-set", "knots");
687 fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
688 } else if ( arg.find( "--mach=" ) == 0) {
689 fgSetString("/sim/startup/speed-set", "mach");
690 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
691 } else if ( arg.find( "--heading=" ) == 0 ) {
692 fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
693 } else if ( arg.find( "--roll=" ) == 0 ) {
694 fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
695 } else if ( arg.find( "--pitch=" ) == 0 ) {
696 fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
697 } else if ( arg.find( "--glideslope=" ) == 0 ) {
698 fgSetDouble("/velocities/glideslope", atof(arg.substr(13))
699 *SG_DEGREES_TO_RADIANS);
700 } else if ( arg.find( "--roc=" ) == 0 ) {
701 fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
702 } else if ( arg.find( "--fg-root=" ) == 0 ) {
703 globals->set_fg_root(arg.substr( 10 ));
704 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
705 globals->set_fg_scenery(arg.substr( 13 ));
706 } else if ( arg.find( "--fdm=" ) == 0 ) {
707 fgSetString("/sim/flight-model", arg.substr(6).c_str());
708 } else if ( arg.find( "--aero=" ) == 0 ) {
709 fgSetString("/sim/aero", arg.substr(7).c_str());
710 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
711 fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
712 } else if ( arg.find( "--model-hz=" ) == 0 ) {
713 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
714 } else if ( arg.find( "--speed=" ) == 0 ) {
715 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
716 } else if ( arg.find( "--trim") == 0) {
717 fgSetBool("/sim/startup/trim", true);
718 } else if ( arg.find( "--notrim") == 0) {
719 fgSetBool("/sim/startup/trim", false);
720 } else if ( arg.find( "--on-ground") == 0) {
721 fgSetBool("/sim/startup/onground", true);
722 } else if ( arg.find( "--in-air") == 0) {
723 fgSetBool("/sim/startup/onground", false);
724 } else if ( arg == "--fog-disable" ) {
725 fgSetString("/sim/rendering/fog", "disabled");
726 } else if ( arg == "--fog-fastest" ) {
727 fgSetString("/sim/rendering/fog", "fastest");
728 } else if ( arg == "--fog-nicest" ) {
729 fgSetString("/sim/fog", "nicest");
730 } else if ( arg == "--disable-clouds" ) {
731 fgSetBool("/environment/clouds/status", false);
732 } else if ( arg == "--enable-clouds" ) {
733 fgSetBool("/environment/clouds/status", true);
734 } else if ( arg.find( "--fov=" ) == 0 ) {
735 parse_fov( arg.substr(6) );
736 } else if ( arg == "--disable-fullscreen" ) {
737 fgSetBool("/sim/startup/fullscreen", false);
738 } else if ( arg== "--enable-fullscreen") {
739 fgSetBool("/sim/startup/fullscreen", true);
740 } else if ( arg == "--shading-flat") {
741 fgSetBool("/sim/rendering/shading", false);
742 } else if ( arg == "--shading-smooth") {
743 fgSetBool("/sim/rendering/shading", true);
744 } else if ( arg == "--disable-skyblend") {
745 fgSetBool("/sim/rendering/skyblend", false);
746 } else if ( arg== "--enable-skyblend" ) {
747 fgSetBool("/sim/rendering/skyblend", true);
748 } else if ( arg == "--disable-textures" ) {
749 fgSetBool("/sim/rendering/textures", false);
750 } else if ( arg == "--enable-textures" ) {
751 fgSetBool("/sim/rendering/textures", true);
752 } else if ( arg == "--disable-wireframe" ) {
753 fgSetBool("/sim/rendering/wireframe", false);
754 } else if ( arg == "--enable-wireframe" ) {
755 fgSetBool("/sim/rendering/wireframe", true);
756 } else if ( arg.find( "--geometry=" ) == 0 ) {
757 bool geometry_ok = true;
758 int xsize = 0, ysize = 0;
759 string geometry = arg.substr( 11 );
760 string::size_type i = geometry.find('x');
762 if (i != string::npos) {
763 xsize = atoi(geometry.substr(0, i));
764 ysize = atoi(geometry.substr(i+1));
769 if ( xsize <= 0 || ysize <= 0 ) {
775 if ( !geometry_ok ) {
776 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
777 SG_LOG( SG_GENERAL, SG_ALERT,
778 "Setting geometry to " << xsize << 'x' << ysize << '\n');
780 SG_LOG( SG_GENERAL, SG_INFO,
781 "Setting geometry to " << xsize << 'x' << ysize << '\n');
782 fgSetInt("/sim/startup/xsize", xsize);
783 fgSetInt("/sim/startup/ysize", ysize);
785 } else if ( arg.find( "--bpp=" ) == 0 ) {
786 string bits_per_pix = arg.substr( 6 );
787 if ( bits_per_pix == "16" ) {
788 fgSetInt("/sim/rendering/bits-per-pixel", 16);
789 } else if ( bits_per_pix == "24" ) {
790 fgSetInt("/sim/rendering/bits-per-pixel", 24);
791 } else if ( bits_per_pix == "32" ) {
792 fgSetInt("/sim/rendering/bits-per-pixel", 32);
794 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
796 } else if ( arg == "--units-feet" ) {
797 fgSetString("/sim/startup/units", "feet");
798 } else if ( arg == "--units-meters" ) {
799 fgSetString("/sim/startup/units", "meters");
800 } else if ( arg.find( "--time-offset" ) == 0 ) {
801 fgSetInt("/sim/startup/time-offset",
802 parse_time_offset( (arg.substr(14)) ));
803 fgSetString("/sim/startup/time-offset-type", "system-offset");
804 } else if ( arg.find( "--time-match-real") == 0 ) {
805 fgSetString("/sim/startup/time-offset-type", "system-offset");
806 } else if ( arg.find( "--time-match-local") == 0 ) {
807 fgSetString("/sim/startup/time-offset-type", "latitude-offset");
808 } else if ( arg.find( "--start-date-sys=") == 0 ) {
809 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
810 fgSetString("/sim/startup/time-offset-type", "system");
811 } else if ( arg.find( "--start-date-lat=") == 0 ) {
812 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
813 fgSetString("/sim/startup/time-offset-type", "latitude");
814 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
815 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
816 fgSetString("/sim/startup/time-offset-type", "gmt");
817 } else if ( arg == "--hud-tris" ) {
818 fgSetString("/sim/hud/frame-stat-type", "tris");
819 } else if ( arg == "--hud-culled" ) {
820 fgSetString("/sim/hud/frame-stat-type", "culled");
821 } else if ( arg.find( "--atc610x" ) == 0 ) {
822 add_channel( "atc610x", "dummy" );
823 } else if ( arg.find( "--atlas=" ) == 0 ) {
824 add_channel( "atlas", arg.substr(8) );
825 } else if ( arg.find( "--httpd=" ) == 0 ) {
826 add_channel( "httpd", arg.substr(8) );
827 #ifdef FG_JPEG_SERVER
828 } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
829 add_channel( "jpg-httpd", arg.substr(12) );
831 } else if ( arg.find( "--native=" ) == 0 ) {
832 add_channel( "native", arg.substr(9) );
833 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
834 add_channel( "native_ctrls", arg.substr(15) );
835 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
836 add_channel( "native_fdm", arg.substr(13) );
837 } else if ( arg.find( "--opengc=" ) == 0 ) {
839 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
840 add_channel( "opengc", arg.substr(9) );
841 } else if ( arg.find( "--garmin=" ) == 0 ) {
842 add_channel( "garmin", arg.substr(9) );
843 } else if ( arg.find( "--nmea=" ) == 0 ) {
844 add_channel( "nmea", arg.substr(7) );
845 } else if ( arg.find( "--props=" ) == 0 ) {
846 add_channel( "props", arg.substr(8) );
847 } else if ( arg.find( "--telnet=" ) == 0 ) {
848 add_channel( "telnet", arg.substr(9) );
849 } else if ( arg.find( "--pve=" ) == 0 ) {
850 add_channel( "pve", arg.substr(6) );
851 } else if ( arg.find( "--ray=" ) == 0 ) {
852 add_channel( "ray", arg.substr(6) );
853 } else if ( arg.find( "--rul=" ) == 0 ) {
854 add_channel( "rul", arg.substr(6) );
855 } else if ( arg.find( "--joyclient=" ) == 0 ) {
856 add_channel( "joyclient", arg.substr(12) );
857 #ifdef FG_NETWORK_OLK
858 } else if ( arg == "--disable-network-olk" ) {
859 fgSetBool("/sim/networking/olk", false);
860 } else if ( arg== "--enable-network-olk") {
861 fgSetBool("/sim/networking/olk", true);
862 } else if ( arg == "--net-hud" ) {
863 fgSetBool("/sim/hud/net-display", true);
864 net_hud_display = 1; // FIXME
865 } else if ( arg.find( "--net-id=") == 0 ) {
866 fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
868 } else if ( arg.find( "--prop:" ) == 0 ) {
869 string assign = arg.substr(7);
870 unsigned int pos = assign.find('=');
871 if ( pos == arg.npos || pos == 0 ) {
872 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
873 return FG_OPTIONS_ERROR;
875 string name = assign.substr(0, pos);
876 string value = assign.substr(pos + 1);
877 fgSetString(name.c_str(), value.c_str());
878 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
879 // << name << " to \"" << value << '"');
880 } else if ( arg.find("--trace-read=") == 0) {
881 string name = arg.substr(13);
882 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
883 fgGetNode(name.c_str(), true)
884 ->setAttribute(SGPropertyNode::TRACE_READ, true);
885 } else if ( arg.find("--trace-write=") == 0) {
886 string name = arg.substr(14);
887 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
888 fgGetNode(name.c_str(), true)
889 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
890 } else if ( arg.find( "--view-offset=" ) == 0 ) {
891 // $$$ begin - added VS Renganathan, 14 Oct 2K
892 // for multi-window outside window imagery
893 string woffset = arg.substr( 14 );
894 double default_view_offset = 0.0;
895 if ( woffset == "LEFT" ) {
896 default_view_offset = SGD_PI * 0.25;
897 } else if ( woffset == "RIGHT" ) {
898 default_view_offset = SGD_PI * 1.75;
899 } else if ( woffset == "CENTER" ) {
900 default_view_offset = 0.00;
902 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
904 FGViewer *pilot_view =
905 (FGViewer *)globals->get_viewmgr()->get_view( 0 );
906 // this will work without calls to the viewer...
907 fgSetDouble( "/sim/current-view/heading-offset-deg",
908 default_view_offset * SGD_RADIANS_TO_DEGREES );
909 // $$$ end - added VS Renganathan, 14 Oct 2K
910 } else if ( arg.find( "--visibility=" ) == 0 ) {
911 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
912 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
913 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
914 fgSetDouble("/environment/visibility-m", visibility);
915 } else if ( arg.find( "--wind=" ) == 0 ) {
916 double min_hdg, max_hdg, speed, gust;
917 if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
918 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
919 return FG_OPTIONS_ERROR;
921 fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
922 fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
923 fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
924 fgSetDouble("/environment/wind-speed-kt", speed);
925 fgSetDouble("/environment/params/base-wind-speed-kt", speed);
926 fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
928 string val = arg.substr(7);
929 unsigned int pos = val.find('@');
930 if ( pos == string::npos ) {
931 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << val );
932 return FG_OPTIONS_ERROR;
934 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
935 speed << " knots" << endl);
939 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
940 while (min_hdg > 360)
944 min_hdg *= SGD_DEGREES_TO_RADIANS;
945 fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
946 fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
947 #endif // FG_WEATHERCM
949 } else if ( arg.find( "--wp=" ) == 0 ) {
950 parse_wp( arg.substr( 5 ) );
951 } else if ( arg.find( "--flight-plan=") == 0) {
952 parse_flightplan ( arg.substr (14) );
953 } else if ( arg.find( "--config=" ) == 0 ) {
954 string file = arg.substr(9);
956 readProperties(file, globals->get_props());
957 } catch (const sg_exception &e) {
958 string message = "Error loading config file: ";
959 message += e.getFormattedMessage();
960 SG_LOG(SG_INPUT, SG_ALERT, message);
963 } else if ( arg.find( "--aircraft=" ) == 0 ) {
964 // read in the top level aircraft definition file
965 SGPath apath( globals->get_fg_root() );
966 apath.append( "Aircraft" );
967 apath.append( arg.substr(11) );
968 apath.concat( "-set.xml" );
969 SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11)
970 << " from " << apath.str());
971 readProperties( apath.str(), globals->get_props() );
973 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
974 return FG_OPTIONS_ERROR;
977 return FG_OPTIONS_OK;
981 // Scan the command line options for an fg_root definition and set
984 fgScanForRoot (int argc, char **argv)
988 SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
991 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
993 string arg = argv[i];
994 if ( arg.find( "--fg-root=" ) == 0 ) {
995 return arg.substr( 10 );
1005 // Scan the config file for an fg_root definition and set just that.
1007 fgScanForRoot (const string& path)
1009 sg_gzifstream in( path );
1010 if ( !in.is_open() )
1013 SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
1017 while ( ! in.eof() ) {
1020 while ( in.get(c) && c != '\0' ) {
1025 #if defined( macintosh )
1026 getline( in, line, '\r' );
1028 getline( in, line, '\n' );
1031 // catch extraneous (DOS) line ending character
1032 if ( line[line.length() - 1] < 32 ) {
1033 line = line.substr( 0, line.length()-1 );
1036 if ( line.find( "--fg-root=" ) == 0 ) {
1037 return line.substr( 10 );
1047 // Parse the command line options
1049 fgParseArgs (int argc, char **argv)
1051 bool in_options = true;
1053 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1055 for (int i = 1; i < argc; i++) {
1056 string arg = argv[i];
1058 if (in_options && (arg.find('-') == 0)) {
1062 int result = parse_option(arg);
1063 if ( (result == FG_OPTIONS_HELP) ||
1064 (result == FG_OPTIONS_ERROR) ) {
1071 SG_LOG(SG_GENERAL, SG_INFO,
1072 "Reading command-line property file " << arg);
1073 readProperties(arg, globals->get_props());
1077 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1081 // Parse config file options
1083 fgParseOptions (const string& path) {
1084 sg_gzifstream in( path );
1085 if ( !in.is_open() ) {
1089 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1093 while ( ! in.eof() ) {
1096 while ( in.get(c) && c != '\0' ) {
1101 #if defined( macintosh )
1102 getline( in, line, '\r' );
1104 getline( in, line, '\n' );
1107 // catch extraneous (DOS) line ending character
1108 if ( line[line.length() - 1] < 32 ) {
1109 line = line.substr( 0, line.length()-1 );
1112 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1113 SG_LOG( SG_GENERAL, SG_ALERT,
1114 "Config file parse error: " << path << " '"
1124 // Print usage message
1128 cout << "Usage: fgfs [ option ... ]" << endl
1131 << "General Options:" << endl
1132 << " --help, -h Print usage" << endl
1133 << " --fg-root=path Specify the root data path" << endl
1134 << " --fg-scenery=path Specify the base scenery path;" << endl
1135 << " Defaults to $FG_ROOT/Scenery" << endl
1136 << " --disable-game-mode Disable full-screen game mode" << endl
1137 << " --enable-game-mode Enable full-screen game mode" << endl
1138 << " --disable-splash-screen Disable splash screen" << endl
1139 << " --enable-splash-screen Enable splash screen" << endl
1140 << " --disable-intro-music Disable introduction music" << endl
1141 << " --enable-intro-music Enable introduction music" << endl
1142 << " --disable-mouse-pointer Disable extra mouse pointer" << endl
1143 << " --enable-mouse-pointer Enable extra mouse pointer (i.e. for full-" << endl
1144 << " screen Voodoo based cards)" << endl
1145 << " --disable-freeze Start in a running state" << endl
1146 << " --enable-freeze Start in a frozen state" << endl
1147 << " --disable-fuel-freeze Fuel is consumed normally" << endl
1148 << " --enable-fuel-freeze Fuel tank quantity forced to remain constant" << endl
1149 << " --disable-clock-freeze Clock advances normally" << endl
1150 << " --enable-clock-freeze Do not advance clock" << endl
1151 << " --control=mode Primary control mode (joystick, keyboard," << endl
1152 << " mouse)" << endl
1153 << " --enable-auto-coordination Enable auto coordination" << endl
1154 << " --disable-auto-coordination Disable auto coordination" << endl
1155 << " --browser-app=path Specify path to your web browser" << endl
1156 << " --prop:name=value Set property <name> to <value>" << endl
1157 << " --config=path Load additional properties from path" << endl
1158 << " --units-feet Use feet for distances" << endl
1159 << " --units-meters Use meters for distances" << endl
1162 << "Features:" << endl
1163 << " --disable-hud Disable Heads Up Display (HUD)" << endl
1164 << " --enable-hud Enable Heads Up Display (HUD)" << endl
1165 << " --disable-panel Disable instrument panel" << endl
1166 << " --enable-panel Enable instrument panel" << endl
1167 << " --disable-sound Disable sound effects" << endl
1168 << " --enable-sound Enable sound effects" << endl
1169 << " --disable-anti-alias-hud Disable anti-aliased HUD" << endl
1170 << " --enable-anti-alias-hud Enable anti-aliased HUD" << endl
1173 << "Aircraft:" <<endl
1174 << " --aircraft=name Select an aircraft profile as defined by a" << endl
1175 << " top level <name>-set.xml" << endl
1178 << "Flight Model:" << endl
1179 << " --fdm=name Select the core flight dynamics model" << endl
1180 << " Can be one of jsb, larcsim, yasim, magic," << endl
1181 << " balloon, ada, external, or null" << endl
1182 << " --aero=name Select aircraft aerodynamics model to load" << endl
1183 << " --model-hz=n Run the FDM this rate (iterations per" << endl
1184 << " second)" << endl
1185 << " --speed=n Run the FDM 'n' times faster than real time" << endl
1186 << " --notrim Do NOT attempt to trim the model (only with" << endl
1187 << " fdm=jsbsim)" << endl
1188 << " --on-ground Start at ground level (default)" << endl
1189 << " --in-air Start in air (implied when using --altitude)" << endl
1190 << " --wind=DIR@SPEED Specify wind coming from DIR (degrees) at" << endl
1191 << " SPEED (knots); both DIR and SPEED can" << endl
1192 << " optionally contain a colon-separated range." << endl
1195 << "Aircraft model directory (UIUC FDM ONLY):" << endl
1196 << " --aircraft-dir=path Aircraft directory relative to the path of" << endl
1197 << " the executable" << endl
1200 << "Initial Position and Orientation:" << endl
1201 << " --airport-id=ID Specify starting position by airport ID" << endl
1202 << " --offset-distance=nm Specify distance to threshold" << endl
1203 << " --offset-azimuth=degrees Specify heading to threshold" << endl
1204 << " --lon=degrees Starting longitude (west = -)" << endl
1205 << " --lat=degrees Starting latitude (south = -)" << endl
1206 << " --altitude=value Starting altitude (in feet unless" << endl
1207 << " --units-meters specified)" << endl
1208 << " --heading=degrees Specify heading (yaw) angle (Psi)" << endl
1209 << " --roll=degrees Specify roll angle (Phi)" << endl
1210 << " --pitch=degrees Specify pitch angle (Theta)" << endl
1211 << " --uBody=units_per_sec Specify velocity along the body X axis" << endl
1212 << " (in feet unless --units-meters specified)" << endl
1213 << " --vBody=units_per_sec Specify velocity along the body Y axis" << endl
1214 << " (in feet unless --units-meters specified)" << endl
1215 << " --wBody=units_per_sec Specify velocity along the body Z axis" << endl
1216 << " (in feet unless --units-meters specified)" << endl
1217 << " --vc=knots Specify initial airspeed" << endl
1218 << " --mach=num Specify initial mach number" << endl
1219 << " --glideslope=degreees Specify flight path angle (can be positive)" << endl
1220 << " --roc=fpm Specify initial climb rate (can be negative)" << endl
1223 << "Rendering Options:" << endl
1224 << " --bpp=depth Specify the bits per pixel" << endl
1225 << " --fog-disable Disable fog/haze" << endl
1226 << " --fog-fastest Enable fastest fog/haze" << endl
1227 << " --fog-nicest Enable nicest fog/haze" << endl
1228 << " --enable-clouds Enable cloud layers" << endl
1229 << " --disable-clouds Disable cloud layers" << endl
1231 << " --fov=degrees Specify field of view angle" << endl
1232 << " --disable-fullscreen Disable fullscreen mode" << endl
1233 << " --enable-fullscreen Enable fullscreen mode" << endl
1234 << " --shading-flat Enable flat shading" << endl
1235 << " --shading-smooth Enable smooth shading" << endl
1236 << " --disable-skyblend Disable sky blending" << endl
1237 << " --enable-skyblend Enable sky blending" << endl
1238 << " --disable-textures Disable textures" << endl
1239 << " --enable-textures Enable textures" << endl
1240 << " --disable-wireframe Disable wireframe drawing mode" << endl
1241 << " --enable-wireframe Enable wireframe drawing mode" << endl
1242 << " --geometry=WxH Specify window geometry (640x480, etc)" << endl
1243 << " --view-offset=value Specify the default forward view direction" << endl
1244 << " as an offset from straight ahead. Allowable" << endl
1245 << " values are LEFT, RIGHT, CENTER, or a specific" << endl
1246 << " number in degrees" << endl
1247 << " --visibility=meters Specify initial visibility" << endl
1248 << " --visibility-miles=miles Specify initial visibility in miles" << endl
1251 << "Hud Options:" << endl
1252 << " --hud-tris Hud displays number of triangles rendered" << endl
1253 << " --hud-culled Hud displays percentage of triangles culled" << endl
1256 << "Time Options:" << endl
1257 << " --time-offset=[+-]hh:mm:ss Add this time offset" << endl
1258 << " --time-match-real Synchronize time with real-world time" << endl
1259 << " --time-match-local Synchronize time with local real-world time" << endl
1260 << " --start-date-sys=yyyy:mm:dd:hh:mm:ss" << endl
1261 << " Specify a starting date/time with respect to" << endl
1262 << " system time" << endl
1263 << " --start-date-gmt=yyyy:mm:dd:hh:mm:ss" << endl
1264 << " Specify a starting date/time with respect to" << endl
1265 << " Greenwich Mean Time" << endl
1266 << " --start-date-lat=yyyy:mm:dd:hh:mm:ss" << endl
1267 << " Specify a starting date/time with respect to" << endl
1268 << " Local Aircraft Time" << endl
1271 << "Network Options:" << endl
1272 << " --httpd=port Enable http server on the specified port" << endl
1273 << " --telnet=port Enable telnet server on the specified port" << endl
1274 #ifdef FG_JPEG_SERVER
1275 << " --jpg-httpd=port Enable screen shot http server on the" << endl
1276 << " specified port" << endl
1278 #ifdef FG_NETWORK_OLK
1279 << " --disable-network-olk Disable Multipilot mode (default)" << endl
1280 << " --enable-network-olk Enable Multipilot mode" << endl
1281 << " --net-hud Hud displays network info" << endl
1282 << " --net-id=name Specify your own callsign" << endl
1286 << "Route/Way Point Options:" << endl
1287 << " --wp=ID[@alt] Specify a waypoint for the GC autopilot;" << endl
1288 << " multiple instances can be used to create a" << endl
1290 << " --flight-plan=file Read all waypoints from a file" << endl
1293 << "IO Options:" << endl
1294 << " --gamin=params Open connection using the Garmin GPS protocol" << endl
1295 << " --joyclient=params Open connection to an Agwagon joystick" << endl
1296 << " --native-ctrls=params Open connection using the FG Native Controls" << endl
1297 << " protocol" << endl
1298 << " --native-fdm=params Open connection using the FG Native FDM" << endl
1299 << " protocol" << endl
1300 << " --native=params Open connection using the FG Native protocol" << endl
1301 << " --nmea=params Open connection using the NMEA protocol" << endl
1302 << " --opengc=params Open connection using the OpenGC protocol" << endl
1303 << " --props=params Open connection using the interactive" << endl
1304 << " property manager" << endl
1305 << " --pve=params Open connection using the PVE protocol" << endl
1306 << " --ray=params Open connection using the RayWoodworth" << endl
1307 << " motion chair protocol" << endl
1308 << " --rul=params Open connection using the RUL protocol" << endl
1310 << " --atc610x Enable atc610x interface." << endl
1313 << "Debugging Options:" << endl
1314 << " --trace-read=property Trace the reads for a property; multiple" << endl
1315 << " instances allowed." << endl
1316 << " --trace-write=property Trace the writes for a property; multiple" << endl
1317 << " instances allowed." << endl