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