]> git.mxchange.org Git - flightgear.git/blob - Main/options.cxx
Added an option to enable/disable full-screen mode.
[flightgear.git] / Main / options.cxx
1 //
2 // options.cxx -- class to handle command line options
3 //
4 // Written by Curtis Olson, started April 1998.
5 //
6 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23 // (Log is kept at end of this file)
24
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #include <math.h>            // rint()
31 #include <stdio.h>
32 #include <stdlib.h>          // atof()
33 #include <string.h>
34
35 #include <Debug/fg_debug.h>
36
37 #include "options.hxx"
38
39
40 // Defined the shared options class here
41 fgOPTIONS current_options;
42
43
44 // Constructor
45 fgOPTIONS::fgOPTIONS( void ) {
46     // set initial values/defaults
47
48     strcpy(airport_id, "");
49
50     // Features
51     hud_status = 0;
52
53     // Rendering options
54     fog = 1;
55     fullscreen = 0;
56     shading = 1;
57     skyblend = 1;
58     textures = 1;
59     wireframe = 0;
60
61     // Time options
62     time_offset = 0;
63 }
64
65
66 // parse time string in the form of [+-]hh:mm:ss, returns the value in seconds
67 static double parse_time(char *time_str) {
68     char num[256];
69     double hours, minutes, seconds;
70     double result = 0.0;
71     int sign = 1;
72     int i;
73
74     // printf("parse_time(): %s\n", time_str);
75
76     // check for sign
77     if ( strlen(time_str) ) {
78         if ( time_str[0] == '+' ) {
79             sign = 1;
80             time_str++;
81         } else if ( time_str[0] == '-' ) {
82             sign = -1;
83             time_str++;
84         }
85     }
86     // printf("sign = %d\n", sign);
87
88     // get hours
89     if ( strlen(time_str) ) {
90         i = 0;
91         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
92             num[i] = time_str[0];
93             time_str++;
94             i++;
95         }
96         if ( time_str[0] == ':' ) {
97             time_str++;
98         }
99         num[i] = '\0';
100         hours = atof(num);
101         // printf("hours = %.2lf\n", hours);
102
103         result += hours * 3600.0;
104     }
105
106     // get minutes
107     if ( strlen(time_str) ) {
108         i = 0;
109         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
110             num[i] = time_str[0];
111             time_str++;
112             i++;
113         }
114         if ( time_str[0] == ':' ) {
115             time_str++;
116         }
117         num[i] = '\0';
118         minutes = atof(num);
119         // printf("minutes = %.2lf\n", minutes);
120
121         result += minutes * 60.0;
122     }
123
124     // get seconds
125     if ( strlen(time_str) ) {
126         i = 0;
127         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
128             num[i] = time_str[0];
129             time_str++;
130             i++;
131         }
132         num[i] = '\0';
133         seconds = atof(num);
134         // printf("seconds = %.2lf\n", seconds);
135
136         result += seconds;
137     }
138
139     return(sign * result);
140 }
141
142
143 // parse time offset command line option
144 static int parse_time_offset(char *time_str) {
145     int result;
146
147     time_str += 14;
148
149     // printf("time offset = %s\n", time_str);
150
151 #ifdef HAVE_RINT
152     result = (int)rint(parse_time(time_str));
153 #else
154     result = (int)parse_time(time_str);
155 #endif
156
157     printf("parse_time_offset(): %d\n", result);
158
159     return( result );
160
161 }
162
163
164 // Parse the command line options
165 int fgOPTIONS::parse( int argc, char **argv ) {
166     int i = 1;
167
168     fgPrintf(FG_GENERAL, FG_INFO, "Processing arguments\n");
169
170     while ( i < argc ) {
171         fgPrintf(FG_GENERAL, FG_INFO, "argv[%d] = %s\n", i, argv[i]);
172
173         // General Options
174         if ( (strcmp(argv[i], "--help") == 0) ||
175              (strcmp(argv[i], "-h") == 0) ) {
176             // help/usage request
177             return(FG_OPTIONS_HELP);
178         } else if ( strcmp(argv[i], "--disable-hud") == 0 ) {
179             hud_status = 0;     
180         } else if ( strcmp(argv[i], "--enable-hud") == 0 ) {
181             hud_status = 1;     
182         } else if ( strncmp(argv[i], "--airport-id=", 13) == 0 ) {
183             argv[i] += 13;
184             strncpy(airport_id, argv[i], 4);
185         } else if ( strcmp(argv[i], "--disable-fog") == 0 ) {
186             fog = 0;    
187         } else if ( strcmp(argv[i], "--enable-fog") == 0 ) {
188             fog = 1;    
189         } else if ( strcmp(argv[i], "--disable-fullscreen") == 0 ) {
190             fullscreen = 0;     
191         } else if ( strcmp(argv[i], "--enable-fullscreen") == 0 ) {
192             fullscreen = 1;     
193         } else if ( strcmp(argv[i], "--shading-flat") == 0 ) {
194             shading = 0;        
195         } else if ( strcmp(argv[i], "--shading-smooth") == 0 ) {
196             shading = 1;        
197         } else if ( strcmp(argv[i], "--disable-skyblend") == 0 ) {
198             skyblend = 0;       
199         } else if ( strcmp(argv[i], "--enable-skyblend") == 0 ) {
200             skyblend = 1;       
201         } else if ( strcmp(argv[i], "--disable-textures") == 0 ) {
202             textures = 0;       
203         } else if ( strcmp(argv[i], "--enable-textures") == 0 ) {
204             textures = 1;       
205         } else if ( strcmp(argv[i], "--disable-wireframe") == 0 ) {
206             wireframe = 0;      
207         } else if ( strcmp(argv[i], "--enable-wireframe") == 0 ) {
208             wireframe = 1;      
209         } else if ( strncmp(argv[i], "--time-offset=", 14) == 0 ) {
210             time_offset = parse_time_offset(argv[i]);
211         } else {
212             return(FG_OPTIONS_ERROR);
213         }
214
215         i++;
216     }
217     
218     return(FG_OPTIONS_OK);
219 }
220
221
222 // Print usage message
223 void fgOPTIONS::usage ( void ) {
224     printf("Usage: fg [ options ... ]\n");
225     printf("\n");
226
227     printf("General Options:\n");
228     printf("\t--help -h:  print usage\n");
229     printf("\n");
230
231     printf("Features:\n");
232     printf("\t--disable-hud:  disable heads up display\n");
233     printf("\t--enable-hud:  enable heads up display\n");
234     printf("\n");
235  
236     printf("Initial Position:\n");
237     printf("\t--airport-id=ABCD:  specify starting postion by airport id\n");
238     printf("\n");
239
240     printf("Rendering Options:\n");
241     printf("\t--disable-fog:  disable fog/haze\n");
242     printf("\t--enable-fog:  enable fog/haze\n");
243     printf("\t--disable-fullscreen:  disable fullscreen mode\n");
244     printf("\t--enable-fullscreen:  enable fullscreen mode\n");
245     printf("\t--shading-flat:  enable flat shading\n");
246     printf("\t--shading-smooth:  enable smooth shading\n");
247     printf("\t--disable-skyblend:  disable sky blending\n");
248     printf("\t--enable-skyblend:  enable sky blending\n");
249     printf("\t--disable-textures:  disable textures\n");
250     printf("\t--enable-textures:  enable textures\n");
251     printf("\t--disable-wireframe:  disable wireframe drawing mode\n");
252     printf("\t--enable-wireframe:  enable wireframe drawing mode\n");
253     printf("\n");
254
255     printf("Time Options:\n");
256     printf("\t--time-offset=[+-]hh:mm:ss:  offset local time by this amount\n");
257 }
258
259
260 // Destructor
261 fgOPTIONS::~fgOPTIONS( void ) {
262 }
263
264
265 // $Log$
266 // Revision 1.6  1998/05/03 00:47:32  curt
267 // Added an option to enable/disable full-screen mode.
268 //
269 // Revision 1.5  1998/04/30 12:34:19  curt
270 // Added command line rendering options:
271 //   enable/disable fog/haze
272 //   specify smooth/flat shading
273 //   disable sky blending and just use a solid color
274 //   enable wireframe drawing mode
275 //
276 // Revision 1.4  1998/04/28 01:20:22  curt
277 // Type-ified fgTIME and fgVIEW.
278 // Added a command line option to disable textures.
279 //
280 // Revision 1.3  1998/04/26 05:01:19  curt
281 // Added an rint() / HAVE_RINT check.
282 //
283 // Revision 1.2  1998/04/25 15:11:12  curt
284 // Added an command line option to set starting position based on airport ID.
285 //
286 // Revision 1.1  1998/04/24 00:49:21  curt
287 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
288 // Trying out some different option parsing code.
289 // Some code reorganization.
290 //
291 //