]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
Added keyboard mappings to move panel up/down/right/left.
[flightgear.git] / src / Main / options.cxx
1 // options.cxx -- class to handle command line options
2 //
3 // Written by Curtis Olson, started April 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #if defined(FX) && defined(XMESA)
29 bool global_fullscreen = true;
30 #endif
31
32 #include <simgear/compiler.h>
33
34 #include <math.h>            // rint()
35 #include <stdio.h>
36 #include <stdlib.h>          // atof(), atoi()
37 #include <string.h>
38
39 #include STL_STRING
40
41 #include <simgear/constants.h>
42 #include <simgear/debug/logstream.hxx>
43 #include <simgear/misc/fgstream.hxx>
44 #include <simgear/misc/props.hxx>
45 #include <simgear/timing/sg_time.hxx>
46
47 #include <Include/general.hxx>
48 #include <Cockpit/cockpit.hxx>
49 #include <FDM/flight.hxx>
50 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
51 #ifdef FG_NETWORK_OLK
52 #  include <NetworkOLK/network.h>
53 #endif
54
55 #include "globals.hxx"
56 #include "options.hxx"
57 #include "views.hxx"
58
59 FG_USING_STD(string);
60 FG_USING_NAMESPACE(std);
61
62 // from GLUTmain.cxx
63 extern void fgReshape( int width, int height );
64
65 inline double
66 atof( const string& str )
67 {
68
69 #ifdef __MWERKS__ 
70     // -dw- if ::atof is called, then we get an infinite loop
71     return std::atof( str.c_str() );
72 #else
73     return ::atof( str.c_str() );
74 #endif
75 }
76
77 inline int
78 atoi( const string& str )
79 {
80 #ifdef __MWERKS__ 
81     // -dw- if ::atoi is called, then we get an infinite loop
82     return std::atoi( str.c_str() );
83 #else
84     return ::atoi( str.c_str() );
85 #endif
86 }
87
88
89 // Defined the shared options class here
90 fgOPTIONS current_options;
91
92
93 // Constructor
94 fgOPTIONS::fgOPTIONS() :
95     // starting longitude in degrees (west = -)
96     // starting latitude in degrees (south = -)
97
98     // Default initial position is Globe, AZ (P13)
99     lon(-110.6642444),
100     lat(  33.3528917),
101
102     // North of the city of Globe
103     // lon(-110.7),
104     // lat(  33.4),
105
106     // North of the city of Globe
107     // lon(-110.742578),
108     // lat(  33.507122),
109
110     // Near where I used to live in Globe, AZ
111     // lon(-110.766000),
112     // lat(  33.377778),
113
114     // 10125 Jewell St. NE
115     // lon(-93.15),
116     // lat( 45.15),
117
118     // Near KHSP (Hot Springs, VA)
119     // lon(-79.8338964 + 0.01),
120     // lat( 37.9514564 + 0.008),
121
122     // (SEZ) SEDONA airport
123     // lon(-111.7884614 + 0.01),
124     // lat(  34.8486289 - 0.015),
125
126     // Jim Brennon's Kingmont Observatory
127     // lon(-121.1131667),
128     // lat(  38.8293917),
129
130     // Huaras, Peru (S09d 31.871'  W077d 31.498')
131     // lon(-77.5249667),
132     // lat( -9.5311833),
133  
134     // Eclipse Watching w73.5 n10 (approx) 18:00 UT
135     // lon(-73.5),
136     // lat( 10.0),
137
138     // Timms Hill (WI)
139     // lon(-90.1953055556),
140     // lat( 45.4511388889),
141
142     // starting altitude in meters (this will be reset to ground level
143     // if it is lower than the terrain
144     altitude(-9999.0),
145
146     // Initial Orientation
147     heading(270.0),      // heading (yaw) angle in degress (Psi)
148     roll(0.0),           // roll angle in degrees (Phi)
149     pitch(0.424),        // pitch angle in degrees (Theta)
150
151     // Initialize current options velocities to 0.0
152     uBody(0.0), vBody(0.0), wBody(0.0), vkcas(0.0), mach(0.0),
153
154     // Miscellaneous
155     game_mode(0),
156     splash_screen(1),
157     intro_music(1),
158     mouse_pointer(0),
159     control_mode(FG_JOYSTICK),
160     auto_coordination(FG_AUTO_COORD_NOT_SPECIFIED),
161
162     // Features
163     hud_status(0),
164     panel_status(1),
165     sound(1),
166     anti_alias_hud(0),
167
168     // Flight Model options
169     flight_model( FGInterface::FG_LARCSIM ),
170     aircraft( "c172" ),
171     model_hz( NEW_DEFAULT_MODEL_HZ ),
172     speed_up( 1 ),
173     trim(0),
174
175     // Rendering options
176     fog(FG_FOG_NICEST),  // nicest
177     clouds(false),
178     clouds_asl(5000*FEET_TO_METER),
179     fov(55.0),
180     fullscreen(0),
181     shading(1),
182     skyblend(1),
183     textures(1),
184     wireframe(0),
185     xsize(800),
186     ysize(600),
187     bpp(16),
188     view_mode(FG_VIEW_PILOT),
189
190     // Scenery options
191     tile_diameter(5),
192
193     // HUD options
194     units(FG_UNITS_FEET),
195     tris_or_culled(0),
196         
197     // Time options
198     time_offset(0),
199
200     network_olk(false)
201 {
202     // set initial values/defaults
203     time_offset_type = FG_TIME_SYS_OFFSET;
204     char* envp = ::getenv( "FG_ROOT" );
205
206     if ( envp != NULL ) {
207         // fg_root could be anywhere, so default to environmental
208         // variable $FG_ROOT if it is set.
209         fg_root = envp;
210     } else {
211         // Otherwise, default to a random compiled-in location if
212         // $FG_ROOT is not set.  This can still be overridden from the
213         // command line or a config file.
214
215 #if defined( WIN32 )
216         fg_root = "\\FlightGear";
217 #elif defined( macintosh )
218         fg_root = "";
219 #else
220         fg_root = PKGLIBDIR;
221 #endif
222     }
223
224     // set a possibly independent location for scenery data
225     envp = ::getenv( "FG_SCENERY" );
226
227     if ( envp != NULL ) {
228         // fg_root could be anywhere, so default to environmental
229         // variable $FG_ROOT if it is set.
230         fg_scenery = envp;
231     } else {
232         // Otherwise, default to Scenery being in $FG_ROOT/Scenery
233         fg_scenery = "";
234     }
235
236     airport_id = "KPAO";        // default airport id
237     net_id = "Johnney";         // default pilot's name
238
239     // initialize port config string list
240     channel_options_list.clear();
241 }
242
243 void 
244 fgOPTIONS::toggle_panel() {
245     
246     bool freeze = globals->get_freeze();
247
248     if( !freeze )
249         globals->set_freeze(true);
250     
251     if( panel_status ) {
252         panel_status = false;
253         if ( current_panel != NULL )
254           current_panel->setVisibility(false);
255     } else {
256         panel_status = true;
257         if ( current_panel != NULL )
258           current_panel->setVisibility(true);
259     }
260
261     // new rule .. "fov" shouldn't get messed with like this.
262     /* if ( panel_status ) {
263         fov *= 0.4232;
264     } else {
265         fov *= (1.0 / 0.4232);
266     } */
267
268     // fgReshape( xsize, ysize);
269     fgReshape( current_view.get_winWidth(), current_view.get_winHeight() );
270
271     if( !freeze )
272         globals->set_freeze( false );
273 }
274
275 double
276 fgOPTIONS::parse_time(const string& time_in) {
277     char *time_str, num[256];
278     double hours, minutes, seconds;
279     double result = 0.0;
280     int sign = 1;
281     int i;
282
283     time_str = (char *)time_in.c_str();
284
285     // printf("parse_time(): %s\n", time_str);
286
287     // check for sign
288     if ( strlen(time_str) ) {
289         if ( time_str[0] == '+' ) {
290             sign = 1;
291             time_str++;
292         } else if ( time_str[0] == '-' ) {
293             sign = -1;
294             time_str++;
295         }
296     }
297     // printf("sign = %d\n", sign);
298
299     // get hours
300     if ( strlen(time_str) ) {
301         i = 0;
302         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
303             num[i] = time_str[0];
304             time_str++;
305             i++;
306         }
307         if ( time_str[0] == ':' ) {
308             time_str++;
309         }
310         num[i] = '\0';
311         hours = atof(num);
312         // printf("hours = %.2lf\n", hours);
313
314         result += hours;
315     }
316
317     // get minutes
318     if ( strlen(time_str) ) {
319         i = 0;
320         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
321             num[i] = time_str[0];
322             time_str++;
323             i++;
324         }
325         if ( time_str[0] == ':' ) {
326             time_str++;
327         }
328         num[i] = '\0';
329         minutes = atof(num);
330         // printf("minutes = %.2lf\n", minutes);
331
332         result += minutes / 60.0;
333     }
334
335     // get seconds
336     if ( strlen(time_str) ) {
337         i = 0;
338         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
339             num[i] = time_str[0];
340             time_str++;
341             i++;
342         }
343         num[i] = '\0';
344         seconds = atof(num);
345         // printf("seconds = %.2lf\n", seconds);
346
347         result += seconds / 3600.0;
348     }
349
350     return(sign * result);
351 }
352
353
354 long int fgOPTIONS::parse_date( const string& date)
355 {
356     struct tm gmt;
357     char * date_str, num[256];
358     int i;
359     // initialize to zero
360     gmt.tm_sec = 0;
361     gmt.tm_min = 0;
362     gmt.tm_hour = 0;
363     gmt.tm_mday = 0;
364     gmt.tm_mon = 0;
365     gmt.tm_year = 0;
366     gmt.tm_isdst = 0; // ignore daylight savings time for the moment
367     date_str = (char *)date.c_str();
368     // get year
369     if ( strlen(date_str) ) {
370         i = 0;
371         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
372             num[i] = date_str[0];
373             date_str++;
374             i++;
375         }
376         if ( date_str[0] == ':' ) {
377             date_str++;
378         }
379         num[i] = '\0';
380         gmt.tm_year = atoi(num) - 1900;
381     }
382     // get month
383     if ( strlen(date_str) ) {
384         i = 0;
385         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
386             num[i] = date_str[0];
387             date_str++;
388             i++;
389         }
390         if ( date_str[0] == ':' ) {
391             date_str++;
392         }
393         num[i] = '\0';
394         gmt.tm_mon = atoi(num) -1;
395     }
396     // get day
397     if ( strlen(date_str) ) {
398         i = 0;
399         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
400             num[i] = date_str[0];
401             date_str++;
402             i++;
403         }
404         if ( date_str[0] == ':' ) {
405             date_str++;
406         }
407         num[i] = '\0';
408         gmt.tm_mday = atoi(num);
409     }
410     // get hour
411     if ( strlen(date_str) ) {
412         i = 0;
413         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
414             num[i] = date_str[0];
415             date_str++;
416             i++;
417         }
418         if ( date_str[0] == ':' ) {
419             date_str++;
420         }
421         num[i] = '\0';
422         gmt.tm_hour = atoi(num);
423     }
424     // get minute
425     if ( strlen(date_str) ) {
426         i = 0;
427         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
428             num[i] = date_str[0];
429             date_str++;
430             i++;
431         }
432         if ( date_str[0] == ':' ) {
433             date_str++;
434         }
435         num[i] = '\0';
436         gmt.tm_min = atoi(num);
437     }
438     // get second
439     if ( strlen(date_str) ) {
440         i = 0;
441         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
442             num[i] = date_str[0];
443             date_str++;
444             i++;
445         }
446         if ( date_str[0] == ':' ) {
447             date_str++;
448         }
449         num[i] = '\0';
450         gmt.tm_sec = atoi(num);
451     }
452     time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
453                                    gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
454     //printf ("Date is %s\n", ctime(&theTime));
455     //printf ("in seconds that is %d\n", theTime);
456     //exit(1);
457     return (theTime);
458 }
459
460
461 // parse degree in the form of [+/-]hhh:mm:ss
462 void fgOPTIONS::parse_control( const string& mode ) {
463     if ( mode == "joystick" ) {
464         control_mode = FG_JOYSTICK;
465     } else if ( mode == "mouse" ) {
466         control_mode = FG_MOUSE;
467     } else {
468         control_mode = FG_KEYBOARD;
469     }
470 }
471
472
473 /// parse degree in the form of [+/-]hhh:mm:ss
474 double
475 fgOPTIONS::parse_degree( const string& degree_str) {
476     double result = parse_time( degree_str );
477
478     // printf("Degree = %.4f\n", result);
479
480     return(result);
481 }
482
483
484 // parse time offset command line option
485 int
486 fgOPTIONS::parse_time_offset( const string& time_str) {
487     int result;
488
489     // printf("time offset = %s\n", time_str);
490
491 #ifdef HAVE_RINT
492     result = (int)rint(parse_time(time_str) * 3600.0);
493 #else
494     result = (int)(parse_time(time_str) * 3600.0);
495 #endif
496
497     // printf("parse_time_offset(): %d\n", result);
498
499     return( result );
500 }
501
502
503 // Parse --tile-diameter=n type option 
504
505 int
506 fgOPTIONS::parse_tile_radius( const string& arg ) {
507     int radius = atoi( arg );
508
509     if ( radius < FG_RADIUS_MIN ) { radius = FG_RADIUS_MIN; }
510     if ( radius > FG_RADIUS_MAX ) { radius = FG_RADIUS_MAX; }
511
512     // printf("parse_tile_radius(): radius = %d\n", radius);
513
514     return(radius);
515 }
516
517
518 // Parse --fdm=abcdefg type option 
519 int
520 fgOPTIONS::parse_fdm( const string& fm ) {
521     // cout << "fdm = " << fm << endl;
522
523     if ( fm == "balloon" ) {
524         return FGInterface::FG_BALLOONSIM;
525     } else if ( fm == "external" ) {
526         return FGInterface::FG_EXTERNAL;
527     } else if ( fm == "jsb" ) {
528         return FGInterface::FG_JSBSIM;
529     } else if ( (fm == "larcsim") || (fm == "LaRCsim") ) {
530         return FGInterface::FG_LARCSIM;
531     } else if ( fm == "magic" ) {
532         return FGInterface::FG_MAGICCARPET;
533     } else {
534         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown fdm = " << fm );
535         exit(-1);
536     }
537
538     // we'll never get here, but it makes the compiler happy.
539     return -1;
540 }
541
542
543 // Parse --fov=x.xx type option 
544 double
545 fgOPTIONS::parse_fov( const string& arg ) {
546     double fov = atof(arg);
547
548     if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
549     if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
550
551     // printf("parse_fov(): result = %.4f\n", fov);
552
553     return(fov);
554 }
555
556
557 // Parse I/O channel option
558 //
559 // Format is "--protocol=medium,direction,hz,medium_options,..."
560 //
561 //   protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
562 //   medium = { serial, socket, file, etc. }
563 //   direction = { in, out, bi }
564 //   hz = number of times to process channel per second (floating
565 //        point values are ok.
566 //
567 // Serial example "--nmea=serial,dir,hz,device,baud" where
568 // 
569 //  device = OS device name of serial line to be open()'ed
570 //  baud = {300, 1200, 2400, ..., 230400}
571 //
572 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
573 // 
574 //  machine = machine name or ip address if client (leave empty if server)
575 //  port = port, leave empty to let system choose
576 //  style = tcp or udp
577 //
578 // File example "--garmin=file,dir,hz,filename" where
579 // 
580 //  filename = file system file name
581
582 bool 
583 fgOPTIONS::parse_channel( const string& type, const string& channel_str ) {
584     // cout << "Channel string = " << channel_str << endl;
585
586     channel_options_list.push_back( type + "," + channel_str );
587
588     return true;
589 }
590
591
592 // Parse a single option
593 int fgOPTIONS::parse_option( const string& arg ) {
594     // General Options
595     if ( (arg == "--help") || (arg == "-h") ) {
596         // help/usage request
597         return(FG_OPTIONS_HELP);
598     } else if ( arg == "--disable-game-mode") {
599         game_mode = false;
600     } else if ( arg == "--enable-game-mode" ) {
601         game_mode = true;
602     } else if ( arg == "--disable-splash-screen" ) {
603         splash_screen = false;
604     } else if ( arg == "--enable-splash-screen" ) {
605         splash_screen = true;
606     } else if ( arg == "--disable-intro-music" ) {
607         intro_music = false;
608     } else if ( arg == "--enable-intro-music" ) {
609         intro_music = true;
610     } else if ( arg == "--disable-mouse-pointer" ) {
611         mouse_pointer = 1;
612     } else if ( arg == "--enable-mouse-pointer" ) {
613         mouse_pointer = 2;
614     } else if ( arg == "--disable-freeze" ) {
615         globals->set_freeze( false );
616     } else if ( arg == "--enable-freeze" ) {
617         globals->set_freeze( true );
618     } else if ( arg == "--disable-anti-alias-hud" ) {
619         anti_alias_hud = false; 
620     } else if ( arg == "--enable-anti-alias-hud" ) {
621         anti_alias_hud = true;  
622     } else if ( arg.find( "--control=") != string::npos ) {
623         parse_control( arg.substr(10) );
624     } else if ( arg == "--disable-auto-coordination" ) {
625         auto_coordination = FG_AUTO_COORD_DISABLED;     
626     } else if ( arg == "--enable-auto-coordination" ) {
627         auto_coordination = FG_AUTO_COORD_ENABLED;      
628     } else if ( arg == "--disable-hud" ) {
629         hud_status = false;     
630     } else if ( arg == "--enable-hud" ) {
631         hud_status = true;      
632     } else if ( arg == "--disable-panel" ) {
633         panel_status = false;
634         if ( current_panel != NULL )
635           current_panel->setVisibility(false);
636     } else if ( arg == "--enable-panel" ) {
637         panel_status = true;
638         if ( current_panel != NULL )
639             current_panel->setVisibility(true);
640         // fov *= 0.4232; /* NO!!! */
641     } else if ( arg == "--disable-sound" ) {
642         sound = false;
643     } else if ( arg == "--enable-sound" ) {
644         sound = true;
645     } else if ( arg.find( "--airport-id=") != string::npos ) {
646         airport_id = arg.substr( 13 );
647         current_properties.setStringValue("/position/airport-id", airport_id);
648     } else if ( arg.find( "--lon=" ) != string::npos ) {
649         lon = parse_degree( arg.substr(6) );
650         airport_id = "";
651         current_properties.setDoubleValue("/position/longitude", lon);
652         current_properties.setStringValue("/position/airport-id", airport_id);
653     } else if ( arg.find( "--lat=" ) != string::npos ) {
654         lat = parse_degree( arg.substr(6) );
655         airport_id = "";
656         current_properties.setDoubleValue("/position/latitude", lat);
657         current_properties.setStringValue("/position/airport-id", airport_id);
658     } else if ( arg.find( "--altitude=" ) != string::npos ) {
659         if ( units == FG_UNITS_FEET ) {
660             altitude = atof( arg.substr(11) ) * FEET_TO_METER;
661         } else {
662             altitude = atof( arg.substr(11) );
663         }
664         current_properties.setDoubleValue("/position/altitude", altitude);
665     } else if ( arg.find( "--uBody=" ) != string::npos ) {
666         vkcas=mach=-1;
667         if ( units == FG_UNITS_FEET ) {
668             uBody = atof( arg.substr(8) );
669         } else {
670             uBody = atof( arg.substr(8) ) * FEET_TO_METER;
671         }
672         current_properties.setDoubleValue("/velocities/speed-north", uBody);
673     } else if ( arg.find( "--vBody=" ) != string::npos ) {
674         vkcas=mach=-1;
675         if ( units == FG_UNITS_FEET ) {
676             vBody = atof( arg.substr(8) );
677         } else {
678             vBody = atof( arg.substr(8) ) * FEET_TO_METER;
679         }
680         current_properties.setDoubleValue("/velocities/speed-east", vBody);
681     } else if ( arg.find( "--wBody=" ) != string::npos ) {
682         vkcas=mach=-1;
683         if ( units == FG_UNITS_FEET ) {
684             wBody = atof( arg.substr(8) );
685         } else {
686             wBody = atof( arg.substr(8) ) * FEET_TO_METER;
687         }
688         current_properties.setDoubleValue("/velocities/speed-down", wBody);
689     } else if ( arg.find( "--vc=" ) != string::npos) {
690         mach=-1;
691         vkcas=atof( arg.substr(5) );
692         cout << "Got vc: " << vkcas << endl;
693     } else if ( arg.find( "--mach=" ) != string::npos) {
694         vkcas=-1;
695         mach=atof( arg.substr(7) );
696     } else if ( arg.find( "--heading=" ) != string::npos ) {
697         heading = atof( arg.substr(10) );
698         current_properties.setDoubleValue("/orientation/heading", heading);
699     } else if ( arg.find( "--roll=" ) != string::npos ) {
700         roll = atof( arg.substr(7) );
701         current_properties.setDoubleValue("/orientation/roll", roll);
702     } else if ( arg.find( "--pitch=" ) != string::npos ) {
703         pitch = atof( arg.substr(8) );
704         current_properties.setDoubleValue("/orientation/pitch", pitch);
705     } else if ( arg.find( "--fg-root=" ) != string::npos ) {
706         fg_root = arg.substr( 10 );
707     } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
708         fg_scenery = arg.substr( 13 );
709     } else if ( arg.find( "--fdm=" ) != string::npos ) {
710         flight_model = parse_fdm( arg.substr(6) );
711         current_properties.setIntValue("/sim/flight-model", flight_model);
712     if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
713         set_trim_mode(1);
714     } else {
715         set_trim_mode(0);
716     }        
717     } else if ( arg.find( "--aircraft=" ) != string::npos ) {
718         aircraft = arg.substr(11);
719         current_properties.setStringValue("/sim/aircraft", aircraft);
720     } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
721         aircraft_dir =  arg.substr(15); //  (UIUC)
722     } else if ( arg.find( "--model-hz=" ) != string::npos ) {
723         model_hz = atoi( arg.substr(11) );
724     } else if ( arg.find( "--speed=" ) != string::npos ) {
725         speed_up = atoi( arg.substr(8) );
726     } else if ( arg.find( "--notrim") != string::npos) {
727         trim=-1;
728     } else if ( arg == "--fog-disable" ) {
729         fog = FG_FOG_DISABLED;  
730     } else if ( arg == "--fog-fastest" ) {
731         fog = FG_FOG_FASTEST;   
732     } else if ( arg == "--fog-nicest" ) {
733         fog = FG_FOG_NICEST;    
734     } else if ( arg == "--disable-clouds" ) {
735         clouds = false; 
736     } else if ( arg == "--enable-clouds" ) {
737         clouds = true;  
738     } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
739         if ( units == FG_UNITS_FEET ) {
740             clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
741         } else {
742             clouds_asl = atof( arg.substr(13) );
743         }
744     } else if ( arg.find( "--fov=" ) != string::npos ) {
745         fov = parse_fov( arg.substr(6) );
746     } else if ( arg == "--disable-fullscreen" ) {
747         fullscreen = false;     
748     } else if ( arg== "--enable-fullscreen") {
749         fullscreen = true;      
750     } else if ( arg == "--shading-flat") {
751         shading = 0;    
752     } else if ( arg == "--shading-smooth") {
753         shading = 1;    
754     } else if ( arg == "--disable-skyblend") {
755         skyblend = false;       
756     } else if ( arg== "--enable-skyblend" ) {
757         skyblend = true;        
758     } else if ( arg == "--disable-textures" ) {
759         textures = false;       
760     } else if ( arg == "--enable-textures" ) {
761         textures = true;
762     } else if ( arg == "--disable-wireframe" ) {
763         wireframe = false;      
764     } else if ( arg == "--enable-wireframe" ) {
765         wireframe = true;
766     } else if ( arg.find( "--geometry=" ) != string::npos ) {
767         bool geometry_ok = true;
768         string geometry = arg.substr( 11 );
769         string::size_type i = geometry.find('x');
770
771         if (i != string::npos) {
772             xsize = atoi(geometry.substr(0, i));
773             ysize = atoi(geometry.substr(i+1));
774             // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
775         } else {
776             geometry_ok = false;
777         }
778
779         if ( xsize <= 0 || ysize <= 0 ) {
780             xsize = 640;
781             ysize = 480;
782             geometry_ok = false;
783         }
784
785         if ( !geometry_ok ) {
786             FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
787             FG_LOG( FG_GENERAL, FG_ALERT,
788                     "Setting geometry to " << xsize << 'x' << ysize << '\n');
789         }
790     } else if ( arg.find( "--bpp=" ) != string::npos ) {
791         string bits_per_pix = arg.substr( 6 );
792         if ( bits_per_pix == "16" ) {
793             bpp = 16;
794         } else if ( bits_per_pix == "24" ) {
795             bpp = 24;
796         } else if ( bits_per_pix == "32" ) {
797             bpp = 32;
798         }
799     } else if ( arg == "--units-feet" ) {
800         units = FG_UNITS_FEET;  
801     } else if ( arg == "--units-meters" ) {
802         units = FG_UNITS_METERS;        
803     } else if ( arg.find( "--tile-radius=" ) != string::npos ) {
804         tile_radius = parse_tile_radius( arg.substr(14) );
805         tile_diameter = tile_radius * 2 + 1;
806     } else if ( arg.find( "--time-offset" ) != string::npos ) {
807         time_offset = parse_time_offset( (arg.substr(14)) );
808         //time_offset_type = FG_TIME_SYS_OFFSET;
809     } else if ( arg.find( "--time-match-real") != string::npos ) {
810       //time_offset = parse_time_offset(arg.substr(18));
811         time_offset_type = FG_TIME_SYS_OFFSET;
812     } else if ( arg.find( "--time-match-local") != string::npos ) {
813       //time_offset = parse_time_offset(arg.substr(18));
814         time_offset_type = FG_TIME_LAT_OFFSET;
815     } else if ( arg.find( "--start-date-sys=") != string::npos ) {
816         time_offset = parse_date( (arg.substr(17)) );
817         time_offset_type = FG_TIME_SYS_ABSOLUTE;
818     } else if ( arg.find( "--start-date-lat=") != string::npos ) {
819         time_offset = parse_date( (arg.substr(17)) );
820         time_offset_type = FG_TIME_LAT_ABSOLUTE;
821     } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
822         time_offset = parse_date( (arg.substr(17)) );
823         time_offset_type = FG_TIME_GMT_ABSOLUTE;
824
825     } else if ( arg == "--hud-tris" ) {
826         tris_or_culled = 0;     
827     } else if ( arg == "--hud-culled" ) {
828         tris_or_culled = 1;
829     } else if ( arg.find( "--native=" ) != string::npos ) {
830         parse_channel( "native", arg.substr(9) );
831     } else if ( arg.find( "--garmin=" ) != string::npos ) {
832         parse_channel( "garmin", arg.substr(9) );
833     } else if ( arg.find( "--nmea=" ) != string::npos ) {
834         parse_channel( "nmea", arg.substr(7) );
835     } else if ( arg.find( "--props=" ) != string::npos ) {
836         parse_channel( "props", arg.substr(8) );
837     } else if ( arg.find( "--pve=" ) != string::npos ) {
838         parse_channel( "pve", arg.substr(6) );
839     } else if ( arg.find( "--ray=" ) != string::npos ) {
840         parse_channel( "ray", arg.substr(6) );
841     } else if ( arg.find( "--rul=" ) != string::npos ) {
842         parse_channel( "rul", arg.substr(6) );
843     } else if ( arg.find( "--joyclient=" ) != string::npos ) {
844         parse_channel( "joyclient", arg.substr(12) );
845 #ifdef FG_NETWORK_OLK
846     } else if ( arg == "--disable-network-olk" ) {
847         network_olk = false;    
848     } else if ( arg== "--enable-network-olk") {
849         network_olk = true;     
850     } else if ( arg == "--net-hud" ) {
851         net_hud_display = 1;    
852     } else if ( arg.find( "--net-id=") != string::npos ) {
853         net_id = arg.substr( 9 );
854 #endif
855     } else if ( arg.find( "--prop:" ) == 0 ) {
856         string assign = arg.substr(7);
857         int pos = assign.find('=');
858         if (pos == arg.npos || pos == 0) {
859             FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
860             return FG_OPTIONS_ERROR;
861         }
862         string name = assign.substr(0, pos);
863         string value = assign.substr(pos + 1);
864         current_properties.setStringValue(name.c_str(), value);
865         FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
866                << name << " to \"" << value << '"');
867     } else {
868         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
869         return FG_OPTIONS_ERROR;
870     }
871     
872     return FG_OPTIONS_OK;
873 }
874
875
876 // Scan the command line options for an fg_root definition and set
877 // just that.
878 int fgOPTIONS::scan_command_line_for_root( int argc, char **argv ) {
879     int i = 1;
880     int result;
881
882     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
883
884     while ( i < argc ) {
885         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
886
887         string arg = argv[i];
888         if ( arg.find( "--fg-root=" ) != string::npos ) {
889             fg_root = arg.substr( 10 );
890         }
891
892         i++;
893     }
894     
895     return FG_OPTIONS_OK;
896 }
897
898
899 // Scan the config file for an fg_root definition and set just that.
900 int fgOPTIONS::scan_config_file_for_root( const string& path ) {
901     fg_gzifstream in( path );
902     if ( !in.is_open() )
903         return(FG_OPTIONS_ERROR);
904
905     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
906
907     in >> skipcomment;
908 #ifndef __MWERKS__
909     while ( ! in.eof() ) {
910 #else
911     char c = '\0';
912     while ( in.get(c) && c != '\0' ) {
913         in.putback(c);
914 #endif
915         string line;
916
917 #ifdef GETLINE_NEEDS_TERMINATOR
918         getline( in, line, '\n' );
919 #elif defined( macintosh )
920         getline( in, line, '\r' );
921 #else
922         getline( in, line );
923 #endif
924
925         if ( line.find( "--fg-root=" ) != string::npos ) {
926             fg_root = line.substr( 10 );
927         }
928
929         in >> skipcomment;
930     }
931
932     return FG_OPTIONS_OK;
933 }
934
935
936 // Parse the command line options
937 int fgOPTIONS::parse_command_line( int argc, char **argv ) {
938     int i = 1;
939     int result;
940
941     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
942
943     while ( i < argc ) {
944         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
945
946         result = parse_option(argv[i]);
947         if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
948             return(result);
949         }
950
951         i++;
952     }
953     
954     return FG_OPTIONS_OK;
955 }
956
957
958 // Parse config file options
959 int fgOPTIONS::parse_config_file( const string& path ) {
960     fg_gzifstream in( path );
961     if ( !in.is_open() )
962         return(FG_OPTIONS_ERROR);
963
964     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
965
966     in >> skipcomment;
967 #ifndef __MWERKS__
968     while ( ! in.eof() ) {
969 #else
970     char c = '\0';
971     while ( in.get(c) && c != '\0' ) {
972         in.putback(c);
973 #endif
974         string line;
975
976 #ifdef GETLINE_NEEDS_TERMINATOR
977         getline( in, line, '\n' );
978 #elif defined( macintosh )
979         getline( in, line, '\r' );
980 #else
981         getline( in, line );
982 #endif
983
984         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
985             FG_LOG( FG_GENERAL, FG_ALERT, 
986                     "Config file parse error: " << path << " '" 
987                     << line << "'" );
988             exit(-1);
989         }
990         in >> skipcomment;
991     }
992
993     return FG_OPTIONS_OK;
994 }
995
996
997 // Print usage message
998 void fgOPTIONS::usage ( void ) {
999     cout << "Usage: fg [ options ... ]" << endl;
1000     cout << endl;
1001
1002     cout << "General Options:" << endl;
1003     cout << "\t--help -h:  print usage" << endl;
1004     cout << "\t--fg-root=path:  specify the root path for all the data files"
1005          << endl;
1006     cout << "\t--fg-scenery=path:  specify the base path for all the scenery"
1007          << " data." << endl
1008          << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1009     cout << "\t--disable-game-mode:  disable full-screen game mode" << endl;
1010     cout << "\t--enable-game-mode:  enable full-screen game mode" << endl;
1011     cout << "\t--disable-splash-screen:  disable splash screen" << endl;
1012     cout << "\t--enable-splash-screen:  enable splash screen" << endl;
1013     cout << "\t--disable-intro-music:  disable introduction music" << endl;
1014     cout << "\t--enable-intro-music:  enable introduction music" << endl;
1015     cout << "\t--disable-mouse-pointer:  disable extra mouse pointer" << endl;
1016     cout << "\t--enable-mouse-pointer:  enable extra mouse pointer (i.e. for"
1017          << endl;
1018     cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1019     cout << "\t--disable-freeze:  start out in an running state" << endl;
1020     cout << "\t--enable-freeze:  start out in a frozen state" << endl;
1021     cout << "\t--control=mode:  primary control mode " 
1022          << "(joystick, keyboard, mouse)" << endl;
1023     cout << endl;
1024
1025     cout << "Features:" << endl;
1026     cout << "\t--disable-hud:  disable heads up display" << endl;
1027     cout << "\t--enable-hud:  enable heads up display" << endl;
1028     cout << "\t--disable-panel:  disable instrument panel" << endl;
1029     cout << "\t--enable-panel:  enable instrumetn panel" << endl;
1030     cout << "\t--disable-sound:  disable sound effects" << endl;
1031     cout << "\t--enable-sound:  enable sound effects" << endl;
1032     cout << "\t--disable-anti-alias-hud:  disable anti aliased hud" << endl;
1033     cout << "\t--enable-anti-alias-hud:  enable anti aliased hud" << endl;
1034     cout << endl;
1035  
1036     cout << "Flight Model:" << endl;
1037     cout << "\t--fdm=abcd:  selects the core flight model code." << endl;
1038     cout << "\t\tcan be one of jsb, larcsim, magic, or external" << endl;
1039     cout << "\t--aircraft=abcd:  aircraft model to load" << endl;
1040     cout << "\t--model-hz=n:  run the FDM this rate (iterations per second)" 
1041          << endl;
1042     cout << "\t--speed=n:  run the FDM this much faster than real time" << endl;
1043     cout << "\t--notrim:  Do NOT attempt to trim the model when initializing JSBsim" << endl;
1044     cout << endl;
1045     //(UIUC)
1046     cout <<"Aircraft model directory" << endl;
1047     cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1048     cout << endl;
1049
1050     cout << "Initial Position and Orientation:" << endl;
1051     cout << "\t--airport-id=ABCD:  specify starting postion by airport id" 
1052          << endl;
1053     cout << "\t--lon=degrees:  starting longitude in degrees (west = -)" 
1054          << endl;
1055     cout << "\t--lat=degrees:  starting latitude in degrees (south = -)"
1056          << endl;
1057     cout << "\t--altitude=feet:  starting altitude in feet" << endl;
1058     cout << "\t\t(unless --units-meters specified" << endl;
1059     cout << "\t--heading=degrees:  heading (yaw) angle in degress (Psi)"
1060          << endl;
1061     cout << "\t--roll=degrees:  roll angle in degrees (Phi)" << endl;
1062     cout << "\t--pitch=degrees:  pitch angle in degrees (Theta)" << endl;
1063     cout << "\t--uBody=feet per second:  velocity along the body X axis"
1064          << endl;
1065     cout << "\t--vBody=feet per second:  velocity along the body Y axis"
1066          << endl;
1067     cout << "\t--wBody=feet per second:  velocity along the body Z axis"
1068          << endl;
1069     cout << "\t\t(unless --units-meters specified" << endl;
1070     cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1071     cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1072     cout << endl;
1073
1074     cout << "Rendering Options:" << endl;
1075     cout << "\t--fog-disable:  disable fog/haze" << endl;
1076     cout << "\t--fog-fastest:  enable fastest fog/haze" << endl;
1077     cout << "\t--fog-nicest:  enable nicest fog/haze" << endl;
1078     cout << "\t--enable-clouds:  enable demo cloud layer" << endl;
1079     cout << "\t--disable-clouds:  disable demo cloud layer" << endl;
1080     cout << "\t--clouds-asl=xxx:  specify altitude of cloud layer above sea level" << endl;
1081     cout << "\t--fov=xx.x:  specify initial field of view angle in degrees"
1082          << endl;
1083     cout << "\t--disable-fullscreen:  disable fullscreen mode" << endl;
1084     cout << "\t--enable-fullscreen:  enable fullscreen mode" << endl;
1085     cout << "\t--shading-flat:  enable flat shading" << endl;
1086     cout << "\t--shading-smooth:  enable smooth shading" << endl;
1087     cout << "\t--disable-skyblend:  disable sky blending" << endl;
1088     cout << "\t--enable-skyblend:  enable sky blending" << endl;
1089     cout << "\t--disable-textures:  disable textures" << endl;
1090     cout << "\t--enable-textures:  enable textures" << endl;
1091     cout << "\t--disable-wireframe:  disable wireframe drawing mode" << endl;
1092     cout << "\t--enable-wireframe:  enable wireframe drawing mode" << endl;
1093     cout << "\t--geometry=WWWxHHH:  window geometry: 640x480, 800x600, etc."
1094          << endl;
1095     cout << endl;
1096
1097     cout << "Scenery Options:" << endl;
1098     cout << "\t--tile-radius=n:  specify tile radius, must be 1 - 4" << endl;
1099     cout << endl;
1100
1101     cout << "Hud Options:" << endl;
1102     cout << "\t--units-feet:  Hud displays units in feet" << endl;
1103     cout << "\t--units-meters:  Hud displays units in meters" << endl;
1104     cout << "\t--hud-tris:  Hud displays number of triangles rendered" << endl;
1105     cout << "\t--hud-culled:  Hud displays percentage of triangles culled"
1106          << endl;
1107     cout << endl;
1108         
1109     cout << "Time Options:" << endl;
1110     cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1111     cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1112          << "\t\ttime. Can be used in combination with --time-offset." << endl;
1113     cout << "\t--time-match-local:Synchronize local real-world and " << endl
1114          << "\t\tFlightGear time" << endl;   
1115     cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1116          << "\t\tdate/time. Uses your system time " << endl;
1117     cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1118          << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1119     cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1120          << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1121 #ifdef FG_NETWORK_OLK
1122     cout << "" << endl;
1123
1124     cout << "Network Options:" << endl;
1125     cout << "\t--enable-network-olk:  enable Multipilot mode" << endl;
1126     cout << "\t--disable-network-olk:  disable Multipilot mode (default)" << endl;
1127     cout << "\t--net-hud:  Hud displays network info" << endl;
1128     cout << "\t--net-id=name:  specify your own callsign" << endl;
1129 #endif
1130 }
1131
1132
1133 // Destructor
1134 fgOPTIONS::~fgOPTIONS( void ) {
1135 }