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");
187 fgSetLong("/sim/time/cur-time-override", 0);
189 fgSetBool("/sim/networking/network-olk", false);
190 fgSetString("/sim/networking/call-sign", "Johnny");
193 fgSetBool("/sim/freeze/master", false);
194 fgSetBool("/sim/freeze/position", false);
195 fgSetBool("/sim/freeze/clock", false);
196 fgSetBool("/sim/freeze/fuel", false);
200 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
202 parse_time(const string& time_in) {
203 char *time_str, num[256];
204 double hours, minutes, seconds;
209 time_str = (char *)time_in.c_str();
211 // printf("parse_time(): %s\n", time_str);
214 if ( strlen(time_str) ) {
215 if ( time_str[0] == '+' ) {
218 } else if ( time_str[0] == '-' ) {
223 // printf("sign = %d\n", sign);
226 if ( strlen(time_str) ) {
228 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
229 num[i] = time_str[0];
233 if ( time_str[0] == ':' ) {
238 // printf("hours = %.2lf\n", hours);
244 if ( strlen(time_str) ) {
246 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
247 num[i] = time_str[0];
251 if ( time_str[0] == ':' ) {
256 // printf("minutes = %.2lf\n", minutes);
258 result += minutes / 60.0;
262 if ( strlen(time_str) ) {
264 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
265 num[i] = time_str[0];
271 // printf("seconds = %.2lf\n", seconds);
273 result += seconds / 3600.0;
276 return(sign * result);
280 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
282 parse_date( const string& date)
285 char * date_str, num[256];
287 // initialize to zero
294 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
295 date_str = (char *)date.c_str();
297 if ( strlen(date_str) ) {
299 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
300 num[i] = date_str[0];
304 if ( date_str[0] == ':' ) {
308 gmt.tm_year = atoi(num) - 1900;
311 if ( strlen(date_str) ) {
313 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
314 num[i] = date_str[0];
318 if ( date_str[0] == ':' ) {
322 gmt.tm_mon = atoi(num) -1;
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_mday = atoi(num);
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_hour = atoi(num);
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_min = 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_sec = atoi(num);
380 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
381 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
382 //printf ("Date is %s\n", ctime(&theTime));
383 //printf ("in seconds that is %d\n", theTime);
389 // parse angle in the form of [+/-]ddd:mm:ss into degrees
391 parse_degree( const string& degree_str) {
392 double result = parse_time( degree_str );
394 // printf("Degree = %.4f\n", result);
400 // parse time offset string into seconds
402 parse_time_offset( const string& time_str) {
405 // printf("time offset = %s\n", time_str);
408 result = (int)rint(parse_time(time_str) * 3600.0);
410 result = (int)(parse_time(time_str) * 3600.0);
413 // printf("parse_time_offset(): %d\n", result);
419 // Parse --fov=x.xx type option
421 parse_fov( const string& arg ) {
422 double fov = atof(arg);
424 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
425 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
427 fgSetDouble("/sim/field-of-view", fov);
429 // printf("parse_fov(): result = %.4f\n", fov);
435 // Parse I/O channel option
437 // Format is "--protocol=medium,direction,hz,medium_options,..."
439 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
440 // medium = { serial, socket, file, etc. }
441 // direction = { in, out, bi }
442 // hz = number of times to process channel per second (floating
443 // point values are ok.
445 // Serial example "--nmea=serial,dir,hz,device,baud" where
447 // device = OS device name of serial line to be open()'ed
448 // baud = {300, 1200, 2400, ..., 230400}
450 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
452 // machine = machine name or ip address if client (leave empty if server)
453 // port = port, leave empty to let system choose
454 // style = tcp or udp
456 // File example "--garmin=file,dir,hz,filename" where
458 // filename = file system file name
461 add_channel( const string& type, const string& channel_str ) {
462 // cout << "Channel string = " << channel_str << endl;
464 globals->get_channel_options_list()->push_back( type + "," + channel_str );
470 // Parse --wp=ID[@alt]
472 parse_wp( const string& arg ) {
476 unsigned int pos = arg.find( "@" );
477 if ( pos != string::npos ) {
478 id = arg.substr( 0, pos );
479 alt_str = arg.substr( pos + 1 );
480 // cout << "id str = " << id << " alt str = " << alt_str << endl;
481 alt = atof( alt_str.c_str() );
482 if ( fgGetString("/sim/startup/units") == "feet" ) {
483 alt *= SG_FEET_TO_METER;
490 if ( fgFindAirportID( id, &a ) ) {
491 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
492 globals->get_route()->add_waypoint( wp );
501 // Parse --flight-plan=[file]
503 parse_flightplan(const string& arg)
505 sg_gzifstream in(arg.c_str());
506 if ( !in.is_open() ) {
512 #if defined( macintosh )
513 getline( in, line, '\r' );
515 getline( in, line, '\n' );
518 // catch extraneous (DOS) line ending character
519 if ( line[line.length() - 1] < 32 ) {
520 line = line.substr( 0, line.length()-1 );
533 // Parse a single option
535 parse_option (const string& arg)
538 if ( (arg == "--help") || (arg == "-h") ) {
539 // help/usage request
540 return(FG_OPTIONS_HELP);
541 } else if ( arg == "--disable-game-mode") {
542 fgSetBool("/sim/startup/game-mode", false);
543 } else if ( arg == "--enable-game-mode" ) {
544 fgSetBool("/sim/startup/game-mode", true);
545 } else if ( arg == "--disable-splash-screen" ) {
546 fgSetBool("/sim/startup/splash-screen", false);
547 } else if ( arg == "--enable-splash-screen" ) {
548 fgSetBool("/sim/startup/splash-screen", true);
549 } else if ( arg == "--disable-intro-music" ) {
550 fgSetBool("/sim/startup/intro-music", false);
551 } else if ( arg == "--enable-intro-music" ) {
552 fgSetBool("/sim/startup/intro-music", true);
553 } else if ( arg == "--disable-mouse-pointer" ) {
554 fgSetString("/sim/startup/mouse-pointer", "disabled");
555 } else if ( arg == "--enable-mouse-pointer" ) {
556 fgSetString("/sim/startup/mouse-pointer", "enabled");
557 } else if ( arg == "--disable-freeze" ) {
558 fgSetBool("/sim/freeze/master", false);
559 } else if ( arg == "--enable-freeze" ) {
560 fgSetBool("/sim/freeze/master", true);
561 } else if ( arg == "--disable-fuel-freeze" ) {
562 fgSetBool("/sim/freeze/fuel", false);
563 } else if ( arg == "--enable-fuel-freeze" ) {
564 fgSetBool("/sim/freeze/fuel", true);
565 } else if ( arg == "--disable-clock-freeze" ) {
566 fgSetBool("/sim/freeze/clock", false);
567 } else if ( arg == "--enable-clock-freeze" ) {
568 fgSetBool("/sim/freeze/clock", true);
569 } else if ( arg == "--disable-anti-alias-hud" ) {
570 fgSetBool("/sim/hud/antialiased", false);
571 } else if ( arg == "--enable-anti-alias-hud" ) {
572 fgSetBool("/sim/hud/antialiased", true);
573 } else if ( arg.find( "--control=") == 0 ) {
574 fgSetString("/sim/control-mode", arg.substr(10));
575 } else if ( arg == "--disable-auto-coordination" ) {
576 fgSetBool("/sim/auto-coordination", false);
577 } else if ( arg == "--enable-auto-coordination" ) {
578 fgSetBool("/sim/auto-coordination", true);
579 } else if ( arg.find( "--browser-app=") == 0 ) {
580 fgSetString("/sim/startup/browser-app", arg.substr(14));
581 } else if ( arg == "--disable-hud" ) {
582 fgSetBool("/sim/hud/visibility", false);
583 } else if ( arg == "--enable-hud" ) {
584 fgSetBool("/sim/hud/visibility", true);
585 } else if ( arg == "--disable-panel" ) {
586 fgSetBool("/sim/panel/visibility", false);
587 } else if ( arg == "--enable-panel" ) {
588 fgSetBool("/sim/panel/visibility", true);
589 } else if ( arg == "--disable-sound" ) {
590 fgSetBool("/sim/sound", false);
591 } else if ( arg == "--enable-sound" ) {
592 fgSetBool("/sim/sound", true);
593 } else if ( arg.find( "--airport-id=") == 0 ) {
594 // NB: changed property name!!!
595 fgSetString("/sim/startup/airport-id", arg.substr(13));
596 } else if ( arg.find( "--offset-distance=") == 0 ) {
597 fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
598 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
599 fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17)));
600 } else if ( arg.find( "--lon=" ) == 0 ) {
601 fgSetDouble("/position/longitude-deg",
602 parse_degree(arg.substr(6)));
603 fgSetString("/sim/startup/airport-id", "");
604 } else if ( arg.find( "--lat=" ) == 0 ) {
605 fgSetDouble("/position/latitude-deg",
606 parse_degree(arg.substr(6)));
607 fgSetString("/sim/startup/airport-id", "");
608 } else if ( arg.find( "--altitude=" ) == 0 ) {
609 fgSetBool("/sim/startup/onground", false);
610 if ( fgGetString("/sim/startup/units") == "feet" )
611 fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
613 fgSetDouble("/position/altitude-ft",
614 atof(arg.substr(11)) * SG_METER_TO_FEET);
615 } else if ( arg.find( "--uBody=" ) == 0 ) {
616 fgSetString("/sim/startup/speed-set", "UVW");
617 if ( fgGetString("/sim/startup/units") == "feet" )
618 fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
620 fgSetDouble("/velocities/uBody-fps",
621 atof(arg.substr(8)) * SG_METER_TO_FEET);
622 } else if ( arg.find( "--vBody=" ) == 0 ) {
623 fgSetString("/sim/startup/speed-set", "UVW");
624 if ( fgGetString("/sim/startup/units") == "feet" )
625 fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
627 fgSetDouble("/velocities/vBody-fps",
628 atof(arg.substr(8)) * SG_METER_TO_FEET);
629 } else if ( arg.find( "--wBody=" ) == 0 ) {
630 fgSetString("/sim/startup/speed-set", "UVW");
631 if ( fgGetString("/sim/startup/units") == "feet" )
632 fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
634 fgSetDouble("/velocities/wBody-fps",
635 atof(arg.substr(8)) * SG_METER_TO_FEET);
636 } else if ( arg.find( "--vNorth=" ) == 0 ) {
637 fgSetString("/sim/startup/speed-set", "NED");
638 if ( fgGetString("/sim/startup/units") == "feet" )
639 fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
641 fgSetDouble("/velocities/speed-north-fps",
642 atof(arg.substr(9)) * SG_METER_TO_FEET);
643 } else if ( arg.find( "--vEast=" ) == 0 ) {
644 fgSetString("/sim/startup/speed-set", "NED");
645 if ( fgGetString("/sim/startup/units") == "feet" )
646 fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
648 fgSetDouble("/velocities/speed-east-fps",
649 atof(arg.substr(8)) * SG_METER_TO_FEET);
650 } else if ( arg.find( "--vDown=" ) == 0 ) {
651 fgSetString("/sim/startup/speed-set", "NED");
652 if ( fgGetString("/sim/startup/units") == "feet" )
653 fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
655 fgSetDouble("/velocities/speed-down-fps",
656 atof(arg.substr(8)) * SG_METER_TO_FEET);
657 } else if ( arg.find( "--vc=" ) == 0) {
658 fgSetString("/sim/startup/speed-set", "knots");
659 fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
660 } else if ( arg.find( "--mach=" ) == 0) {
661 fgSetString("/sim/startup/speed-set", "mach");
662 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
663 } else if ( arg.find( "--heading=" ) == 0 ) {
664 fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
665 } else if ( arg.find( "--roll=" ) == 0 ) {
666 fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
667 } else if ( arg.find( "--pitch=" ) == 0 ) {
668 fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
669 } else if ( arg.find( "--fg-root=" ) == 0 ) {
670 globals->set_fg_root(arg.substr( 10 ));
671 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
672 globals->set_fg_scenery(arg.substr( 13 ));
673 } else if ( arg.find( "--fdm=" ) == 0 ) {
674 fgSetString("/sim/flight-model", arg.substr(6));
675 } else if ( arg.find( "--aero=" ) == 0 ) {
676 fgSetString("/sim/aero", arg.substr(7));
677 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
678 fgSetString("/sim/aircraft-dir", arg.substr(15));
679 } else if ( arg.find( "--model-hz=" ) == 0 ) {
680 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
681 } else if ( arg.find( "--speed=" ) == 0 ) {
682 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
683 } else if ( arg.find( "--trim") == 0) {
684 fgSetBool("/sim/startup/trim", true);
685 } else if ( arg.find( "--notrim") == 0) {
686 fgSetBool("/sim/startup/trim", false);
687 } else if ( arg.find( "--on-ground") == 0) {
688 fgSetBool("/sim/startup/onground", true);
689 } else if ( arg.find( "--in-air") == 0) {
690 fgSetBool("/sim/startup/onground", false);
691 } else if ( arg == "--fog-disable" ) {
692 fgSetString("/sim/rendering/fog", "disabled");
693 } else if ( arg == "--fog-fastest" ) {
694 fgSetString("/sim/rendering/fog", "fastest");
695 } else if ( arg == "--fog-nicest" ) {
696 fgSetString("/sim/fog", "nicest");
697 } else if ( arg == "--disable-clouds" ) {
698 fgSetBool("/environment/clouds/status", false);
699 } else if ( arg == "--enable-clouds" ) {
700 fgSetBool("/environment/clouds/status", true);
701 } else if ( arg.find( "--clouds-asl=" ) == 0 ) {
702 // FIXME: check units
703 if ( fgGetString("/sim/startup/units") == "feet" )
704 fgSetDouble("/environment/clouds/altitude-ft",
705 atof(arg.substr(13)));
707 fgSetDouble("/environment/clouds/altitude-ft",
708 atof(arg.substr(13)) * SG_METER_TO_FEET);
709 } else if ( arg.find( "--fov=" ) == 0 ) {
710 parse_fov( arg.substr(6) );
711 } else if ( arg == "--disable-fullscreen" ) {
712 fgSetBool("/sim/startup/fullscreen", false);
713 } else if ( arg== "--enable-fullscreen") {
714 fgSetBool("/sim/startup/fullscreen", true);
715 } else if ( arg == "--shading-flat") {
716 fgSetBool("/sim/rendering/shading", false);
717 } else if ( arg == "--shading-smooth") {
718 fgSetBool("/sim/rendering/shading", true);
719 } else if ( arg == "--disable-skyblend") {
720 fgSetBool("/sim/rendering/skyblend", false);
721 } else if ( arg== "--enable-skyblend" ) {
722 fgSetBool("/sim/rendering/skyblend", true);
723 } else if ( arg == "--disable-textures" ) {
724 fgSetBool("/sim/rendering/textures", false);
725 } else if ( arg == "--enable-textures" ) {
726 fgSetBool("/sim/rendering/textures", true);
727 } else if ( arg == "--disable-wireframe" ) {
728 fgSetBool("/sim/rendering/wireframe", false);
729 } else if ( arg == "--enable-wireframe" ) {
730 fgSetBool("/sim/rendering/wireframe", true);
731 } else if ( arg.find( "--geometry=" ) == 0 ) {
732 bool geometry_ok = true;
733 int xsize = 0, ysize = 0;
734 string geometry = arg.substr( 11 );
735 string::size_type i = geometry.find('x');
737 if (i != string::npos) {
738 xsize = atoi(geometry.substr(0, i));
739 ysize = atoi(geometry.substr(i+1));
744 if ( xsize <= 0 || ysize <= 0 ) {
750 if ( !geometry_ok ) {
751 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
752 SG_LOG( SG_GENERAL, SG_ALERT,
753 "Setting geometry to " << xsize << 'x' << ysize << '\n');
755 SG_LOG( SG_GENERAL, SG_INFO,
756 "Setting geometry to " << xsize << 'x' << ysize << '\n');
757 fgSetInt("/sim/startup/xsize", xsize);
758 fgSetInt("/sim/startup/ysize", ysize);
760 } else if ( arg.find( "--bpp=" ) == 0 ) {
761 string bits_per_pix = arg.substr( 6 );
762 if ( bits_per_pix == "16" ) {
763 fgSetInt("/sim/rendering/bits-per-pixel", 16);
764 } else if ( bits_per_pix == "24" ) {
765 fgSetInt("/sim/rendering/bits-per-pixel", 24);
766 } else if ( bits_per_pix == "32" ) {
767 fgSetInt("/sim/rendering/bits-per-pixel", 32);
769 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
771 } else if ( arg == "--units-feet" ) {
772 fgSetString("/sim/startup/units", "feet");
773 } else if ( arg == "--units-meters" ) {
774 fgSetString("/sim/startup/units", "meters");
775 } else if ( arg.find( "--time-offset" ) == 0 ) {
776 fgSetInt("/sim/startup/time-offset",
777 parse_time_offset( (arg.substr(14)) ));
778 fgSetString("/sim/startup/time-offset-type", "system-offset");
779 } else if ( arg.find( "--time-match-real") == 0 ) {
780 fgSetString("/sim/startup/time-offset-type", "system-offset");
781 } else if ( arg.find( "--time-match-local") == 0 ) {
782 fgSetString("/sim/startup/time-offset-type", "latitude-offset");
783 } else if ( arg.find( "--start-date-sys=") == 0 ) {
784 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
785 fgSetString("/sim/startup/time-offset-type", "system");
786 } else if ( arg.find( "--start-date-lat=") == 0 ) {
787 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
788 fgSetString("/sim/startup/time-offset-type", "latitude");
789 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
790 fgSetInt("/sim/startup/time-offset", 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( "--atc610x" ) == 0 ) {
797 add_channel( "atc610x", "dummy" );
798 } else if ( arg.find( "--atlas=" ) == 0 ) {
799 add_channel( "atlas", arg.substr(8) );
800 } else if ( arg.find( "--httpd=" ) == 0 ) {
801 add_channel( "httpd", arg.substr(8) );
802 #ifdef FG_JPEG_SERVER
803 } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
804 add_channel( "jpg-httpd", arg.substr(12) );
806 } else if ( arg.find( "--native=" ) == 0 ) {
807 add_channel( "native", arg.substr(9) );
808 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
809 add_channel( "native_ctrls", arg.substr(15) );
810 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
811 add_channel( "native_fdm", arg.substr(13) );
812 } else if ( arg.find( "--opengc=" ) == 0 ) {
814 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
815 add_channel( "opengc", arg.substr(9) );
816 } else if ( arg.find( "--garmin=" ) == 0 ) {
817 add_channel( "garmin", arg.substr(9) );
818 } else if ( arg.find( "--nmea=" ) == 0 ) {
819 add_channel( "nmea", arg.substr(7) );
820 } else if ( arg.find( "--props=" ) == 0 ) {
821 add_channel( "props", arg.substr(8) );
822 } else if ( arg.find( "--pve=" ) == 0 ) {
823 add_channel( "pve", arg.substr(6) );
824 } else if ( arg.find( "--ray=" ) == 0 ) {
825 add_channel( "ray", arg.substr(6) );
826 } else if ( arg.find( "--rul=" ) == 0 ) {
827 add_channel( "rul", arg.substr(6) );
828 } else if ( arg.find( "--joyclient=" ) == 0 ) {
829 add_channel( "joyclient", arg.substr(12) );
830 #ifdef FG_NETWORK_OLK
831 } else if ( arg == "--disable-network-olk" ) {
832 fgSetBool("/sim/networking/olk", false);
833 } else if ( arg== "--enable-network-olk") {
834 fgSetBool("/sim/networking/olk", true);
835 } else if ( arg == "--net-hud" ) {
836 fgSetBool("/sim/hud/net-display", true);
837 net_hud_display = 1; // FIXME
838 } else if ( arg.find( "--net-id=") == 0 ) {
839 fgSetString("sim/networking/call-sign", arg.substr(9));
841 } else if ( arg.find( "--prop:" ) == 0 ) {
842 string assign = arg.substr(7);
843 unsigned int pos = assign.find('=');
844 if ( pos == arg.npos || pos == 0 ) {
845 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
846 return FG_OPTIONS_ERROR;
848 string name = assign.substr(0, pos);
849 string value = assign.substr(pos + 1);
850 fgSetString(name.c_str(), value);
851 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
852 // << name << " to \"" << value << '"');
853 } else if ( arg.find("--trace-read=") == 0) {
854 string name = arg.substr(13);
855 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
856 fgGetNode(name, true)->setAttribute(SGPropertyNode::TRACE_READ, true);
857 } else if ( arg.find("--trace-write=") == 0) {
858 string name = arg.substr(14);
859 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
860 fgGetNode(name, true)->setAttribute(SGPropertyNode::TRACE_WRITE, true);
861 } else if ( arg.find( "--view-offset=" ) == 0 ) {
862 // $$$ begin - added VS Renganathan, 14 Oct 2K
863 // for multi-window outside window imagery
864 string woffset = arg.substr( 14 );
865 double default_view_offset = 0.0;
866 if ( woffset == "LEFT" ) {
867 default_view_offset = SGD_PI * 0.25;
868 } else if ( woffset == "RIGHT" ) {
869 default_view_offset = SGD_PI * 1.75;
870 } else if ( woffset == "CENTER" ) {
871 default_view_offset = 0.00;
873 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
875 FGViewerRPH *pilot_view =
876 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
877 pilot_view->set_view_offset( default_view_offset );
878 pilot_view->set_goal_view_offset( default_view_offset );
879 fgSetDouble("/sim/view/offset-deg", default_view_offset);
880 // $$$ end - added VS Renganathan, 14 Oct 2K
881 } else if ( arg.find( "--visibility=" ) == 0 ) {
882 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
883 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
884 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
885 fgSetDouble("/environment/visibility-m", visibility);
886 } else if ( arg.find( "--wind=" ) == 0 ) {
887 string val = arg.substr(7);
888 unsigned int pos = val.find('@');
889 if ( pos == string::npos ) {
890 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << val );
891 return FG_OPTIONS_ERROR;
893 double dir = atof(val.substr(0,pos).c_str());
894 double speed = atof(val.substr(pos+1).c_str());
895 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << dir << '@' <<
896 speed << " knots" << endl);
897 fgSetDouble("/environment/wind-from-heading-deg", dir);
898 fgSetDouble("/environment/wind-speed-knots", speed);
901 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
905 dir *= SGD_DEGREES_TO_RADIANS;
906 fgSetDouble("/environment/wind-north-fps",
908 fgSetDouble("/environment/wind-east-fps",
910 } else if ( arg.find( "--wp=" ) == 0 ) {
911 parse_wp( arg.substr( 5 ) );
912 } else if ( arg.find( "--flight-plan=") == 0) {
913 parse_flightplan ( arg.substr (14) );
914 } else if ( arg.find( "--config=" ) == 0 ) {
915 string file = arg.substr(9);
917 readProperties(file, globals->get_props());
918 } catch (const sg_exception &e) {
919 string message = "Error loading config file: ";
920 message += e.getFormattedMessage();
921 SG_LOG(SG_INPUT, SG_ALERT, message);
924 } else if ( arg.find( "--aircraft=" ) == 0 ) {
925 // read in the top level aircraft definition file
926 SGPath apath( globals->get_fg_root() );
927 apath.append( "Aircraft" );
928 apath.append( arg.substr(11) );
929 apath.concat( "-set.xml" );
931 readProperties( apath.str(), globals->get_props() );
932 } catch (const sg_exception &e) {
933 string message = "Error loading aircraft file: ";
934 message += e.getFormattedMessage();
935 SG_LOG(SG_INPUT, SG_ALERT, message);
939 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
940 return FG_OPTIONS_ERROR;
943 return FG_OPTIONS_OK;
947 // Scan the command line options for an fg_root definition and set
950 fgScanForRoot (int argc, char **argv)
954 SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
957 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
959 string arg = argv[i];
960 if ( arg.find( "--fg-root=" ) == 0 ) {
961 return arg.substr( 10 );
971 // Scan the config file for an fg_root definition and set just that.
973 fgScanForRoot (const string& path)
975 sg_gzifstream in( path );
979 SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
983 while ( ! in.eof() ) {
986 while ( in.get(c) && c != '\0' ) {
991 #if defined( macintosh )
992 getline( in, line, '\r' );
994 getline( in, line, '\n' );
997 // catch extraneous (DOS) line ending character
998 if ( line[line.length() - 1] < 32 ) {
999 line = line.substr( 0, line.length()-1 );
1002 if ( line.find( "--fg-root=" ) == 0 ) {
1003 return line.substr( 10 );
1013 // Parse the command line options
1015 fgParseArgs (int argc, char **argv)
1017 bool in_options = true;
1019 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1021 for (int i = 1; i < argc; i++) {
1022 string arg = argv[i];
1024 if (in_options && (arg.find('-') == 0)) {
1028 int result = parse_option(arg);
1029 if ( (result == FG_OPTIONS_HELP) ||
1030 (result == FG_OPTIONS_ERROR) ) {
1037 SG_LOG(SG_GENERAL, SG_INFO,
1038 "Reading command-line property file " << arg);
1039 readProperties(arg, globals->get_props());
1043 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1047 // Parse config file options
1049 fgParseOptions (const string& path) {
1050 sg_gzifstream in( path );
1051 if ( !in.is_open() ) {
1055 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1059 while ( ! in.eof() ) {
1062 while ( in.get(c) && c != '\0' ) {
1067 #if defined( macintosh )
1068 getline( in, line, '\r' );
1070 getline( in, line, '\n' );
1073 // catch extraneous (DOS) line ending character
1074 if ( line[line.length() - 1] < 32 ) {
1075 line = line.substr( 0, line.length()-1 );
1078 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1079 SG_LOG( SG_GENERAL, SG_ALERT,
1080 "Config file parse error: " << path << " '"
1090 // Print usage message
1094 cout << "Usage: fgfs [ option ... ]" << endl
1097 << "General Options:" << endl
1098 << " --help, -h Print usage" << endl
1099 << " --fg-root=path Specify the root data path" << endl
1100 << " --fg-scenery=path Specify the base scenery path;" << endl
1101 << " Defaults to $FG_ROOT/Scenery" << endl
1102 << " --disable-game-mode Disable full-screen game mode" << endl
1103 << " --enable-game-mode Enable full-screen game mode" << endl
1104 << " --disable-splash-screen Disable splash screen" << endl
1105 << " --enable-splash-screen Enable splash screen" << endl
1106 << " --disable-intro-music Disable introduction music" << endl
1107 << " --enable-intro-music Enable introduction music" << endl
1108 << " --disable-mouse-pointer Disable extra mouse pointer" << endl
1109 << " --enable-mouse-pointer Enable extra mouse pointer (i.e. for full-" << endl
1110 << " screen Voodoo based cards)" << endl
1111 << " --disable-freeze Start in a running state" << endl
1112 << " --enable-freeze Start in a frozen state" << endl
1113 << " --disable-fuel-freeze Fuel is consumed normally" << endl
1114 << " --enable-fuel-freeze Fuel tank quantity forced to remain constant" << endl
1115 << " --disable-clock-freeze Clock advances normally" << endl
1116 << " --enable-clock-freeze Do not advance clock" << endl
1117 << " --control=mode Primary control mode (joystick, keyboard," << endl
1118 << " mouse)" << endl
1119 << " --enable-auto-coordination Enable auto coordination" << endl
1120 << " --disable-auto-coordination Disable auto coordination" << endl
1121 << " --browser-app=path Specify path to your web browser" << endl
1122 << " --prop:name=value Set property <name> to <value>" << endl
1123 << " --config=path Load additional properties from path" << endl
1124 << " --units-feet Use feet for distances" << endl
1125 << " --units-meters Use meters for distances" << endl
1128 << "Features:" << endl
1129 << " --disable-hud Disable Heads Up Display (HUD)" << endl
1130 << " --enable-hud Enable Heads Up Display (HUD)" << endl
1131 << " --disable-panel Disable instrument panel" << endl
1132 << " --enable-panel Enable instrument panel" << endl
1133 << " --disable-sound Disable sound effects" << endl
1134 << " --enable-sound Enable sound effects" << endl
1135 << " --disable-anti-alias-hud Disable anti-aliased HUD" << endl
1136 << " --enable-anti-alias-hud Enable anti-aliased HUD" << endl
1139 << "Aircraft:" <<endl
1140 << " --aircraft=name Select an aircraft profile as defined by a" << endl
1141 << " top level <name>-set.xml" << endl
1144 << "Flight Model:" << endl
1145 << " --fdm=name Select the core flight dynamics model" << endl
1146 << " Can be one of jsb, larcsim, yasim, magic," << endl
1147 << " balloon, ada, external, or null" << endl
1148 << " --aero=name Select aircraft aerodynamics model to load" << endl
1149 << " --model-hz=n Run the FDM this rate (iterations per" << endl
1150 << " second)" << endl
1151 << " --speed=n Run the FDM 'n' times faster than real time" << endl
1152 << " --notrim Do NOT attempt to trim the model (only with" << endl
1153 << " fdm=jsbsim)" << endl
1154 << " --on-ground Start at ground level (default)" << endl
1155 << " --in-air Start in air (implied when using --altitude)" << endl
1156 << " --wind=DIR@SPEED Specify wind coming from DIR (degrees) at" << endl
1157 << " SPEED (knots)" << endl
1160 << "Aircraft model directory (UIUC FDM ONLY):" << endl
1161 << " --aircraft-dir=path Aircraft directory relative to the path of" << endl
1162 << " the executable" << endl
1165 << "Initial Position and Orientation:" << endl
1166 << " --airport-id=ID Specify starting position by airport ID" << endl
1167 << " --offset-distance=nm Specify distance to threshold" << endl
1168 << " --offset-azimuth=degrees Specify heading to threshold" << endl
1169 << " --lon=degrees Starting longitude (west = -)" << endl
1170 << " --lat=degrees Starting latitude (south = -)" << endl
1171 << " --altitude=value Starting altitude (in feet unless" << endl
1172 << " --units-meters specified)" << endl
1173 << " --heading=degrees Specify heading (yaw) angle (Psi)" << endl
1174 << " --roll=degrees Specify roll angle (Phi)" << endl
1175 << " --pitch=degrees Specify pitch angle (Theta)" << endl
1176 << " --uBody=units_per_sec Specify velocity along the body X axis" << endl
1177 << " (in feet unless --units-meters specified)" << endl
1178 << " --vBody=units_per_sec Specify velocity along the body Y axis" << endl
1179 << " (in feet unless --units-meters specified)" << endl
1180 << " --wBody=units_per_sec Specify velocity along the body Z axis" << endl
1181 << " (in feet unless --units-meters specified)" << endl
1182 << " --vc=knots Specify initial airspeed" << endl
1183 << " --mach=num Specify initial mach number" << endl
1186 << "Rendering Options:" << endl
1187 << " --bpp=depth Specify the bits per pixel" << endl
1188 << " --fog-disable Disable fog/haze" << endl
1189 << " --fog-fastest Enable fastest fog/haze" << endl
1190 << " --fog-nicest Enable nicest fog/haze" << endl
1191 << " --enable-clouds Enable cloud layers" << endl
1192 << " --disable-clouds Disable cloud layers" << endl
1193 << " --clouds-asl=altitude Specify altitude of cloud layer above sea" << endl
1195 << " --fov=degrees Specify field of view angle" << endl
1196 << " --disable-fullscreen Disable fullscreen mode" << endl
1197 << " --enable-fullscreen Enable fullscreen mode" << endl
1198 << " --shading-flat Enable flat shading" << endl
1199 << " --shading-smooth Enable smooth shading" << endl
1200 << " --disable-skyblend Disable sky blending" << endl
1201 << " --enable-skyblend Enable sky blending" << endl
1202 << " --disable-textures Disable textures" << endl
1203 << " --enable-textures Enable textures" << endl
1204 << " --disable-wireframe Disable wireframe drawing mode" << endl
1205 << " --enable-wireframe Enable wireframe drawing mode" << endl
1206 << " --geometry=WxH Specify window geometry (640x480, etc)" << endl
1207 << " --view-offset=value Specify the default forward view direction" << endl
1208 << " as an offset from straight ahead. Allowable" << endl
1209 << " values are LEFT, RIGHT, CENTER, or a specific" << endl
1210 << " number in degrees" << endl
1211 << " --visibility=meters Specify initial visibility" << endl
1212 << " --visibility-miles=miles Specify initial visibility in miles" << endl
1215 << "Hud Options:" << endl
1216 << " --hud-tris Hud displays number of triangles rendered" << endl
1217 << " --hud-culled Hud displays percentage of triangles culled" << endl
1220 << "Time Options:" << endl
1221 << " --time-offset=[+-]hh:mm:ss Add this time offset" << endl
1222 << " --time-match-real Synchronize time with real-world time" << endl
1223 << " --time-match-local Synchronize time with local real-world time" << endl
1224 << " --start-date-sys=yyyy:mm:dd:hh:mm:ss" << endl
1225 << " Specify a starting date/time with respect to" << endl
1226 << " system time" << endl
1227 << " --start-date-gmt=yyyy:mm:dd:hh:mm:ss" << endl
1228 << " Specify a starting date/time with respect to" << endl
1229 << " Greenwich Mean Time" << endl
1230 << " --start-date-lat=yyyy:mm:dd:hh:mm:ss" << endl
1231 << " Specify a starting date/time with respect to" << endl
1232 << " Local Aircraft Time" << endl
1235 << "Network Options:" << endl
1236 << " --httpd=port Enable http server on the specified port" << endl
1237 #ifdef FG_JPEG_SERVER
1238 << " --jpg-httpd=port Enable screen shot http server on the" << endl
1239 << " specified port" << endl
1241 #ifdef FG_NETWORK_OLK
1242 << " --disable-network-olk Disable Multipilot mode (default)" << endl
1243 << " --enable-network-olk Enable Multipilot mode" << endl
1244 << " --net-hud Hud displays network info" << endl
1245 << " --net-id=name Specify your own callsign" << endl
1249 << "Route/Way Point Options:" << endl
1250 << " --wp=ID[@alt] Specify a waypoint for the GC autopilot;" << endl
1251 << " multiple instances can be used to create a" << endl
1253 << " --flight-plan=file Read all waypoints from a file" << endl
1256 << "IO Options:" << endl
1257 << " --gamin=params Open connection using the Garmin GPS protocol" << endl
1258 << " --joyclient=params Open connection to an Agwagon joystick" << endl
1259 << " --native-ctrls=params Open connection using the FG Native Controls" << endl
1260 << " protocol" << endl
1261 << " --native-fdm=params Open connection using the FG Native FDM" << endl
1262 << " protocol" << endl
1263 << " --native=params Open connection using the FG Native protocol" << endl
1264 << " --nmea=params Open connection using the NMEA protocol" << endl
1265 << " --opengc=params Open connection using the OpenGC protocol" << endl
1266 << " --props=params Open connection using the interactive" << endl
1267 << " property manager" << endl
1268 << " --pve=params Open connection using the PVE protocol" << endl
1269 << " --ray=params Open connection using the RayWoodworth" << endl
1270 << " motion chair protocol" << endl
1271 << " --rul=params Open connection using the RUL protocol" << endl
1273 << " --atc610x Enable atc610x interface." << endl
1276 << "Debugging Options:" << endl
1277 << " --trace-read=property Trace the reads for a property; multiple" << endl
1278 << " instances allowed." << endl
1279 << " --trace-write=property Trace the writes for a property; multiple" << endl
1280 << " instances allowed." << endl