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>
32 #if defined(FX) && defined(XMESA)
33 bool global_fullscreen = true;
36 #include <math.h> // rint()
38 #include <stdlib.h> // atof(), atoi()
43 #include <simgear/misc/sgstream.hxx>
45 // #include <Include/general.hxx>
46 // #include <Airports/simple.hxx>
47 // #include <Cockpit/cockpit.hxx>
48 // #include <FDM/flight.hxx>
49 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
51 # include <NetworkOLK/network.h>
56 #include "globals.hxx"
57 #include "fg_init.hxx"
58 #include "fg_props.hxx"
59 #include "options.hxx"
60 #include "viewmgr.hxx"
63 SG_USING_NAMESPACE(std);
66 #define NEW_DEFAULT_MODEL_HZ 120
76 atof( const string& str )
80 // -dw- if ::atof is called, then we get an infinite loop
81 return std::atof( str.c_str() );
83 return ::atof( str.c_str() );
88 atoi( const string& str )
91 // -dw- if ::atoi is called, then we get an infinite loop
92 return std::atoi( str.c_str() );
94 return ::atoi( str.c_str() );
100 * Set a few fail-safe default property values.
102 * These should all be set in $FG_ROOT/preferences.xml, but just
103 * in case, we provide some initial sane values here. This method
104 * should be invoked *before* reading any init files.
109 // set a possibly independent location for scenery data
110 char *envp = ::getenv( "FG_SCENERY" );
112 if ( envp != NULL ) {
113 // fg_root could be anywhere, so default to environmental
114 // variable $FG_ROOT if it is set.
115 globals->set_fg_scenery(envp);
117 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
118 globals->set_fg_scenery("");
120 // Position (Globe, AZ)
121 fgSetDouble("/position/longitude-deg", -110.6642444);
122 fgSetDouble("/position/latitude-deg", 33.3528917);
123 fgSetDouble("/position/altitude-ft", -9999.0);
126 fgSetDouble("/orientation/heading-deg", 270);
127 fgSetDouble("/orientation/roll-deg", 0);
128 fgSetDouble("/orientation/pitch-deg", 0.424);
131 fgSetString("/sim/startup/speed-set", "knots");
132 fgSetDouble("/velocities/uBody-fps", 0.0);
133 fgSetDouble("/velocities/vBody-fps", 0.0);
134 fgSetDouble("/velocities/wBody-fps", 0.0);
135 fgSetDouble("/velocities/speed-north-fps", 0.0);
136 fgSetDouble("/velocities/speed-east-fps", 0.0);
137 fgSetDouble("/velocities/speed-down-fps", 0.0);
138 fgSetDouble("/velocities/airspeed-kt", 0.0);
139 fgSetDouble("/velocities/mach", 0.0);
142 fgSetBool("/sim/startup/game-mode", false);
143 fgSetBool("/sim/startup/splash-screen", true);
144 fgSetBool("/sim/startup/intro-music", true);
145 // we want mouse-pointer to have an undefined value if nothing is
146 // specified so we can do the right thing for voodoo-1/2 cards.
147 // fgSetString("/sim/startup/mouse-pointer", "disabled");
148 fgSetString("/sim/control-mode", "joystick");
149 fgSetBool("/sim/auto-coordination", false);
151 fgSetString("/sim/startup/browser-app", "netscape");
153 fgSetString("/sim/startup/browser-app", "webrun.bat");
156 fgSetBool("/sim/hud/visibility", false);
157 fgSetBool("/sim/panel/visibility", true);
158 fgSetBool("/sim/sound", true);
159 fgSetBool("/sim/hud/antialiased", false);
161 // Flight Model options
162 fgSetString("/sim/flight-model", "jsb");
163 fgSetString("/sim/aero", "c172");
164 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
165 fgSetInt("/sim/speed-up", 1);
166 fgSetBool("/sim/startup/trim", false);
167 fgSetBool("/sim/startup/onground", true);
170 fgSetString("/sim/rendering/fog", "nicest");
171 fgSetBool("/environment/clouds/status", true);
172 fgSetDouble("/environment/clouds/altitude-ft", 5000);
173 fgSetBool("/sim/startup/fullscreen", false);
174 fgSetBool("/sim/rendering/shading", true);
175 fgSetBool("/sim/rendering/skyblend", true);
176 fgSetBool("/sim/rendering/textures", true);
177 fgSetBool("/sim/rendering/wireframe", false);
178 fgSetInt("/sim/startup/xsize", 800);
179 fgSetInt("/sim/startup/ysize", 600);
180 fgSetInt("/sim/rendering/bits-per-pixel", 16);
181 fgSetString("/sim/view-mode", "pilot");
182 fgSetDouble("/sim/view/offset-deg", 0);
183 fgSetDouble("/environment/visibility-m", 20000);
186 fgSetString("/sim/startup/units", "feet");
187 fgSetString("/sim/hud/frame-stat-type", "tris");
190 fgSetInt("/sim/startup/time-offset", 0);
191 fgSetString("/sim/startup/time-offset-type", "system-offset");
193 fgSetBool("/sim/networking/network-olk", false);
194 fgSetString("/sim/networking/call-sign", "Johnny");
198 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
200 parse_time(const string& time_in) {
201 char *time_str, num[256];
202 double hours, minutes, seconds;
207 time_str = (char *)time_in.c_str();
209 // printf("parse_time(): %s\n", time_str);
212 if ( strlen(time_str) ) {
213 if ( time_str[0] == '+' ) {
216 } else if ( time_str[0] == '-' ) {
221 // printf("sign = %d\n", sign);
224 if ( strlen(time_str) ) {
226 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
227 num[i] = time_str[0];
231 if ( time_str[0] == ':' ) {
236 // printf("hours = %.2lf\n", hours);
242 if ( strlen(time_str) ) {
244 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
245 num[i] = time_str[0];
249 if ( time_str[0] == ':' ) {
254 // printf("minutes = %.2lf\n", minutes);
256 result += minutes / 60.0;
260 if ( strlen(time_str) ) {
262 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
263 num[i] = time_str[0];
269 // printf("seconds = %.2lf\n", seconds);
271 result += seconds / 3600.0;
274 return(sign * result);
278 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
280 parse_date( const string& date)
283 char * date_str, num[256];
285 // initialize to zero
292 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
293 date_str = (char *)date.c_str();
295 if ( strlen(date_str) ) {
297 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
298 num[i] = date_str[0];
302 if ( date_str[0] == ':' ) {
306 gmt.tm_year = atoi(num) - 1900;
309 if ( strlen(date_str) ) {
311 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
312 num[i] = date_str[0];
316 if ( date_str[0] == ':' ) {
320 gmt.tm_mon = atoi(num) -1;
323 if ( strlen(date_str) ) {
325 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
326 num[i] = date_str[0];
330 if ( date_str[0] == ':' ) {
334 gmt.tm_mday = atoi(num);
337 if ( strlen(date_str) ) {
339 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
340 num[i] = date_str[0];
344 if ( date_str[0] == ':' ) {
348 gmt.tm_hour = atoi(num);
351 if ( strlen(date_str) ) {
353 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
354 num[i] = date_str[0];
358 if ( date_str[0] == ':' ) {
362 gmt.tm_min = atoi(num);
365 if ( strlen(date_str) ) {
367 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
368 num[i] = date_str[0];
372 if ( date_str[0] == ':' ) {
376 gmt.tm_sec = atoi(num);
378 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
379 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
380 //printf ("Date is %s\n", ctime(&theTime));
381 //printf ("in seconds that is %d\n", theTime);
387 // parse angle in the form of [+/-]ddd:mm:ss into degrees
389 parse_degree( const string& degree_str) {
390 double result = parse_time( degree_str );
392 // printf("Degree = %.4f\n", result);
398 // parse time offset string into seconds
400 parse_time_offset( const string& time_str) {
403 // printf("time offset = %s\n", time_str);
406 result = (int)rint(parse_time(time_str) * 3600.0);
408 result = (int)(parse_time(time_str) * 3600.0);
411 // printf("parse_time_offset(): %d\n", result);
417 // Parse --fov=x.xx type option
419 parse_fov( const string& arg ) {
420 double fov = atof(arg);
422 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
423 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
425 fgSetDouble("/sim/field-of-view", fov);
427 // printf("parse_fov(): result = %.4f\n", fov);
433 // Parse I/O channel option
435 // Format is "--protocol=medium,direction,hz,medium_options,..."
437 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
438 // medium = { serial, socket, file, etc. }
439 // direction = { in, out, bi }
440 // hz = number of times to process channel per second (floating
441 // point values are ok.
443 // Serial example "--nmea=serial,dir,hz,device,baud" where
445 // device = OS device name of serial line to be open()'ed
446 // baud = {300, 1200, 2400, ..., 230400}
448 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
450 // machine = machine name or ip address if client (leave empty if server)
451 // port = port, leave empty to let system choose
452 // style = tcp or udp
454 // File example "--garmin=file,dir,hz,filename" where
456 // filename = file system file name
459 add_channel( const string& type, const string& channel_str ) {
460 // cout << "Channel string = " << channel_str << endl;
462 globals->get_channel_options_list()->push_back( type + "," + channel_str );
468 // Parse --wp=ID[@alt]
470 parse_wp( const string& arg ) {
474 unsigned int pos = arg.find( "@" );
475 if ( pos != string::npos ) {
476 id = arg.substr( 0, pos );
477 alt_str = arg.substr( pos + 1 );
478 // cout << "id str = " << id << " alt str = " << alt_str << endl;
479 alt = atof( alt_str.c_str() );
480 if ( fgGetString("/sim/startup/units") == "feet" ) {
481 alt *= SG_FEET_TO_METER;
488 if ( fgFindAirportID( id, &a ) ) {
489 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
490 globals->get_route()->add_waypoint( wp );
499 // Parse --flight-plan=[file]
501 parse_flightplan(const string& arg)
503 sg_gzifstream in(arg.c_str());
504 if ( !in.is_open() ) {
510 #if defined( macintosh )
511 getline( in, line, '\r' );
513 getline( in, line, '\n' );
516 // catch extraneous (DOS) line ending character
517 if ( line[line.length() - 1] < 32 ) {
518 line = line.substr( 0, line.length()-1 );
531 // Parse a single option
533 parse_option (const string& arg)
536 if ( (arg == "--help") || (arg == "-h") ) {
537 // help/usage request
538 return(FG_OPTIONS_HELP);
539 } else if ( arg == "--disable-game-mode") {
540 fgSetBool("/sim/startup/game-mode", false);
541 } else if ( arg == "--enable-game-mode" ) {
542 fgSetBool("/sim/startup/game-mode", true);
543 } else if ( arg == "--disable-splash-screen" ) {
544 fgSetBool("/sim/startup/splash-screen", false);
545 } else if ( arg == "--enable-splash-screen" ) {
546 fgSetBool("/sim/startup/splash-screen", true);
547 } else if ( arg == "--disable-intro-music" ) {
548 fgSetBool("/sim/startup/intro-music", false);
549 } else if ( arg == "--enable-intro-music" ) {
550 fgSetBool("/sim/startup/intro-music", true);
551 } else if ( arg == "--disable-mouse-pointer" ) {
552 fgSetString("/sim/startup/mouse-pointer", "disabled");
553 } else if ( arg == "--enable-mouse-pointer" ) {
554 fgSetString("/sim/startup/mouse-pointer", "enabled");
555 } else if ( arg == "--disable-freeze" ) {
556 fgSetBool("/sim/freeze", false);
557 } else if ( arg == "--enable-freeze" ) {
558 fgSetBool("/sim/freeze", true);
559 } else if ( arg == "--disable-anti-alias-hud" ) {
560 fgSetBool("/sim/hud/antialiased", false);
561 } else if ( arg == "--enable-anti-alias-hud" ) {
562 fgSetBool("/sim/hud/antialiased", true);
563 } else if ( arg.find( "--control=") == 0 ) {
564 fgSetString("/sim/control-mode", arg.substr(10));
565 } else if ( arg == "--disable-auto-coordination" ) {
566 fgSetBool("/sim/auto-coordination", false);
567 } else if ( arg == "--enable-auto-coordination" ) {
568 fgSetBool("/sim/auto-coordination", true);
569 } else if ( arg.find( "--browser-app=") == 0 ) {
570 fgSetString("/sim/startup/browser-app", arg.substr(14));
571 } else if ( arg == "--disable-hud" ) {
572 fgSetBool("/sim/hud/visibility", false);
573 } else if ( arg == "--enable-hud" ) {
574 fgSetBool("/sim/hud/visibility", true);
575 } else if ( arg == "--disable-panel" ) {
576 fgSetBool("/sim/panel/visibility", false);
577 } else if ( arg == "--enable-panel" ) {
578 fgSetBool("/sim/panel/visibility", true);
579 } else if ( arg == "--disable-sound" ) {
580 fgSetBool("/sim/sound", false);
581 } else if ( arg == "--enable-sound" ) {
582 fgSetBool("/sim/sound", true);
583 } else if ( arg.find( "--airport-id=") == 0 ) {
584 // NB: changed property name!!!
585 fgSetString("/sim/startup/airport-id", arg.substr(13));
586 } else if ( arg.find( "--offset-distance=") == 0 ) {
587 fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
588 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
589 fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17)));
590 } else if ( arg.find( "--lon=" ) == 0 ) {
591 fgSetDouble("/position/longitude-deg",
592 parse_degree(arg.substr(6)));
593 fgSetString("/sim/startup/airport-id", "");
594 } else if ( arg.find( "--lat=" ) == 0 ) {
595 fgSetDouble("/position/latitude-deg",
596 parse_degree(arg.substr(6)));
597 fgSetString("/sim/startup/airport-id", "");
598 } else if ( arg.find( "--altitude=" ) == 0 ) {
599 fgSetBool("/sim/startup/onground", false);
600 if ( fgGetString("/sim/startup/units") == "feet" )
601 fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
603 fgSetDouble("/position/altitude-ft",
604 atof(arg.substr(11)) * SG_METER_TO_FEET);
605 } else if ( arg.find( "--uBody=" ) == 0 ) {
606 fgSetString("/sim/startup/speed-set", "UVW");
607 if ( fgGetString("/sim/startup/units") == "feet" )
608 fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
610 fgSetDouble("/velocities/uBody-fps",
611 atof(arg.substr(8)) * SG_METER_TO_FEET);
612 } else if ( arg.find( "--vBody=" ) == 0 ) {
613 fgSetString("/sim/startup/speed-set", "UVW");
614 if ( fgGetString("/sim/startup/units") == "feet" )
615 fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
617 fgSetDouble("/velocities/vBody-fps",
618 atof(arg.substr(8)) * SG_METER_TO_FEET);
619 } else if ( arg.find( "--wBody=" ) == 0 ) {
620 fgSetString("/sim/startup/speed-set", "UVW");
621 if ( fgGetString("/sim/startup/units") == "feet" )
622 fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
624 fgSetDouble("/velocities/wBody-fps",
625 atof(arg.substr(8)) * SG_METER_TO_FEET);
626 } else if ( arg.find( "--vNorth=" ) == 0 ) {
627 fgSetString("/sim/startup/speed-set", "NED");
628 if ( fgGetString("/sim/startup/units") == "feet" )
629 fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
631 fgSetDouble("/velocities/speed-north-fps",
632 atof(arg.substr(9)) * SG_METER_TO_FEET);
633 } else if ( arg.find( "--vEast=" ) == 0 ) {
634 fgSetString("/sim/startup/speed-set", "NED");
635 if ( fgGetString("/sim/startup/units") == "feet" )
636 fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
638 fgSetDouble("/velocities/speed-east-fps",
639 atof(arg.substr(8)) * SG_METER_TO_FEET);
640 } else if ( arg.find( "--vDown=" ) == 0 ) {
641 fgSetString("/sim/startup/speed-set", "NED");
642 if ( fgGetString("/sim/startup/units") == "feet" )
643 fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
645 fgSetDouble("/velocities/speed-down-fps",
646 atof(arg.substr(8)) * SG_METER_TO_FEET);
647 } else if ( arg.find( "--vc=" ) == 0) {
648 fgSetString("/sim/startup/speed-set", "knots");
649 fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
650 } else if ( arg.find( "--mach=" ) == 0) {
651 fgSetString("/sim/startup/speed-set", "mach");
652 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
653 } else if ( arg.find( "--heading=" ) == 0 ) {
654 fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
655 } else if ( arg.find( "--roll=" ) == 0 ) {
656 fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
657 } else if ( arg.find( "--pitch=" ) == 0 ) {
658 fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
659 } else if ( arg.find( "--fg-root=" ) == 0 ) {
660 globals->set_fg_root(arg.substr( 10 ));
661 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
662 globals->set_fg_scenery(arg.substr( 13 ));
663 } else if ( arg.find( "--fdm=" ) == 0 ) {
664 fgSetString("/sim/flight-model", arg.substr(6));
665 } else if ( arg.find( "--aero=" ) == 0 ) {
666 fgSetString("/sim/aero", arg.substr(7));
667 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
668 fgSetString("/sim/aircraft-dir", arg.substr(15));
669 } else if ( arg.find( "--model-hz=" ) == 0 ) {
670 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
671 } else if ( arg.find( "--speed=" ) == 0 ) {
672 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
673 } else if ( arg.find( "--trim") == 0) {
674 fgSetBool("/sim/startup/trim", true);
675 } else if ( arg.find( "--notrim") == 0) {
676 fgSetBool("/sim/startup/trim", false);
677 } else if ( arg.find( "--on-ground") == 0) {
678 fgSetBool("/sim/startup/onground", true);
679 } else if ( arg.find( "--in-air") == 0) {
680 fgSetBool("/sim/startup/onground", false);
681 } else if ( arg == "--fog-disable" ) {
682 fgSetString("/sim/rendering/fog", "disabled");
683 } else if ( arg == "--fog-fastest" ) {
684 fgSetString("/sim/rendering/fog", "fastest");
685 } else if ( arg == "--fog-nicest" ) {
686 fgSetString("/sim/fog", "nicest");
687 } else if ( arg == "--disable-clouds" ) {
688 fgSetBool("/environment/clouds/status", false);
689 } else if ( arg == "--enable-clouds" ) {
690 fgSetBool("/environment/clouds/status", true);
691 } else if ( arg.find( "--clouds-asl=" ) == 0 ) {
692 // FIXME: check units
693 if ( fgGetString("/sim/startup/units") == "feet" )
694 fgSetDouble("/environment/clouds/altitude-ft",
695 atof(arg.substr(13)) * SG_FEET_TO_METER);
697 fgSetDouble("/environment/clouds/altitude-ft",
698 atof(arg.substr(13)));
699 } else if ( arg.find( "--fov=" ) == 0 ) {
700 parse_fov( arg.substr(6) );
701 } else if ( arg == "--disable-fullscreen" ) {
702 fgSetBool("/sim/startup/fullscreen", false);
703 } else if ( arg== "--enable-fullscreen") {
704 fgSetBool("/sim/startup/fullscreen", true);
705 } else if ( arg == "--shading-flat") {
706 fgSetBool("/sim/rendering/shading", false);
707 } else if ( arg == "--shading-smooth") {
708 fgSetBool("/sim/rendering/shading", true);
709 } else if ( arg == "--disable-skyblend") {
710 fgSetBool("/sim/rendering/skyblend", false);
711 } else if ( arg== "--enable-skyblend" ) {
712 fgSetBool("/sim/rendering/skyblend", true);
713 } else if ( arg == "--disable-textures" ) {
714 fgSetBool("/sim/rendering/textures", false);
715 } else if ( arg == "--enable-textures" ) {
716 fgSetBool("/sim/rendering/textures", true);
717 } else if ( arg == "--disable-wireframe" ) {
718 fgSetBool("/sim/rendering/wireframe", false);
719 } else if ( arg == "--enable-wireframe" ) {
720 fgSetBool("/sim/rendering/wireframe", true);
721 } else if ( arg.find( "--geometry=" ) == 0 ) {
722 bool geometry_ok = true;
723 int xsize = 0, ysize = 0;
724 string geometry = arg.substr( 11 );
725 string::size_type i = geometry.find('x');
727 if (i != string::npos) {
728 xsize = atoi(geometry.substr(0, i));
729 ysize = atoi(geometry.substr(i+1));
734 if ( xsize <= 0 || ysize <= 0 ) {
740 if ( !geometry_ok ) {
741 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
742 SG_LOG( SG_GENERAL, SG_ALERT,
743 "Setting geometry to " << xsize << 'x' << ysize << '\n');
745 SG_LOG( SG_GENERAL, SG_INFO,
746 "Setting geometry to " << xsize << 'x' << ysize << '\n');
747 fgSetInt("/sim/startup/xsize", xsize);
748 fgSetInt("/sim/startup/ysize", ysize);
750 } else if ( arg.find( "--bpp=" ) == 0 ) {
751 string bits_per_pix = arg.substr( 6 );
752 if ( bits_per_pix == "16" ) {
753 fgSetInt("/sim/rendering/bits-per-pixel", 16);
754 } else if ( bits_per_pix == "24" ) {
755 fgSetInt("/sim/rendering/bits-per-pixel", 24);
756 } else if ( bits_per_pix == "32" ) {
757 fgSetInt("/sim/rendering/bits-per-pixel", 32);
759 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
761 } else if ( arg == "--units-feet" ) {
762 fgSetString("/sim/startup/units", "feet");
763 } else if ( arg == "--units-meters" ) {
764 fgSetString("/sim/startup/units", "meters");
765 } else if ( arg.find( "--time-offset" ) == 0 ) {
766 fgSetInt("/sim/startup/time-offset",
767 parse_time_offset( (arg.substr(14)) ));
768 } else if ( arg.find( "--time-match-real") == 0 ) {
769 fgSetString("/sim/startup/time-offset-type",
771 } else if ( arg.find( "--time-match-local") == 0 ) {
772 fgSetString("/sim/startup/time-offset-type",
774 } else if ( arg.find( "--start-date-sys=") == 0 ) {
775 fgSetInt("/sim/startup/time-offset",
776 parse_date((arg.substr(17))));
777 fgSetString("/sim/startup/time-offset-type", "system");
778 } else if ( arg.find( "--start-date-lat=") == 0 ) {
779 fgSetInt("/sim/startup/time-offset",
780 parse_date((arg.substr(17))));
781 fgSetString("/sim/startup/time-offset-type",
783 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
784 fgSetInt("/sim/startup/time-offset",
785 parse_date((arg.substr(17))));
786 fgSetString("/sim/startup/time-offset-type", "gmt");
787 } else if ( arg == "--hud-tris" ) {
788 fgSetString("/sim/hud/frame-stat-type", "tris");
789 } else if ( arg == "--hud-culled" ) {
790 fgSetString("/sim/hud/frame-stat-type", "culled");
791 } else if ( arg.find( "--atlas=" ) == 0 ) {
792 add_channel( "atlas", arg.substr(8) );
793 } else if ( arg.find( "--httpd=" ) == 0 ) {
794 add_channel( "httpd", arg.substr(8) );
795 } else if ( arg.find( "--native=" ) == 0 ) {
796 add_channel( "native", arg.substr(9) );
797 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
798 add_channel( "native_ctrls", arg.substr(15) );
799 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
800 add_channel( "native_fdm", arg.substr(13) );
801 } else if ( arg.find( "--opengc=" ) == 0 ) {
803 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
804 add_channel( "opengc", arg.substr(9) );
805 } else if ( arg.find( "--garmin=" ) == 0 ) {
806 add_channel( "garmin", arg.substr(9) );
807 } else if ( arg.find( "--nmea=" ) == 0 ) {
808 add_channel( "nmea", arg.substr(7) );
809 } else if ( arg.find( "--props=" ) == 0 ) {
810 add_channel( "props", arg.substr(8) );
811 } else if ( arg.find( "--pve=" ) == 0 ) {
812 add_channel( "pve", arg.substr(6) );
813 } else if ( arg.find( "--ray=" ) == 0 ) {
814 add_channel( "ray", arg.substr(6) );
815 } else if ( arg.find( "--rul=" ) == 0 ) {
816 add_channel( "rul", arg.substr(6) );
817 } else if ( arg.find( "--joyclient=" ) == 0 ) {
818 add_channel( "joyclient", arg.substr(12) );
819 #ifdef FG_NETWORK_OLK
820 } else if ( arg == "--disable-network-olk" ) {
821 fgSetBool("/sim/networking/olk", false);
822 } else if ( arg== "--enable-network-olk") {
823 fgSetBool("/sim/networking/olk", true);
824 } else if ( arg == "--net-hud" ) {
825 fgSetBool("/sim/hud/net-display", true);
826 net_hud_display = 1; // FIXME
827 } else if ( arg.find( "--net-id=") == 0 ) {
828 fgSetString("sim/networking/call-sign", arg.substr(9));
830 } else if ( arg.find( "--prop:" ) == 0 ) {
831 string assign = arg.substr(7);
832 unsigned int pos = assign.find('=');
833 if ( pos == arg.npos || pos == 0 ) {
834 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
835 return FG_OPTIONS_ERROR;
837 string name = assign.substr(0, pos);
838 string value = assign.substr(pos + 1);
839 fgSetString(name.c_str(), value);
840 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
841 // << name << " to \"" << value << '"');
842 } else if ( arg.find("--trace-read=") == 0) {
843 string name = arg.substr(13);
844 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
845 fgGetNode(name, true)->setAttribute(SGPropertyNode::TRACE_READ, true);
846 } else if ( arg.find("--trace-write=") == 0) {
847 string name = arg.substr(14);
848 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
849 fgGetNode(name, true)->setAttribute(SGPropertyNode::TRACE_WRITE, true);
850 } else if ( arg.find( "--view-offset=" ) == 0 ) {
851 // $$$ begin - added VS Renganathan, 14 Oct 2K
852 // for multi-window outside window imagery
853 string woffset = arg.substr( 14 );
854 double default_view_offset = 0.0;
855 if ( woffset == "LEFT" ) {
856 default_view_offset = SGD_PI * 0.25;
857 } else if ( woffset == "RIGHT" ) {
858 default_view_offset = SGD_PI * 1.75;
859 } else if ( woffset == "CENTER" ) {
860 default_view_offset = 0.00;
862 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
864 FGViewerRPH *pilot_view =
865 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
866 pilot_view->set_view_offset( default_view_offset );
867 pilot_view->set_goal_view_offset( default_view_offset );
868 fgSetDouble("/sim/view/offset-deg", default_view_offset);
869 // $$$ end - added VS Renganathan, 14 Oct 2K
870 } else if ( arg.find( "--visibility=" ) == 0 ) {
871 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
872 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
873 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
874 fgSetDouble("/environment/visibility-m", visibility);
875 } else if ( arg.find( "--wind=" ) == 0 ) {
876 string val = arg.substr(7);
877 unsigned int pos = val.find('@');
878 if ( pos == string::npos ) {
879 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << val );
880 return FG_OPTIONS_ERROR;
882 double dir = atof(val.substr(0,pos).c_str());
883 double speed = atof(val.substr(pos+1).c_str());
884 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << dir << '@' <<
885 speed << " knots" << endl);
886 fgSetDouble("/environment/wind-from-heading-deg", dir);
887 fgSetDouble("/environment/wind-speed-knots", speed);
890 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
894 dir *= SGD_DEGREES_TO_RADIANS;
895 fgSetDouble("/environment/wind-north-fps",
897 fgSetDouble("/environment/wind-east-fps",
899 } else if ( arg.find( "--wp=" ) == 0 ) {
900 parse_wp( arg.substr( 5 ) );
901 } else if ( arg.find( "--flight-plan=") == 0) {
902 parse_flightplan ( arg.substr (14) );
903 } else if ( arg.find( "--config=" ) == 0 ) {
904 string file = arg.substr(9);
906 readProperties(file, globals->get_props());
907 } catch (const sg_exception &e) {
908 string message = "Error loading config file: ";
909 message += e.getFormattedMessage();
910 SG_LOG(SG_INPUT, SG_ALERT, message);
913 } else if ( arg.find( "--aircraft=" ) == 0 ) {
914 // read in the top level aircraft definition file
915 SGPath apath( globals->get_fg_root() );
916 apath.append( "Aircraft" );
917 apath.append( arg.substr(11) );
918 apath.concat( "-set.xml" );
920 readProperties( apath.str(), globals->get_props() );
921 } catch (const sg_exception &e) {
922 string message = "Error loading aircraft file: ";
923 message += e.getFormattedMessage();
924 SG_LOG(SG_INPUT, SG_ALERT, message);
928 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
929 return FG_OPTIONS_ERROR;
932 return FG_OPTIONS_OK;
936 // Scan the command line options for an fg_root definition and set
939 fgScanForRoot (int argc, char **argv)
943 SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
946 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
948 string arg = argv[i];
949 if ( arg.find( "--fg-root=" ) == 0 ) {
950 return arg.substr( 10 );
960 // Scan the config file for an fg_root definition and set just that.
962 fgScanForRoot (const string& path)
964 sg_gzifstream in( path );
968 SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
972 while ( ! in.eof() ) {
975 while ( in.get(c) && c != '\0' ) {
980 #if defined( macintosh )
981 getline( in, line, '\r' );
983 getline( in, line, '\n' );
986 // catch extraneous (DOS) line ending character
987 if ( line[line.length() - 1] < 32 ) {
988 line = line.substr( 0, line.length()-1 );
991 if ( line.find( "--fg-root=" ) == 0 ) {
992 return line.substr( 10 );
1002 // Parse the command line options
1004 fgParseOptions (int argc, char **argv) {
1008 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1010 while ( i < argc ) {
1011 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
1013 result = parse_option(argv[i]);
1014 if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
1024 // Parse config file options
1026 fgParseOptions (const string& path) {
1027 sg_gzifstream in( path );
1028 if ( !in.is_open() ) {
1032 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1036 while ( ! in.eof() ) {
1039 while ( in.get(c) && c != '\0' ) {
1044 #if defined( macintosh )
1045 getline( in, line, '\r' );
1047 getline( in, line, '\n' );
1050 // catch extraneous (DOS) line ending character
1051 if ( line[line.length() - 1] < 32 ) {
1052 line = line.substr( 0, line.length()-1 );
1055 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1056 SG_LOG( SG_GENERAL, SG_ALERT,
1057 "Config file parse error: " << path << " '"
1067 // Print usage message
1071 cout << "Usage: fgfs [ options ... ]" << endl;
1074 cout << "General Options:" << endl;
1075 cout << "\t--help -h: print usage" << endl;
1076 cout << "\t--fg-root=path: specify the root path for all the data files"
1078 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
1080 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1081 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
1082 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1083 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1084 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1085 cout << "\t--disable-intro-music: disable introduction music" << endl;
1086 cout << "\t--enable-intro-music: enable introduction music" << endl;
1087 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1088 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1090 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1091 cout << "\t--disable-freeze: start out in a running state" << endl;
1092 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1093 cout << "\t--control=mode: primary control mode "
1094 << "(joystick, keyboard, mouse)" << endl;
1095 cout << "\t--enable-auto-coordination: enable auto coordination" << endl;
1096 cout << "\t--disable-auto-coordination: disable auto coordination" << endl;
1097 cout << "\t--browser-app=/path/to/app: specify location of your web browser" << endl;
1098 cout << "\t--prop:name=value: set property <name> to <value>" << endl;
1099 cout << "\t--config=path: load additional properties from path" << endl;
1102 cout << "Features:" << endl;
1103 cout << "\t--disable-hud: disable heads up display" << endl;
1104 cout << "\t--enable-hud: enable heads up display" << endl;
1105 cout << "\t--disable-panel: disable instrument panel" << endl;
1106 cout << "\t--enable-panel: enable instrument panel" << endl;
1107 cout << "\t--disable-sound: disable sound effects" << endl;
1108 cout << "\t--enable-sound: enable sound effects" << endl;
1109 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1110 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1113 cout << "Flight Model:" << endl;
1114 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1115 cout << "\t\tcan be one of jsb, larcsim, magic, null, external, balloon, or ada"
1117 cout << "\t--aero=abcd: aerodynamics model to load" << endl;
1118 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1120 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1121 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1122 cout << "\t--on-ground: Start up at ground level (default)" << endl;
1123 cout << "\t--in-air: Start up in air (implied by specifying an initial"
1124 << " altitude above ground level." << endl;
1125 cout << "\t--wind=DIR@SPEED: specify wind coming from DIR (degrees) at SPEED (knots)" << endl;
1129 cout <<"Aircraft model directory:" << endl;
1130 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1133 cout << "Initial Position and Orientation:" << endl;
1134 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1136 cout << "\t--offset-distance: specify distance to threshold"
1138 cout << "\t--offset-azimuth: specify heading to threshold (deg) "
1140 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1142 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1144 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1145 cout << "\t\t(unless --units-meters specified)" << endl;
1146 cout << "\t--heading=degrees: heading (yaw) angle in degrees (Psi)"
1148 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1149 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1150 cout << "\t--uBody=feet per second: velocity along the body X axis"
1152 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1154 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1156 cout << "\t\t(unless --units-meters specified)" << endl;
1157 cout << "\t--vc= initial airspeed in knots" << endl;
1158 cout << "\t--mach= initial mach number" << endl;
1161 cout << "Rendering Options:" << endl;
1162 cout << "\t--fog-disable: disable fog/haze" << endl;
1163 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1164 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1165 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1166 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1167 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1168 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1170 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1171 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1172 cout << "\t--shading-flat: enable flat shading" << endl;
1173 cout << "\t--shading-smooth: enable smooth shading" << endl;
1174 cout << "\t--disable-skyblend: disable sky blending" << endl;
1175 cout << "\t--enable-skyblend: enable sky blending" << endl;
1176 cout << "\t--disable-textures: disable textures" << endl;
1177 cout << "\t--enable-textures: enable textures" << endl;
1178 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1179 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1180 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1182 cout << "\t--view-offset=xxx: set the default forward view direction"
1184 cout << "\t\tas an offset from straight ahead. Allowable values are"
1186 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1187 cout << "\t--visibility=xxx: specify initial visibility in meters" << endl;
1188 cout << "\t--visibility-miles=xxx: specify initial visibility in miles"
1192 cout << "Scenery Options:" << endl;
1193 cout << "\t--tile-radius=n: specify tile radius, must be 1 - 4" << endl;
1196 cout << "Hud Options:" << endl;
1197 cout << "\t--units-feet: Hud displays units in feet" << endl;
1198 cout << "\t--units-meters: Hud displays units in meters" << endl;
1199 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1200 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1204 cout << "Time Options:" << endl;
1205 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1206 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1207 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1208 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1209 << "\t\tFlightGear time" << endl;
1210 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1211 << "\t\tdate/time. Uses your system time " << endl;
1212 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1213 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1214 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1215 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1216 #ifdef FG_NETWORK_OLK
1219 cout << "Network Options:" << endl;
1220 cout << "\t--httpd=port: enable http server on the specified port" << endl;
1221 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1222 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1223 cout << "\t--net-hud: Hud displays network info" << endl;
1224 cout << "\t--net-id=name: specify your own callsign" << endl;
1228 cout << "Route/Way Point Options:" << endl;
1229 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1230 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1232 cout << "\t\tinstances of --wp=" << endl;
1233 cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;