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