]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
Autopilot altitude increment fixes.
[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(1),
164     panel_status(0),
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(640),
186     ysize(480),
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( MACOS )
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 = "";            // 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     if ( panel_status ) {
261         fov *= 0.4232;
262     } else {
263         fov *= (1.0 / 0.4232);
264     }
265     // fgReshape( xsize, ysize);
266     fgReshape( current_view.get_winWidth(), current_view.get_winHeight() );
267
268     if( !freeze )
269         globals->set_freeze( false );
270 }
271
272 double
273 fgOPTIONS::parse_time(const string& time_in) {
274     char *time_str, num[256];
275     double hours, minutes, seconds;
276     double result = 0.0;
277     int sign = 1;
278     int i;
279
280     time_str = (char *)time_in.c_str();
281
282     // printf("parse_time(): %s\n", time_str);
283
284     // check for sign
285     if ( strlen(time_str) ) {
286         if ( time_str[0] == '+' ) {
287             sign = 1;
288             time_str++;
289         } else if ( time_str[0] == '-' ) {
290             sign = -1;
291             time_str++;
292         }
293     }
294     // printf("sign = %d\n", sign);
295
296     // get hours
297     if ( strlen(time_str) ) {
298         i = 0;
299         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
300             num[i] = time_str[0];
301             time_str++;
302             i++;
303         }
304         if ( time_str[0] == ':' ) {
305             time_str++;
306         }
307         num[i] = '\0';
308         hours = atof(num);
309         // printf("hours = %.2lf\n", hours);
310
311         result += hours;
312     }
313
314     // get minutes
315     if ( strlen(time_str) ) {
316         i = 0;
317         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
318             num[i] = time_str[0];
319             time_str++;
320             i++;
321         }
322         if ( time_str[0] == ':' ) {
323             time_str++;
324         }
325         num[i] = '\0';
326         minutes = atof(num);
327         // printf("minutes = %.2lf\n", minutes);
328
329         result += minutes / 60.0;
330     }
331
332     // get seconds
333     if ( strlen(time_str) ) {
334         i = 0;
335         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
336             num[i] = time_str[0];
337             time_str++;
338             i++;
339         }
340         num[i] = '\0';
341         seconds = atof(num);
342         // printf("seconds = %.2lf\n", seconds);
343
344         result += seconds / 3600.0;
345     }
346
347     return(sign * result);
348 }
349
350
351 long int fgOPTIONS::parse_date( const string& date)
352 {
353     struct tm gmt;
354     char * date_str, num[256];
355     int i;
356     // initialize to zero
357     gmt.tm_sec = 0;
358     gmt.tm_min = 0;
359     gmt.tm_hour = 0;
360     gmt.tm_mday = 0;
361     gmt.tm_mon = 0;
362     gmt.tm_year = 0;
363     gmt.tm_isdst = 0; // ignore daylight savings time for the moment
364     date_str = (char *)date.c_str();
365     // get year
366     if ( strlen(date_str) ) {
367         i = 0;
368         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
369             num[i] = date_str[0];
370             date_str++;
371             i++;
372         }
373         if ( date_str[0] == ':' ) {
374             date_str++;
375         }
376         num[i] = '\0';
377         gmt.tm_year = atoi(num) - 1900;
378     }
379     // get month
380     if ( strlen(date_str) ) {
381         i = 0;
382         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
383             num[i] = date_str[0];
384             date_str++;
385             i++;
386         }
387         if ( date_str[0] == ':' ) {
388             date_str++;
389         }
390         num[i] = '\0';
391         gmt.tm_mon = atoi(num) -1;
392     }
393     // get day
394     if ( strlen(date_str) ) {
395         i = 0;
396         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
397             num[i] = date_str[0];
398             date_str++;
399             i++;
400         }
401         if ( date_str[0] == ':' ) {
402             date_str++;
403         }
404         num[i] = '\0';
405         gmt.tm_mday = atoi(num);
406     }
407     // get hour
408     if ( strlen(date_str) ) {
409         i = 0;
410         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
411             num[i] = date_str[0];
412             date_str++;
413             i++;
414         }
415         if ( date_str[0] == ':' ) {
416             date_str++;
417         }
418         num[i] = '\0';
419         gmt.tm_hour = atoi(num);
420     }
421     // get minute
422     if ( strlen(date_str) ) {
423         i = 0;
424         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
425             num[i] = date_str[0];
426             date_str++;
427             i++;
428         }
429         if ( date_str[0] == ':' ) {
430             date_str++;
431         }
432         num[i] = '\0';
433         gmt.tm_min = atoi(num);
434     }
435     // get second
436     if ( strlen(date_str) ) {
437         i = 0;
438         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
439             num[i] = date_str[0];
440             date_str++;
441             i++;
442         }
443         if ( date_str[0] == ':' ) {
444             date_str++;
445         }
446         num[i] = '\0';
447         gmt.tm_sec = atoi(num);
448     }
449     time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
450                                    gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
451     //printf ("Date is %s\n", ctime(&theTime));
452     //printf ("in seconds that is %d\n", theTime);
453     //exit(1);
454     return (theTime);
455 }
456
457
458 // parse degree in the form of [+/-]hhh:mm:ss
459 void fgOPTIONS::parse_control( const string& mode ) {
460     if ( mode == "joystick" ) {
461         control_mode = FG_JOYSTICK;
462     } else if ( mode == "mouse" ) {
463         control_mode = FG_MOUSE;
464     } else {
465         control_mode = FG_KEYBOARD;
466     }
467 }
468
469
470 /// parse degree in the form of [+/-]hhh:mm:ss
471 double
472 fgOPTIONS::parse_degree( const string& degree_str) {
473     double result = parse_time( degree_str );
474
475     // printf("Degree = %.4f\n", result);
476
477     return(result);
478 }
479
480
481 // parse time offset command line option
482 int
483 fgOPTIONS::parse_time_offset( const string& time_str) {
484     int result;
485
486     // printf("time offset = %s\n", time_str);
487
488 #ifdef HAVE_RINT
489     result = (int)rint(parse_time(time_str) * 3600.0);
490 #else
491     result = (int)(parse_time(time_str) * 3600.0);
492 #endif
493
494     // printf("parse_time_offset(): %d\n", result);
495
496     return( result );
497 }
498
499
500 // Parse --tile-diameter=n type option 
501
502 int
503 fgOPTIONS::parse_tile_radius( const string& arg ) {
504     int radius = atoi( arg );
505
506     if ( radius < FG_RADIUS_MIN ) { radius = FG_RADIUS_MIN; }
507     if ( radius > FG_RADIUS_MAX ) { radius = FG_RADIUS_MAX; }
508
509     // printf("parse_tile_radius(): radius = %d\n", radius);
510
511     return(radius);
512 }
513
514
515 // Parse --fdm=abcdefg type option 
516 int
517 fgOPTIONS::parse_fdm( const string& fm ) {
518     // cout << "fdm = " << fm << endl;
519
520     if ( fm == "balloon" ) {
521         return FGInterface::FG_BALLOONSIM;
522     } else if ( fm == "external" ) {
523         return FGInterface::FG_EXTERNAL;
524     } else if ( fm == "jsb" ) {
525         return FGInterface::FG_JSBSIM;
526     } else if ( (fm == "larcsim") || (fm == "LaRCsim") ) {
527         return FGInterface::FG_LARCSIM;
528     } else if ( fm == "magic" ) {
529         return FGInterface::FG_MAGICCARPET;
530     } else {
531         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown fdm = " << fm );
532         exit(-1);
533     }
534
535     // we'll never get here, but it makes the compiler happy.
536     return -1;
537 }
538
539
540 // Parse --fov=x.xx type option 
541 double
542 fgOPTIONS::parse_fov( const string& arg ) {
543     double fov = atof(arg);
544
545     if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
546     if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
547
548     // printf("parse_fov(): result = %.4f\n", fov);
549
550     return(fov);
551 }
552
553
554 // Parse I/O channel option
555 //
556 // Format is "--protocol=medium,direction,hz,medium_options,..."
557 //
558 //   protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
559 //   medium = { serial, socket, file, etc. }
560 //   direction = { in, out, bi }
561 //   hz = number of times to process channel per second (floating
562 //        point values are ok.
563 //
564 // Serial example "--nmea=serial,dir,hz,device,baud" where
565 // 
566 //  device = OS device name of serial line to be open()'ed
567 //  baud = {300, 1200, 2400, ..., 230400}
568 //
569 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
570 // 
571 //  machine = machine name or ip address if client (leave empty if server)
572 //  port = port, leave empty to let system choose
573 //  style = tcp or udp
574 //
575 // File example "--garmin=file,dir,hz,filename" where
576 // 
577 //  filename = file system file name
578
579 bool 
580 fgOPTIONS::parse_channel( const string& type, const string& channel_str ) {
581     // cout << "Channel string = " << channel_str << endl;
582
583     channel_options_list.push_back( type + "," + channel_str );
584
585     return true;
586 }
587
588
589 // Parse a single option
590 int fgOPTIONS::parse_option( const string& arg ) {
591     // General Options
592     if ( (arg == "--help") || (arg == "-h") ) {
593         // help/usage request
594         return(FG_OPTIONS_HELP);
595     } else if ( arg == "--disable-game-mode") {
596         game_mode = false;
597     } else if ( arg == "--enable-game-mode" ) {
598         game_mode = true;
599     } else if ( arg == "--disable-splash-screen" ) {
600         splash_screen = false;
601     } else if ( arg == "--enable-splash-screen" ) {
602         splash_screen = true;
603     } else if ( arg == "--disable-intro-music" ) {
604         intro_music = false;
605     } else if ( arg == "--enable-intro-music" ) {
606         intro_music = true;
607     } else if ( arg == "--disable-mouse-pointer" ) {
608         mouse_pointer = 1;
609     } else if ( arg == "--enable-mouse-pointer" ) {
610         mouse_pointer = 2;
611     } else if ( arg == "--disable-freeze" ) {
612         globals->set_freeze( false );
613     } else if ( arg == "--enable-freeze" ) {
614         globals->set_freeze( true );
615     } else if ( arg == "--disable-anti-alias-hud" ) {
616         anti_alias_hud = false; 
617     } else if ( arg == "--enable-anti-alias-hud" ) {
618         anti_alias_hud = true;  
619     } else if ( arg.find( "--control=") != string::npos ) {
620         parse_control( arg.substr(10) );
621     } else if ( arg == "--disable-auto-coordination" ) {
622         auto_coordination = FG_AUTO_COORD_DISABLED;     
623     } else if ( arg == "--enable-auto-coordination" ) {
624         auto_coordination = FG_AUTO_COORD_ENABLED;      
625     } else if ( arg == "--disable-hud" ) {
626         hud_status = false;     
627     } else if ( arg == "--enable-hud" ) {
628         hud_status = true;      
629     } else if ( arg == "--disable-panel" ) {
630         panel_status = false;
631         if ( current_panel != NULL )
632           current_panel->setVisibility(false);
633     } else if ( arg == "--enable-panel" ) {
634         panel_status = true;
635         if ( current_panel != NULL )
636           current_panel->setVisibility(true);
637         fov *= 0.4232;
638     } else if ( arg == "--disable-sound" ) {
639         sound = false;
640     } else if ( arg == "--enable-sound" ) {
641         sound = true;
642     } else if ( arg.find( "--airport-id=") != string::npos ) {
643         airport_id = arg.substr( 13 );
644     } else if ( arg.find( "--lon=" ) != string::npos ) {
645         lon = parse_degree( arg.substr(6) );
646     } else if ( arg.find( "--lat=" ) != string::npos ) {
647         lat = parse_degree( arg.substr(6) );
648     } else if ( arg.find( "--altitude=" ) != string::npos ) {
649         if ( units == FG_UNITS_FEET ) {
650             altitude = atof( arg.substr(11) ) * FEET_TO_METER;
651         } else {
652             altitude = atof( arg.substr(11) );
653         }
654     } else if ( arg.find( "--uBody=" ) != string::npos ) {
655         vkcas=mach=-1;
656         if ( units == FG_UNITS_FEET ) {
657             uBody = atof( arg.substr(8) );
658         } else {
659             uBody = atof( arg.substr(8) ) * FEET_TO_METER;
660         }
661     } else if ( arg.find( "--vBody=" ) != string::npos ) {
662         vkcas=mach=-1;
663         if ( units == FG_UNITS_FEET ) {
664             vBody = atof( arg.substr(8) );
665         } else {
666             vBody = atof( arg.substr(8) ) * FEET_TO_METER;
667         }
668     } else if ( arg.find( "--wBody=" ) != string::npos ) {
669         vkcas=mach=-1;
670         if ( units == FG_UNITS_FEET ) {
671             wBody = atof( arg.substr(8) );
672         } else {
673             wBody = atof( arg.substr(8) ) * FEET_TO_METER;
674         }
675     } else if ( arg.find( "--vc=" ) != string::npos) {
676         mach=-1;
677         vkcas=atof( arg.substr(5) );
678         cout << "Got vc: " << vkcas << endl;
679     } else if ( arg.find( "--mach=" ) != string::npos) {
680         vkcas=-1;
681         mach=atof( arg.substr(7) );
682     } else if ( arg.find( "--heading=" ) != string::npos ) {
683         heading = atof( arg.substr(10) );
684     } else if ( arg.find( "--roll=" ) != string::npos ) {
685         roll = atof( arg.substr(7) );
686     } else if ( arg.find( "--pitch=" ) != string::npos ) {
687         pitch = atof( arg.substr(8) );
688     } else if ( arg.find( "--fg-root=" ) != string::npos ) {
689         fg_root = arg.substr( 10 );
690     } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
691         fg_scenery = arg.substr( 13 );
692     } else if ( arg.find( "--fdm=" ) != string::npos ) {
693         flight_model = parse_fdm( arg.substr(6) );
694     if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
695         set_trim_mode(1);
696     } else {
697         set_trim_mode(0);
698     }        
699     } else if ( arg.find( "--aircraft=" ) != string::npos ) {
700         aircraft = arg.substr(11);
701     } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
702         aircraft_dir =  arg.substr(15); //  (UIUC)
703     } else if ( arg.find( "--model-hz=" ) != string::npos ) {
704         model_hz = atoi( arg.substr(11) );
705     } else if ( arg.find( "--speed=" ) != string::npos ) {
706         speed_up = atoi( arg.substr(8) );
707     } else if ( arg.find( "--notrim") != string::npos) {
708         trim=-1;
709     } else if ( arg == "--fog-disable" ) {
710         fog = FG_FOG_DISABLED;  
711     } else if ( arg == "--fog-fastest" ) {
712         fog = FG_FOG_FASTEST;   
713     } else if ( arg == "--fog-nicest" ) {
714         fog = FG_FOG_NICEST;    
715     } else if ( arg == "--disable-clouds" ) {
716         clouds = false; 
717     } else if ( arg == "--enable-clouds" ) {
718         clouds = true;  
719     } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
720         if ( units == FG_UNITS_FEET ) {
721             clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
722         } else {
723             clouds_asl = atof( arg.substr(13) );
724         }
725     } else if ( arg.find( "--fov=" ) != string::npos ) {
726         fov = parse_fov( arg.substr(6) );
727     } else if ( arg == "--disable-fullscreen" ) {
728         fullscreen = false;     
729     } else if ( arg== "--enable-fullscreen") {
730         fullscreen = true;      
731     } else if ( arg == "--shading-flat") {
732         shading = 0;    
733     } else if ( arg == "--shading-smooth") {
734         shading = 1;    
735     } else if ( arg == "--disable-skyblend") {
736         skyblend = false;       
737     } else if ( arg== "--enable-skyblend" ) {
738         skyblend = true;        
739     } else if ( arg == "--disable-textures" ) {
740         textures = false;       
741     } else if ( arg == "--enable-textures" ) {
742         textures = true;
743     } else if ( arg == "--disable-wireframe" ) {
744         wireframe = false;      
745     } else if ( arg == "--enable-wireframe" ) {
746         wireframe = true;
747     } else if ( arg.find( "--geometry=" ) != string::npos ) {
748         bool geometry_ok = true;
749         string geometry = arg.substr( 11 );
750         string::size_type i = geometry.find('x');
751
752         if (i != string::npos) {
753             xsize = atoi(geometry.substr(0, i));
754             ysize = atoi(geometry.substr(i+1));
755             // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
756         } else {
757             geometry_ok = false;
758         }
759
760         if ( xsize <= 0 || ysize <= 0 ) {
761             xsize = 640;
762             ysize = 480;
763             geometry_ok = false;
764         }
765
766         if ( !geometry_ok ) {
767             FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
768             FG_LOG( FG_GENERAL, FG_ALERT,
769                     "Setting geometry to " << xsize << 'x' << ysize << '\n');
770         }
771     } else if ( arg.find( "--bpp=" ) != string::npos ) {
772         string bits_per_pix = arg.substr( 6 );
773         if ( bits_per_pix == "16" ) {
774             bpp = 16;
775         } else if ( bits_per_pix == "24" ) {
776             bpp = 24;
777         } else if ( bits_per_pix == "32" ) {
778             bpp = 32;
779         }
780     } else if ( arg == "--units-feet" ) {
781         units = FG_UNITS_FEET;  
782     } else if ( arg == "--units-meters" ) {
783         units = FG_UNITS_METERS;        
784     } else if ( arg.find( "--tile-radius=" ) != string::npos ) {
785         tile_radius = parse_tile_radius( arg.substr(14) );
786         tile_diameter = tile_radius * 2 + 1;
787     } else if ( arg.find( "--time-offset" ) != string::npos ) {
788         time_offset = parse_time_offset( (arg.substr(14)) );
789         //time_offset_type = FG_TIME_SYS_OFFSET;
790     } else if ( arg.find( "--time-match-real") != string::npos ) {
791       //time_offset = parse_time_offset(arg.substr(18));
792         time_offset_type = FG_TIME_SYS_OFFSET;
793     } else if ( arg.find( "--time-match-local") != string::npos ) {
794       //time_offset = parse_time_offset(arg.substr(18));
795         time_offset_type = FG_TIME_LAT_OFFSET;
796     } else if ( arg.find( "--start-date-sys=") != string::npos ) {
797         time_offset = parse_date( (arg.substr(17)) );
798         time_offset_type = FG_TIME_SYS_ABSOLUTE;
799     } else if ( arg.find( "--start-date-lat=") != string::npos ) {
800         time_offset = parse_date( (arg.substr(17)) );
801         time_offset_type = FG_TIME_LAT_ABSOLUTE;
802     } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
803         time_offset = parse_date( (arg.substr(17)) );
804         time_offset_type = FG_TIME_GMT_ABSOLUTE;
805
806     } else if ( arg == "--hud-tris" ) {
807         tris_or_culled = 0;     
808     } else if ( arg == "--hud-culled" ) {
809         tris_or_culled = 1;
810     } else if ( arg.find( "--native=" ) != string::npos ) {
811         parse_channel( "native", arg.substr(9) );
812     } else if ( arg.find( "--garmin=" ) != string::npos ) {
813         parse_channel( "garmin", arg.substr(9) );
814     } else if ( arg.find( "--nmea=" ) != string::npos ) {
815         parse_channel( "nmea", arg.substr(7) );
816     } else if ( arg.find( "--pve=" ) != string::npos ) {
817         parse_channel( "pve", arg.substr(6) );
818     } else if ( arg.find( "--ray=" ) != string::npos ) {
819         parse_channel( "ray", arg.substr(6) );
820     } else if ( arg.find( "--rul=" ) != string::npos ) {
821         parse_channel( "rul", arg.substr(6) );
822     } else if ( arg.find( "--joyclient=" ) != string::npos ) {
823         parse_channel( "joyclient", arg.substr(12) );
824 #ifdef FG_NETWORK_OLK
825     } else if ( arg == "--disable-network-olk" ) {
826         network_olk = false;    
827     } else if ( arg== "--enable-network-olk") {
828         network_olk = true;     
829     } else if ( arg == "--net-hud" ) {
830         net_hud_display = 1;    
831     } else if ( arg.find( "--net-id=") != string::npos ) {
832         net_id = arg.substr( 9 );
833 #endif
834     } else if ( arg.find( "--prop:" ) == 0 ) {
835         string assign = arg.substr(7);
836         int pos = assign.find('=');
837         if (pos == arg.npos || pos == 0) {
838             FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
839             return FG_OPTIONS_ERROR;
840         }
841         string name = assign.substr(0, pos);
842         string value = assign.substr(pos + 1);
843         current_properties.setStringValue(name.c_str(), value);
844         FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
845                << name << " to \"" << value << '"');
846     } else {
847         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
848         return FG_OPTIONS_ERROR;
849     }
850     
851     return FG_OPTIONS_OK;
852 }
853
854
855 // Parse the command line options
856 int fgOPTIONS::parse_command_line( int argc, char **argv ) {
857     int i = 1;
858     int result;
859
860     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
861
862     while ( i < argc ) {
863         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
864
865         result = parse_option(argv[i]);
866         if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
867             return(result);
868         }
869
870         i++;
871     }
872     
873     return(FG_OPTIONS_OK);
874 }
875
876
877 // Parse config file options
878 int fgOPTIONS::parse_config_file( const string& path ) {
879     fg_gzifstream in( path );
880     if ( !in.is_open() )
881         return(FG_OPTIONS_ERROR);
882
883     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
884
885     in >> skipcomment;
886 #ifndef __MWERKS__
887     while ( ! in.eof() ) {
888 #else
889     char c = '\0';
890     while ( in.get(c) && c != '\0' ) {
891         in.putback(c);
892 #endif
893         string line;
894
895 #ifdef GETLINE_NEEDS_TERMINATOR
896         getline( in, line, '\n' );
897 #elif defined (MACOS)
898         getline( in, line, '\r' );
899 #else
900         getline( in, line );
901 #endif
902
903         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
904             FG_LOG( FG_GENERAL, FG_ALERT, 
905                     "Config file parse error: " << path << " '" 
906                     << line << "'" );
907             exit(-1);
908         }
909         in >> skipcomment;
910     }
911
912     return FG_OPTIONS_OK;
913 }
914
915
916 // Print usage message
917 void fgOPTIONS::usage ( void ) {
918     cout << "Usage: fg [ options ... ]" << endl;
919     cout << endl;
920
921     cout << "General Options:" << endl;
922     cout << "\t--help -h:  print usage" << endl;
923     cout << "\t--fg-root=path:  specify the root path for all the data files"
924          << endl;
925     cout << "\t--fg-scenery=path:  specify the base path for all the scenery"
926          << " data." << endl
927          << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
928     cout << "\t--disable-game-mode:  disable full-screen game mode" << endl;
929     cout << "\t--enable-game-mode:  enable full-screen game mode" << endl;
930     cout << "\t--disable-splash-screen:  disable splash screen" << endl;
931     cout << "\t--enable-splash-screen:  enable splash screen" << endl;
932     cout << "\t--disable-intro-music:  disable introduction music" << endl;
933     cout << "\t--enable-intro-music:  enable introduction music" << endl;
934     cout << "\t--disable-mouse-pointer:  disable extra mouse pointer" << endl;
935     cout << "\t--enable-mouse-pointer:  enable extra mouse pointer (i.e. for"
936          << endl;
937     cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
938     cout << "\t--disable-freeze:  start out in an running state" << endl;
939     cout << "\t--enable-freeze:  start out in a frozen state" << endl;
940     cout << "\t--control=mode:  primary control mode " 
941          << "(joystick, keyboard, mouse)" << endl;
942     cout << endl;
943
944     cout << "Features:" << endl;
945     cout << "\t--disable-hud:  disable heads up display" << endl;
946     cout << "\t--enable-hud:  enable heads up display" << endl;
947     cout << "\t--disable-panel:  disable instrument panel" << endl;
948     cout << "\t--enable-panel:  enable instrumetn panel" << endl;
949     cout << "\t--disable-sound:  disable sound effects" << endl;
950     cout << "\t--enable-sound:  enable sound effects" << endl;
951     cout << "\t--disable-anti-alias-hud:  disable anti aliased hud" << endl;
952     cout << "\t--enable-anti-alias-hud:  enable anti aliased hud" << endl;
953     cout << endl;
954  
955     cout << "Flight Model:" << endl;
956     cout << "\t--fdm=abcd:  selects the core flight model code." << endl;
957     cout << "\t\tcan be one of jsb, larcsim, magic, or external" << endl;
958     cout << "\t--aircraft=abcd:  aircraft model to load" << endl;
959     cout << "\t--model-hz=n:  run the FDM this rate (iterations per second)" 
960          << endl;
961     cout << "\t--speed=n:  run the FDM this much faster than real time" << endl;
962     cout << "\t--notrim:  Do NOT attempt to trim the model when initializing JSBsim" << endl;
963     cout << endl;
964     //(UIUC)
965     cout <<"Aircraft model directory" << endl;
966     cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
967     cout << endl;
968
969     cout << "Initial Position and Orientation:" << endl;
970     cout << "\t--airport-id=ABCD:  specify starting postion by airport id" 
971          << endl;
972     cout << "\t--lon=degrees:  starting longitude in degrees (west = -)" 
973          << endl;
974     cout << "\t--lat=degrees:  starting latitude in degrees (south = -)"
975          << endl;
976     cout << "\t--altitude=feet:  starting altitude in feet" << endl;
977     cout << "\t\t(unless --units-meters specified" << endl;
978     cout << "\t--heading=degrees:  heading (yaw) angle in degress (Psi)"
979          << endl;
980     cout << "\t--roll=degrees:  roll angle in degrees (Phi)" << endl;
981     cout << "\t--pitch=degrees:  pitch angle in degrees (Theta)" << endl;
982     cout << "\t--uBody=feet per second:  velocity along the body X axis"
983          << endl;
984     cout << "\t--vBody=feet per second:  velocity along the body Y axis"
985          << endl;
986     cout << "\t--wBody=feet per second:  velocity along the body Z axis"
987          << endl;
988     cout << "\t\t(unless --units-meters specified" << endl;
989     cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
990     cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
991     cout << endl;
992
993     cout << "Rendering Options:" << endl;
994     cout << "\t--fog-disable:  disable fog/haze" << endl;
995     cout << "\t--fog-fastest:  enable fastest fog/haze" << endl;
996     cout << "\t--fog-nicest:  enable nicest fog/haze" << endl;
997     cout << "\t--enable-clouds:  enable demo cloud layer" << endl;
998     cout << "\t--disable-clouds:  disable demo cloud layer" << endl;
999     cout << "\t--clouds-asl=xxx:  specify altitude of cloud layer above sea level" << endl;
1000     cout << "\t--fov=xx.x:  specify initial field of view angle in degrees"
1001          << endl;
1002     cout << "\t--disable-fullscreen:  disable fullscreen mode" << endl;
1003     cout << "\t--enable-fullscreen:  enable fullscreen mode" << endl;
1004     cout << "\t--shading-flat:  enable flat shading" << endl;
1005     cout << "\t--shading-smooth:  enable smooth shading" << endl;
1006     cout << "\t--disable-skyblend:  disable sky blending" << endl;
1007     cout << "\t--enable-skyblend:  enable sky blending" << endl;
1008     cout << "\t--disable-textures:  disable textures" << endl;
1009     cout << "\t--enable-textures:  enable textures" << endl;
1010     cout << "\t--disable-wireframe:  disable wireframe drawing mode" << endl;
1011     cout << "\t--enable-wireframe:  enable wireframe drawing mode" << endl;
1012     cout << "\t--geometry=WWWxHHH:  window geometry: 640x480, 800x600, etc."
1013          << endl;
1014     cout << endl;
1015
1016     cout << "Scenery Options:" << endl;
1017     cout << "\t--tile-radius=n:  specify tile radius, must be 1 - 4" << endl;
1018     cout << endl;
1019
1020     cout << "Hud Options:" << endl;
1021     cout << "\t--units-feet:  Hud displays units in feet" << endl;
1022     cout << "\t--units-meters:  Hud displays units in meters" << endl;
1023     cout << "\t--hud-tris:  Hud displays number of triangles rendered" << endl;
1024     cout << "\t--hud-culled:  Hud displays percentage of triangles culled"
1025          << endl;
1026     cout << endl;
1027         
1028     cout << "Time Options:" << endl;
1029     cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1030     cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1031          << "\t\ttime. Can be used in combination with --time-offset." << endl;
1032     cout << "\t--time-match-local:Synchronize local real-world and " << endl
1033          << "\t\tFlightGear time" << endl;   
1034     cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1035          << "\t\tdate/time. Uses your system time " << endl;
1036     cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1037          << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1038     cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1039          << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1040 #ifdef FG_NETWORK_OLK
1041     cout << "" << endl;
1042
1043     cout << "Network Options:" << endl;
1044     cout << "\t--net-hud:  Hud displays network info" << endl;
1045     cout << "\t--net-id=name:  specify your own callsign" << endl;
1046 #endif
1047 }
1048
1049
1050 // Destructor
1051 fgOPTIONS::~fgOPTIONS( void ) {
1052 }