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()
38 #include <simgear/misc/sgstream.hxx>
40 // #include <Include/general.hxx>
41 // #include <Airports/simple.hxx>
42 // #include <Cockpit/cockpit.hxx>
43 // #include <FDM/flight.hxx>
44 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
46 # include <NetworkOLK/network.h>
51 #include "globals.hxx"
52 #include "fg_init.hxx"
53 #include "fg_props.hxx"
54 #include "options.hxx"
55 #include "viewmgr.hxx"
58 SG_USING_NAMESPACE(std);
61 #define NEW_DEFAULT_MODEL_HZ 120
71 atof( const string& str )
75 // -dw- if ::atof is called, then we get an infinite loop
76 return std::atof( str.c_str() );
78 return ::atof( str.c_str() );
83 atoi( const string& str )
86 // -dw- if ::atoi is called, then we get an infinite loop
87 return std::atoi( str.c_str() );
89 return ::atoi( str.c_str() );
95 * Set a few fail-safe default property values.
97 * These should all be set in $FG_ROOT/preferences.xml, but just
98 * in case, we provide some initial sane values here. This method
99 * should be invoked *before* reading any init files.
104 // set a possibly independent location for scenery data
105 char *envp = ::getenv( "FG_SCENERY" );
107 if ( envp != NULL ) {
108 // fg_root could be anywhere, so default to environmental
109 // variable $FG_ROOT if it is set.
110 globals->set_fg_scenery(envp);
112 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
113 globals->set_fg_scenery("");
115 // Position (Globe, AZ)
116 fgSetDouble("/position/longitude-deg", -110.6642444);
117 fgSetDouble("/position/latitude-deg", 33.3528917);
118 fgSetDouble("/position/altitude-ft", -9999.0);
121 fgSetDouble("/orientation/heading-deg", 270);
122 fgSetDouble("/orientation/roll-deg", 0);
123 fgSetDouble("/orientation/pitch-deg", 0.424);
126 fgSetString("/sim/startup/speed-set", "knots");
127 fgSetDouble("/velocities/uBody-fps", 0.0);
128 fgSetDouble("/velocities/vBody-fps", 0.0);
129 fgSetDouble("/velocities/wBody-fps", 0.0);
130 fgSetDouble("/velocities/speed-north-fps", 0.0);
131 fgSetDouble("/velocities/speed-east-fps", 0.0);
132 fgSetDouble("/velocities/speed-down-fps", 0.0);
133 fgSetDouble("/velocities/airspeed-kt", 0.0);
134 fgSetDouble("/velocities/mach", 0.0);
137 fgSetBool("/sim/startup/game-mode", false);
138 fgSetBool("/sim/startup/splash-screen", true);
139 fgSetBool("/sim/startup/intro-music", true);
140 // we want mouse-pointer to have an undefined value if nothing is
141 // specified so we can do the right thing for voodoo-1/2 cards.
142 // fgSetString("/sim/startup/mouse-pointer", "disabled");
143 fgSetString("/sim/control-mode", "joystick");
144 fgSetBool("/sim/auto-coordination", false);
146 fgSetString("/sim/startup/browser-app", "netscape");
148 fgSetString("/sim/startup/browser-app", "webrun.bat");
151 fgSetBool("/sim/hud/visibility", false);
152 fgSetBool("/sim/panel/visibility", true);
153 fgSetBool("/sim/sound", true);
154 fgSetBool("/sim/hud/antialiased", false);
156 // Flight Model options
157 fgSetString("/sim/flight-model", "jsb");
158 fgSetString("/sim/aero", "c172");
159 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
160 fgSetInt("/sim/speed-up", 1);
161 fgSetBool("/sim/startup/trim", false);
162 fgSetBool("/sim/startup/onground", true);
165 fgSetString("/sim/rendering/fog", "nicest");
166 fgSetBool("/environment/clouds/status", true);
167 fgSetDouble("/environment/clouds/altitude-ft", 5000);
168 fgSetBool("/sim/startup/fullscreen", false);
169 fgSetBool("/sim/rendering/shading", true);
170 fgSetBool("/sim/rendering/skyblend", true);
171 fgSetBool("/sim/rendering/textures", true);
172 fgSetBool("/sim/rendering/wireframe", false);
173 fgSetInt("/sim/startup/xsize", 800);
174 fgSetInt("/sim/startup/ysize", 600);
175 fgSetInt("/sim/rendering/bits-per-pixel", 16);
176 fgSetString("/sim/view-mode", "pilot");
177 fgSetDouble("/sim/view/offset-deg", 0);
178 fgSetDouble("/environment/visibility-m", 20000);
181 fgSetString("/sim/startup/units", "feet");
182 fgSetString("/sim/hud/frame-stat-type", "tris");
185 fgSetInt("/sim/startup/time-offset", 0);
186 fgSetString("/sim/startup/time-offset-type", "system-offset");
188 fgSetBool("/sim/networking/network-olk", false);
189 fgSetString("/sim/networking/call-sign", "Johnny");
192 fgSetBool("/sim/freeze/master", false);
193 fgSetBool("/sim/freeze/position", false);
194 fgSetBool("/sim/freeze/fuel", false);
195 fgSetBool("/sim/freeze/time-of-day", false);
199 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
201 parse_time(const string& time_in) {
202 char *time_str, num[256];
203 double hours, minutes, seconds;
208 time_str = (char *)time_in.c_str();
210 // printf("parse_time(): %s\n", time_str);
213 if ( strlen(time_str) ) {
214 if ( time_str[0] == '+' ) {
217 } else if ( time_str[0] == '-' ) {
222 // printf("sign = %d\n", sign);
225 if ( strlen(time_str) ) {
227 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
228 num[i] = time_str[0];
232 if ( time_str[0] == ':' ) {
237 // printf("hours = %.2lf\n", hours);
243 if ( strlen(time_str) ) {
245 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
246 num[i] = time_str[0];
250 if ( time_str[0] == ':' ) {
255 // printf("minutes = %.2lf\n", minutes);
257 result += minutes / 60.0;
261 if ( strlen(time_str) ) {
263 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
264 num[i] = time_str[0];
270 // printf("seconds = %.2lf\n", seconds);
272 result += seconds / 3600.0;
275 return(sign * result);
279 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
281 parse_date( const string& date)
284 char * date_str, num[256];
286 // initialize to zero
293 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
294 date_str = (char *)date.c_str();
296 if ( strlen(date_str) ) {
298 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
299 num[i] = date_str[0];
303 if ( date_str[0] == ':' ) {
307 gmt.tm_year = atoi(num) - 1900;
310 if ( strlen(date_str) ) {
312 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
313 num[i] = date_str[0];
317 if ( date_str[0] == ':' ) {
321 gmt.tm_mon = atoi(num) -1;
324 if ( strlen(date_str) ) {
326 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
327 num[i] = date_str[0];
331 if ( date_str[0] == ':' ) {
335 gmt.tm_mday = atoi(num);
338 if ( strlen(date_str) ) {
340 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
341 num[i] = date_str[0];
345 if ( date_str[0] == ':' ) {
349 gmt.tm_hour = atoi(num);
352 if ( strlen(date_str) ) {
354 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
355 num[i] = date_str[0];
359 if ( date_str[0] == ':' ) {
363 gmt.tm_min = atoi(num);
366 if ( strlen(date_str) ) {
368 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
369 num[i] = date_str[0];
373 if ( date_str[0] == ':' ) {
377 gmt.tm_sec = atoi(num);
379 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
380 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
381 //printf ("Date is %s\n", ctime(&theTime));
382 //printf ("in seconds that is %d\n", theTime);
388 // parse angle in the form of [+/-]ddd:mm:ss into degrees
390 parse_degree( const string& degree_str) {
391 double result = parse_time( degree_str );
393 // printf("Degree = %.4f\n", result);
399 // parse time offset string into seconds
401 parse_time_offset( const string& time_str) {
404 // printf("time offset = %s\n", time_str);
407 result = (int)rint(parse_time(time_str) * 3600.0);
409 result = (int)(parse_time(time_str) * 3600.0);
412 // printf("parse_time_offset(): %d\n", result);
418 // Parse --fov=x.xx type option
420 parse_fov( const string& arg ) {
421 double fov = atof(arg);
423 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
424 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
426 fgSetDouble("/sim/field-of-view", fov);
428 // printf("parse_fov(): result = %.4f\n", fov);
434 // Parse I/O channel option
436 // Format is "--protocol=medium,direction,hz,medium_options,..."
438 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
439 // medium = { serial, socket, file, etc. }
440 // direction = { in, out, bi }
441 // hz = number of times to process channel per second (floating
442 // point values are ok.
444 // Serial example "--nmea=serial,dir,hz,device,baud" where
446 // device = OS device name of serial line to be open()'ed
447 // baud = {300, 1200, 2400, ..., 230400}
449 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
451 // machine = machine name or ip address if client (leave empty if server)
452 // port = port, leave empty to let system choose
453 // style = tcp or udp
455 // File example "--garmin=file,dir,hz,filename" where
457 // filename = file system file name
460 add_channel( const string& type, const string& channel_str ) {
461 // cout << "Channel string = " << channel_str << endl;
463 globals->get_channel_options_list()->push_back( type + "," + channel_str );
469 // Parse --wp=ID[@alt]
471 parse_wp( const string& arg ) {
475 unsigned int pos = arg.find( "@" );
476 if ( pos != string::npos ) {
477 id = arg.substr( 0, pos );
478 alt_str = arg.substr( pos + 1 );
479 // cout << "id str = " << id << " alt str = " << alt_str << endl;
480 alt = atof( alt_str.c_str() );
481 if ( fgGetString("/sim/startup/units") == "feet" ) {
482 alt *= SG_FEET_TO_METER;
489 if ( fgFindAirportID( id, &a ) ) {
490 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
491 globals->get_route()->add_waypoint( wp );
500 // Parse --flight-plan=[file]
502 parse_flightplan(const string& arg)
504 sg_gzifstream in(arg.c_str());
505 if ( !in.is_open() ) {
511 #if defined( macintosh )
512 getline( in, line, '\r' );
514 getline( in, line, '\n' );
517 // catch extraneous (DOS) line ending character
518 if ( line[line.length() - 1] < 32 ) {
519 line = line.substr( 0, line.length()-1 );
532 // Parse a single option
534 parse_option (const string& arg)
537 if ( (arg == "--help") || (arg == "-h") ) {
538 // help/usage request
539 return(FG_OPTIONS_HELP);
540 } else if ( arg == "--disable-game-mode") {
541 fgSetBool("/sim/startup/game-mode", false);
542 } else if ( arg == "--enable-game-mode" ) {
543 fgSetBool("/sim/startup/game-mode", true);
544 } else if ( arg == "--disable-splash-screen" ) {
545 fgSetBool("/sim/startup/splash-screen", false);
546 } else if ( arg == "--enable-splash-screen" ) {
547 fgSetBool("/sim/startup/splash-screen", true);
548 } else if ( arg == "--disable-intro-music" ) {
549 fgSetBool("/sim/startup/intro-music", false);
550 } else if ( arg == "--enable-intro-music" ) {
551 fgSetBool("/sim/startup/intro-music", true);
552 } else if ( arg == "--disable-mouse-pointer" ) {
553 fgSetString("/sim/startup/mouse-pointer", "disabled");
554 } else if ( arg == "--enable-mouse-pointer" ) {
555 fgSetString("/sim/startup/mouse-pointer", "enabled");
556 } else if ( arg == "--disable-freeze" ) {
557 fgSetBool("/sim/freeze/master", false);
558 } else if ( arg == "--enable-freeze" ) {
559 fgSetBool("/sim/freeze/master", true);
560 } else if ( arg == "--disable-fuel-freeze" ) {
561 fgSetBool("/sim/freeze/fuel", false);
562 } else if ( arg == "--enable-fuel-freeze" ) {
563 fgSetBool("/sim/freeze/fuel", true);
564 } else if ( arg == "--disable-anti-alias-hud" ) {
565 fgSetBool("/sim/hud/antialiased", false);
566 } else if ( arg == "--enable-anti-alias-hud" ) {
567 fgSetBool("/sim/hud/antialiased", true);
568 } else if ( arg.find( "--control=") == 0 ) {
569 fgSetString("/sim/control-mode", arg.substr(10));
570 } else if ( arg == "--disable-auto-coordination" ) {
571 fgSetBool("/sim/auto-coordination", false);
572 } else if ( arg == "--enable-auto-coordination" ) {
573 fgSetBool("/sim/auto-coordination", true);
574 } else if ( arg.find( "--browser-app=") == 0 ) {
575 fgSetString("/sim/startup/browser-app", arg.substr(14));
576 } else if ( arg == "--disable-hud" ) {
577 fgSetBool("/sim/hud/visibility", false);
578 } else if ( arg == "--enable-hud" ) {
579 fgSetBool("/sim/hud/visibility", true);
580 } else if ( arg == "--disable-panel" ) {
581 fgSetBool("/sim/panel/visibility", false);
582 } else if ( arg == "--enable-panel" ) {
583 fgSetBool("/sim/panel/visibility", true);
584 } else if ( arg == "--disable-sound" ) {
585 fgSetBool("/sim/sound", false);
586 } else if ( arg == "--enable-sound" ) {
587 fgSetBool("/sim/sound", true);
588 } else if ( arg.find( "--airport-id=") == 0 ) {
589 // NB: changed property name!!!
590 fgSetString("/sim/startup/airport-id", arg.substr(13));
591 } else if ( arg.find( "--offset-distance=") == 0 ) {
592 fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
593 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
594 fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17)));
595 } else if ( arg.find( "--lon=" ) == 0 ) {
596 fgSetDouble("/position/longitude-deg",
597 parse_degree(arg.substr(6)));
598 fgSetString("/sim/startup/airport-id", "");
599 } else if ( arg.find( "--lat=" ) == 0 ) {
600 fgSetDouble("/position/latitude-deg",
601 parse_degree(arg.substr(6)));
602 fgSetString("/sim/startup/airport-id", "");
603 } else if ( arg.find( "--altitude=" ) == 0 ) {
604 fgSetBool("/sim/startup/onground", false);
605 if ( fgGetString("/sim/startup/units") == "feet" )
606 fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
608 fgSetDouble("/position/altitude-ft",
609 atof(arg.substr(11)) * SG_METER_TO_FEET);
610 } else if ( arg.find( "--uBody=" ) == 0 ) {
611 fgSetString("/sim/startup/speed-set", "UVW");
612 if ( fgGetString("/sim/startup/units") == "feet" )
613 fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
615 fgSetDouble("/velocities/uBody-fps",
616 atof(arg.substr(8)) * SG_METER_TO_FEET);
617 } else if ( arg.find( "--vBody=" ) == 0 ) {
618 fgSetString("/sim/startup/speed-set", "UVW");
619 if ( fgGetString("/sim/startup/units") == "feet" )
620 fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
622 fgSetDouble("/velocities/vBody-fps",
623 atof(arg.substr(8)) * SG_METER_TO_FEET);
624 } else if ( arg.find( "--wBody=" ) == 0 ) {
625 fgSetString("/sim/startup/speed-set", "UVW");
626 if ( fgGetString("/sim/startup/units") == "feet" )
627 fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
629 fgSetDouble("/velocities/wBody-fps",
630 atof(arg.substr(8)) * SG_METER_TO_FEET);
631 } else if ( arg.find( "--vNorth=" ) == 0 ) {
632 fgSetString("/sim/startup/speed-set", "NED");
633 if ( fgGetString("/sim/startup/units") == "feet" )
634 fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
636 fgSetDouble("/velocities/speed-north-fps",
637 atof(arg.substr(9)) * SG_METER_TO_FEET);
638 } else if ( arg.find( "--vEast=" ) == 0 ) {
639 fgSetString("/sim/startup/speed-set", "NED");
640 if ( fgGetString("/sim/startup/units") == "feet" )
641 fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
643 fgSetDouble("/velocities/speed-east-fps",
644 atof(arg.substr(8)) * SG_METER_TO_FEET);
645 } else if ( arg.find( "--vDown=" ) == 0 ) {
646 fgSetString("/sim/startup/speed-set", "NED");
647 if ( fgGetString("/sim/startup/units") == "feet" )
648 fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
650 fgSetDouble("/velocities/speed-down-fps",
651 atof(arg.substr(8)) * SG_METER_TO_FEET);
652 } else if ( arg.find( "--vc=" ) == 0) {
653 fgSetString("/sim/startup/speed-set", "knots");
654 fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
655 } else if ( arg.find( "--mach=" ) == 0) {
656 fgSetString("/sim/startup/speed-set", "mach");
657 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
658 } else if ( arg.find( "--heading=" ) == 0 ) {
659 fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
660 } else if ( arg.find( "--roll=" ) == 0 ) {
661 fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
662 } else if ( arg.find( "--pitch=" ) == 0 ) {
663 fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
664 } else if ( arg.find( "--fg-root=" ) == 0 ) {
665 globals->set_fg_root(arg.substr( 10 ));
666 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
667 globals->set_fg_scenery(arg.substr( 13 ));
668 } else if ( arg.find( "--fdm=" ) == 0 ) {
669 fgSetString("/sim/flight-model", arg.substr(6));
670 } else if ( arg.find( "--aero=" ) == 0 ) {
671 fgSetString("/sim/aero", arg.substr(7));
672 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
673 fgSetString("/sim/aircraft-dir", arg.substr(15));
674 } else if ( arg.find( "--model-hz=" ) == 0 ) {
675 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
676 } else if ( arg.find( "--speed=" ) == 0 ) {
677 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
678 } else if ( arg.find( "--trim") == 0) {
679 fgSetBool("/sim/startup/trim", true);
680 } else if ( arg.find( "--notrim") == 0) {
681 fgSetBool("/sim/startup/trim", false);
682 } else if ( arg.find( "--on-ground") == 0) {
683 fgSetBool("/sim/startup/onground", true);
684 } else if ( arg.find( "--in-air") == 0) {
685 fgSetBool("/sim/startup/onground", false);
686 } else if ( arg == "--fog-disable" ) {
687 fgSetString("/sim/rendering/fog", "disabled");
688 } else if ( arg == "--fog-fastest" ) {
689 fgSetString("/sim/rendering/fog", "fastest");
690 } else if ( arg == "--fog-nicest" ) {
691 fgSetString("/sim/fog", "nicest");
692 } else if ( arg == "--disable-clouds" ) {
693 fgSetBool("/environment/clouds/status", false);
694 } else if ( arg == "--enable-clouds" ) {
695 fgSetBool("/environment/clouds/status", true);
696 } else if ( arg.find( "--clouds-asl=" ) == 0 ) {
697 // FIXME: check units
698 if ( fgGetString("/sim/startup/units") == "feet" )
699 fgSetDouble("/environment/clouds/altitude-ft",
700 atof(arg.substr(13)));
702 fgSetDouble("/environment/clouds/altitude-ft",
703 atof(arg.substr(13)) * SG_METER_TO_FEET);
704 } else if ( arg.find( "--fov=" ) == 0 ) {
705 parse_fov( arg.substr(6) );
706 } else if ( arg == "--disable-fullscreen" ) {
707 fgSetBool("/sim/startup/fullscreen", false);
708 } else if ( arg== "--enable-fullscreen") {
709 fgSetBool("/sim/startup/fullscreen", true);
710 } else if ( arg == "--shading-flat") {
711 fgSetBool("/sim/rendering/shading", false);
712 } else if ( arg == "--shading-smooth") {
713 fgSetBool("/sim/rendering/shading", true);
714 } else if ( arg == "--disable-skyblend") {
715 fgSetBool("/sim/rendering/skyblend", false);
716 } else if ( arg== "--enable-skyblend" ) {
717 fgSetBool("/sim/rendering/skyblend", true);
718 } else if ( arg == "--disable-textures" ) {
719 fgSetBool("/sim/rendering/textures", false);
720 } else if ( arg == "--enable-textures" ) {
721 fgSetBool("/sim/rendering/textures", true);
722 } else if ( arg == "--disable-wireframe" ) {
723 fgSetBool("/sim/rendering/wireframe", false);
724 } else if ( arg == "--enable-wireframe" ) {
725 fgSetBool("/sim/rendering/wireframe", true);
726 } else if ( arg.find( "--geometry=" ) == 0 ) {
727 bool geometry_ok = true;
728 int xsize = 0, ysize = 0;
729 string geometry = arg.substr( 11 );
730 string::size_type i = geometry.find('x');
732 if (i != string::npos) {
733 xsize = atoi(geometry.substr(0, i));
734 ysize = atoi(geometry.substr(i+1));
739 if ( xsize <= 0 || ysize <= 0 ) {
745 if ( !geometry_ok ) {
746 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
747 SG_LOG( SG_GENERAL, SG_ALERT,
748 "Setting geometry to " << xsize << 'x' << ysize << '\n');
750 SG_LOG( SG_GENERAL, SG_INFO,
751 "Setting geometry to " << xsize << 'x' << ysize << '\n');
752 fgSetInt("/sim/startup/xsize", xsize);
753 fgSetInt("/sim/startup/ysize", ysize);
755 } else if ( arg.find( "--bpp=" ) == 0 ) {
756 string bits_per_pix = arg.substr( 6 );
757 if ( bits_per_pix == "16" ) {
758 fgSetInt("/sim/rendering/bits-per-pixel", 16);
759 } else if ( bits_per_pix == "24" ) {
760 fgSetInt("/sim/rendering/bits-per-pixel", 24);
761 } else if ( bits_per_pix == "32" ) {
762 fgSetInt("/sim/rendering/bits-per-pixel", 32);
764 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
766 } else if ( arg == "--units-feet" ) {
767 fgSetString("/sim/startup/units", "feet");
768 } else if ( arg == "--units-meters" ) {
769 fgSetString("/sim/startup/units", "meters");
770 } else if ( arg.find( "--time-offset" ) == 0 ) {
771 fgSetInt("/sim/startup/time-offset",
772 parse_time_offset( (arg.substr(14)) ));
773 } else if ( arg.find( "--time-match-real") == 0 ) {
774 fgSetString("/sim/startup/time-offset-type",
776 } else if ( arg.find( "--time-match-local") == 0 ) {
777 fgSetString("/sim/startup/time-offset-type",
779 } else if ( arg.find( "--start-date-sys=") == 0 ) {
780 fgSetInt("/sim/startup/time-offset",
781 parse_date((arg.substr(17))));
782 fgSetString("/sim/startup/time-offset-type", "system");
783 } else if ( arg.find( "--start-date-lat=") == 0 ) {
784 fgSetInt("/sim/startup/time-offset",
785 parse_date((arg.substr(17))));
786 fgSetString("/sim/startup/time-offset-type",
788 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
789 fgSetInt("/sim/startup/time-offset",
790 parse_date((arg.substr(17))));
791 fgSetString("/sim/startup/time-offset-type", "gmt");
792 } else if ( arg == "--hud-tris" ) {
793 fgSetString("/sim/hud/frame-stat-type", "tris");
794 } else if ( arg == "--hud-culled" ) {
795 fgSetString("/sim/hud/frame-stat-type", "culled");
796 } else if ( arg.find( "--atlas=" ) == 0 ) {
797 add_channel( "atlas", arg.substr(8) );
798 } else if ( arg.find( "--httpd=" ) == 0 ) {
799 add_channel( "httpd", arg.substr(8) );
800 #ifdef FG_JPEG_SERVER
801 } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
802 add_channel( "jpg-httpd", arg.substr(12) );
804 } else if ( arg.find( "--native=" ) == 0 ) {
805 add_channel( "native", arg.substr(9) );
806 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
807 add_channel( "native_ctrls", arg.substr(15) );
808 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
809 add_channel( "native_fdm", arg.substr(13) );
810 } else if ( arg.find( "--opengc=" ) == 0 ) {
812 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
813 add_channel( "opengc", arg.substr(9) );
814 } else if ( arg.find( "--garmin=" ) == 0 ) {
815 add_channel( "garmin", arg.substr(9) );
816 } else if ( arg.find( "--nmea=" ) == 0 ) {
817 add_channel( "nmea", arg.substr(7) );
818 } else if ( arg.find( "--props=" ) == 0 ) {
819 add_channel( "props", arg.substr(8) );
820 } else if ( arg.find( "--pve=" ) == 0 ) {
821 add_channel( "pve", arg.substr(6) );
822 } else if ( arg.find( "--ray=" ) == 0 ) {
823 add_channel( "ray", arg.substr(6) );
824 } else if ( arg.find( "--rul=" ) == 0 ) {
825 add_channel( "rul", arg.substr(6) );
826 } else if ( arg.find( "--joyclient=" ) == 0 ) {
827 add_channel( "joyclient", arg.substr(12) );
828 #ifdef FG_NETWORK_OLK
829 } else if ( arg == "--disable-network-olk" ) {
830 fgSetBool("/sim/networking/olk", false);
831 } else if ( arg== "--enable-network-olk") {
832 fgSetBool("/sim/networking/olk", true);
833 } else if ( arg == "--net-hud" ) {
834 fgSetBool("/sim/hud/net-display", true);
835 net_hud_display = 1; // FIXME
836 } else if ( arg.find( "--net-id=") == 0 ) {
837 fgSetString("sim/networking/call-sign", arg.substr(9));
839 } else if ( arg.find( "--prop:" ) == 0 ) {
840 string assign = arg.substr(7);
841 unsigned int pos = assign.find('=');
842 if ( pos == arg.npos || pos == 0 ) {
843 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
844 return FG_OPTIONS_ERROR;
846 string name = assign.substr(0, pos);
847 string value = assign.substr(pos + 1);
848 fgSetString(name.c_str(), value);
849 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
850 // << name << " to \"" << value << '"');
851 } else if ( arg.find("--trace-read=") == 0) {
852 string name = arg.substr(13);
853 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
854 fgGetNode(name, true)->setAttribute(SGPropertyNode::TRACE_READ, true);
855 } else if ( arg.find("--trace-write=") == 0) {
856 string name = arg.substr(14);
857 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
858 fgGetNode(name, true)->setAttribute(SGPropertyNode::TRACE_WRITE, true);
859 } else if ( arg.find( "--view-offset=" ) == 0 ) {
860 // $$$ begin - added VS Renganathan, 14 Oct 2K
861 // for multi-window outside window imagery
862 string woffset = arg.substr( 14 );
863 double default_view_offset = 0.0;
864 if ( woffset == "LEFT" ) {
865 default_view_offset = SGD_PI * 0.25;
866 } else if ( woffset == "RIGHT" ) {
867 default_view_offset = SGD_PI * 1.75;
868 } else if ( woffset == "CENTER" ) {
869 default_view_offset = 0.00;
871 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
873 FGViewerRPH *pilot_view =
874 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
875 pilot_view->set_view_offset( default_view_offset );
876 pilot_view->set_goal_view_offset( default_view_offset );
877 fgSetDouble("/sim/view/offset-deg", default_view_offset);
878 // $$$ end - added VS Renganathan, 14 Oct 2K
879 } else if ( arg.find( "--visibility=" ) == 0 ) {
880 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
881 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
882 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
883 fgSetDouble("/environment/visibility-m", visibility);
884 } else if ( arg.find( "--wind=" ) == 0 ) {
885 string val = arg.substr(7);
886 unsigned int pos = val.find('@');
887 if ( pos == string::npos ) {
888 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << val );
889 return FG_OPTIONS_ERROR;
891 double dir = atof(val.substr(0,pos).c_str());
892 double speed = atof(val.substr(pos+1).c_str());
893 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << dir << '@' <<
894 speed << " knots" << endl);
895 fgSetDouble("/environment/wind-from-heading-deg", dir);
896 fgSetDouble("/environment/wind-speed-knots", speed);
899 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
903 dir *= SGD_DEGREES_TO_RADIANS;
904 fgSetDouble("/environment/wind-north-fps",
906 fgSetDouble("/environment/wind-east-fps",
908 } else if ( arg.find( "--wp=" ) == 0 ) {
909 parse_wp( arg.substr( 5 ) );
910 } else if ( arg.find( "--flight-plan=") == 0) {
911 parse_flightplan ( arg.substr (14) );
912 } else if ( arg.find( "--config=" ) == 0 ) {
913 string file = arg.substr(9);
915 readProperties(file, globals->get_props());
916 } catch (const sg_exception &e) {
917 string message = "Error loading config file: ";
918 message += e.getFormattedMessage();
919 SG_LOG(SG_INPUT, SG_ALERT, message);
922 } else if ( arg.find( "--aircraft=" ) == 0 ) {
923 // read in the top level aircraft definition file
924 SGPath apath( globals->get_fg_root() );
925 apath.append( "Aircraft" );
926 apath.append( arg.substr(11) );
927 apath.concat( "-set.xml" );
929 readProperties( apath.str(), globals->get_props() );
930 } catch (const sg_exception &e) {
931 string message = "Error loading aircraft file: ";
932 message += e.getFormattedMessage();
933 SG_LOG(SG_INPUT, SG_ALERT, message);
937 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
938 return FG_OPTIONS_ERROR;
941 return FG_OPTIONS_OK;
945 // Scan the command line options for an fg_root definition and set
948 fgScanForRoot (int argc, char **argv)
952 SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
955 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
957 string arg = argv[i];
958 if ( arg.find( "--fg-root=" ) == 0 ) {
959 return arg.substr( 10 );
969 // Scan the config file for an fg_root definition and set just that.
971 fgScanForRoot (const string& path)
973 sg_gzifstream in( path );
977 SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
981 while ( ! in.eof() ) {
984 while ( in.get(c) && c != '\0' ) {
989 #if defined( macintosh )
990 getline( in, line, '\r' );
992 getline( in, line, '\n' );
995 // catch extraneous (DOS) line ending character
996 if ( line[line.length() - 1] < 32 ) {
997 line = line.substr( 0, line.length()-1 );
1000 if ( line.find( "--fg-root=" ) == 0 ) {
1001 return line.substr( 10 );
1011 // Parse the command line options
1013 fgParseArgs (int argc, char **argv)
1015 bool in_options = true;
1017 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1019 for (int i = 1; i < argc; i++) {
1020 string arg = argv[i];
1022 if (in_options && (arg.find('-') == 0)) {
1026 int result = parse_option(arg);
1027 if ( (result == FG_OPTIONS_HELP) ||
1028 (result == FG_OPTIONS_ERROR) ) {
1035 SG_LOG(SG_GENERAL, SG_INFO,
1036 "Reading command-line property file " << arg);
1037 readProperties(arg, globals->get_props());
1041 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1045 // Parse config file options
1047 fgParseOptions (const string& path) {
1048 sg_gzifstream in( path );
1049 if ( !in.is_open() ) {
1053 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1057 while ( ! in.eof() ) {
1060 while ( in.get(c) && c != '\0' ) {
1065 #if defined( macintosh )
1066 getline( in, line, '\r' );
1068 getline( in, line, '\n' );
1071 // catch extraneous (DOS) line ending character
1072 if ( line[line.length() - 1] < 32 ) {
1073 line = line.substr( 0, line.length()-1 );
1076 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1077 SG_LOG( SG_GENERAL, SG_ALERT,
1078 "Config file parse error: " << path << " '"
1088 // Print usage message
1092 cout << "Usage: fgfs [ options ... ]" << endl;
1095 cout << "General Options:" << endl;
1096 cout << "\t--help -h: print usage" << endl;
1097 cout << "\t--fg-root=path: specify the root path for all the data files"
1099 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
1101 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1102 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
1103 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1104 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1105 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1106 cout << "\t--disable-intro-music: disable introduction music" << endl;
1107 cout << "\t--enable-intro-music: enable introduction music" << endl;
1108 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1109 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1111 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1112 cout << "\t--disable-freeze: start out in a running state" << endl;
1113 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1114 cout << "\t--disable-fuel-freeze: fuel is consumed normally" << endl;
1115 cout << "\t--enable-fuel-freeze: fuel tanks magically maintain their current contents" << endl;
1116 cout << "\t--control=mode: primary control mode "
1117 << "(joystick, keyboard, mouse)" << endl;
1118 cout << "\t--enable-auto-coordination: enable auto coordination" << endl;
1119 cout << "\t--disable-auto-coordination: disable auto coordination" << endl;
1120 cout << "\t--browser-app=/path/to/app: specify location of your web browser" << endl;
1121 cout << "\t--prop:name=value: set property <name> to <value>" << endl;
1122 cout << "\t--config=path: load additional properties from path" << endl;
1125 cout << "Features:" << endl;
1126 cout << "\t--disable-hud: disable heads up display" << endl;
1127 cout << "\t--enable-hud: enable heads up display" << endl;
1128 cout << "\t--disable-panel: disable instrument panel" << endl;
1129 cout << "\t--enable-panel: enable instrument panel" << endl;
1130 cout << "\t--disable-sound: disable sound effects" << endl;
1131 cout << "\t--enable-sound: enable sound effects" << endl;
1132 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1133 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1136 cout << "Aircraft:" <<endl;
1137 cout << "\t--aircraft=name: select a top level <name>-set.xml file which" << endl;
1138 cout << "\t\twill automatically pull in the correct flight dynamics model," << endl;
1139 cout << "\t\taero specification, external 3d model, instrument panel, sounds," << endl;
1140 cout << "\t\tetc." << endl;
1144 cout << "Flight Model:" << endl;
1145 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1146 cout << "\t\tcan be one of jsb, larcsim, magic, null, external, balloon, or ada"
1148 cout << "\t--aero=abcd: aerodynamics model to load" << endl;
1149 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1151 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1152 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1153 cout << "\t--on-ground: Start up at ground level (default)" << endl;
1154 cout << "\t--in-air: Start up in air (implied by specifying an initial"
1155 << " altitude above ground level." << endl;
1156 cout << "\t--wind=DIR@SPEED: specify wind coming from DIR (degrees) at SPEED (knots)" << endl;
1160 cout <<"Aircraft model directory:" << endl;
1161 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1164 cout << "Initial Position and Orientation:" << endl;
1165 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1167 cout << "\t--offset-distance: specify distance to threshold"
1169 cout << "\t--offset-azimuth: specify heading to threshold (deg) "
1171 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1173 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1175 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1176 cout << "\t\t(unless --units-meters specified)" << endl;
1177 cout << "\t--heading=degrees: heading (yaw) angle in degrees (Psi)"
1179 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1180 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1181 cout << "\t--uBody=feet per second: velocity along the body X axis"
1183 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1185 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1187 cout << "\t\t(unless --units-meters specified)" << endl;
1188 cout << "\t--vc= initial airspeed in knots" << endl;
1189 cout << "\t--mach= initial mach number" << endl;
1192 cout << "Rendering Options:" << endl;
1193 cout << "\t--fog-disable: disable fog/haze" << endl;
1194 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1195 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1196 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1197 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1198 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1199 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1201 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1202 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1203 cout << "\t--shading-flat: enable flat shading" << endl;
1204 cout << "\t--shading-smooth: enable smooth shading" << endl;
1205 cout << "\t--disable-skyblend: disable sky blending" << endl;
1206 cout << "\t--enable-skyblend: enable sky blending" << endl;
1207 cout << "\t--disable-textures: disable textures" << endl;
1208 cout << "\t--enable-textures: enable textures" << endl;
1209 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1210 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1211 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1213 cout << "\t--view-offset=xxx: set the default forward view direction"
1215 cout << "\t\tas an offset from straight ahead. Allowable values are"
1217 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1218 cout << "\t--visibility=xxx: specify initial visibility in meters" << endl;
1219 cout << "\t--visibility-miles=xxx: specify initial visibility in miles"
1223 cout << "Hud Options:" << endl;
1224 cout << "\t--units-feet: Hud displays units in feet" << endl;
1225 cout << "\t--units-meters: Hud displays units in meters" << endl;
1226 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1227 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1231 cout << "Time Options:" << endl;
1232 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1233 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1234 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1235 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1236 << "\t\tFlightGear time" << endl;
1237 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1238 << "\t\tdate/time. Uses your system time " << endl;
1239 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1240 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1241 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1242 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1245 cout << "Network Options:" << endl;
1246 cout << "\t--httpd=port: enable http server on the specified port" << endl;
1247 #ifdef FG_JPEG_SERVER
1248 cout << "\t--jpg-httpd=port: enable screen shot http server on the specified port" << endl;
1250 #ifdef FG_NETWORK_OLK
1251 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1252 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1253 cout << "\t--net-hud: Hud displays network info" << endl;
1254 cout << "\t--net-id=name: specify your own callsign" << endl;
1258 cout << "Route/Way Point Options:" << endl;
1259 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1260 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1262 cout << "\t\tinstances of --wp=" << endl;
1263 cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;