static void fgUpdateViewParams( void ) {
fgFLIGHT *f;
fgLIGHT *l;
+ fgOPTIONS *o;
fgVIEW *v;
f = current_aircraft.flight;
l = &cur_light_params;
+ o = ¤t_options;
v = ¤t_view;
fgViewUpdate(f, v, l);
// Tell GL we are about to modify the projection parameters
xglMatrixMode(GL_PROJECTION);
xglLoadIdentity();
- gluPerspective(65.0, 2.0/win_ratio, 1.0, 100000.0);
+ gluPerspective(o->fov, 2.0/win_ratio, 1.0, 100000.0);
} else {
xglViewport(0, 0 , (GLint)winWidth, (GLint) winHeight);
// Tell GL we are about to modify the projection parameters
xglMatrixMode(GL_PROJECTION);
xglLoadIdentity();
- gluPerspective(65.0, 1.0/win_ratio, 10.0, 100000.0);
+ gluPerspective(o->fov, 1.0/win_ratio, 10.0, 100000.0);
}
xglMatrixMode(GL_MODELVIEW);
double angle;
GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
- GLfloat color[4] = { 0.54, 0.44, 0.29, 1.0 };
-
+ GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
+
l = &cur_light_params;
o = ¤t_options;
t = &cur_time_params;
xglMaterialfv (GL_FRONT, GL_DIFFUSE, white);
} else {
xglDisable( GL_TEXTURE_2D );
- xglMaterialfv (GL_FRONT, GL_AMBIENT, color);
- xglMaterialfv (GL_FRONT, GL_DIFFUSE, color);
+ xglMaterialfv (GL_FRONT, GL_AMBIENT, terrain_color);
+ xglMaterialfv (GL_FRONT, GL_DIFFUSE, terrain_color);
}
fgTileMgrRender();
// Main ...
int main( int argc, char **argv ) {
fgFLIGHT *f;
+ fgOPTIONS *o;
+ char config[256];
int result; // Used in command line argument.
f = current_aircraft.flight;
+ o = ¤t_options;
#ifdef HAVE_BC5PLUS
_control87(MCW_EM, MCW_EM); /* defined in float.h */
fgPrintf( FG_GENERAL, FG_EXIT, "GLUT initialization failed ...\n" );
}
- // Parse remaining command line options
- result = current_options.parse(argc, argv);
+ // Attempt to locate and parse a config file
+ // First check fg_root
+ strcpy(config, o->fg_root);
+ strcat(config, "/system.fgfsrc");
+ result = o->parse_config_file(config);
+
+ // Next check home directory
+ if ( getenv("HOME") != NULL ) {
+ strcpy(config, getenv("HOME"));
+ strcat(config, "/.fgfsrc");
+ result = o->parse_config_file(config);
+ }
+ // Parse remaining command line options
+ // These will override anything specified in a config file
+ result = o->parse_command_line(argc, argv);
if ( result != FG_OPTIONS_OK ) {
// Something must have gone horribly wrong with the command
// line parsing or maybe the user just requested help ... :-)
- current_options.usage();
- fgPrintf( FG_GENERAL, FG_EXIT, "\nShutting down ...\n");
+ o->usage();
+ fgPrintf( FG_GENERAL, FG_EXIT, "\nExiting ...\n");
}
// These are a few miscellaneous things that aren't really
// $Log$
+// Revision 1.14 1998/05/13 18:29:57 curt
+// Added a keyboard binding to dynamically adjust field of view.
+// Added a command line option to specify fov.
+// Adjusted terrain color.
+// Root path info moved to fgOPTIONS.
+// Added ability to parse options out of a config file.
+//
// Revision 1.13 1998/05/11 18:18:15 curt
// For flat shading use "glHint (GL_FOG_HINT, GL_FASTEST )"
//
// General house keeping initializations
int fgInitGeneral( void ) {
fgGENERAL *g;
+ fgOPTIONS *o;
int i;
g = &general;
+ o = ¤t_options;
fgPrintf( FG_GENERAL, FG_INFO, "General Initialization\n" );
fgPrintf( FG_GENERAL, FG_INFO, "======= ==============\n" );
- // determine the fg root path.
- if( !(g->root_dir) ) {
- // If not set by command line test for environmental var..
- g->root_dir = getenv("FG_ROOT");
- if ( !g->root_dir ) {
- // No root path set? Then assume, we will exit if this is
- // wrong when looking for support files.
- fgPrintf( FG_GENERAL, FG_EXIT, "%s %s\n",
- "Cannot continue without environment variable FG_ROOT",
- "being defined.");
- }
+ if ( !strlen(o->fg_root) ) {
+ // No root path set? Then assume, we will exit if this is
+ // wrong when looking for support files.
+ fgPrintf( FG_GENERAL, FG_EXIT, "%s %s\n",
+ "Cannot continue without environment variable FG_ROOT",
+ "being defined.");
}
- fgPrintf( FG_GENERAL, FG_INFO, "FG_ROOT = %s\n\n", g->root_dir);
+ fgPrintf( FG_GENERAL, FG_INFO, "FG_ROOT = %s\n\n", o->fg_root);
// prime the frame rate counter pump
for ( i = 0; i < FG_FRAME_RATE_HISTORY; i++ ) {
// $Log$
+// Revision 1.12 1998/05/13 18:29:58 curt
+// Added a keyboard binding to dynamically adjust field of view.
+// Added a command line option to specify fov.
+// Adjusted terrain color.
+// Root path info moved to fgOPTIONS.
+// Added ability to parse options out of a config file.
+//
// Revision 1.11 1998/05/07 23:14:15 curt
// Added "D" key binding to set autopilot heading.
// Made frame rate calculation average out over last 10 frames.
#include <string.h>
#include <Debug/fg_debug.h>
+#include <Include/fg_zlib.h>
#include "options.hxx"
fgOPTIONS::fgOPTIONS( void ) {
// set initial values/defaults
+ if ( getenv("FG_ROOT") != NULL ) {
+ // fg_root could be anywhere, so default to environmental
+ // variable $FG_ROOT if it is set.
+
+ strcpy(fg_root, getenv("FG_ROOT"));
+ } else {
+ // Otherwise, default to a random compiled in location if
+ // $FG_ROOT is not set. This can still be overridden from the
+ // command line or a config file.
+
+#if defined(WIN32)
+ strcpy(fg_root, "\\FlightGear");
+#else
+ strcpy(fg_root, "/usr/local/lib/FlightGear");
+#endif
+ }
+
+ // default airport id
strcpy(airport_id, "");
// Features
// Rendering options
fog = 1;
+ fov = 65.0;
fullscreen = 0;
shading = 1;
skyblend = 1;
}
+// Parse an int out of a --foo-bar=n type option
+static int parse_int(char *arg) {
+ int result;
+
+ // advance past the '='
+ while ( (arg[0] != '=') && (arg[0] != '\0') ) {
+ arg++;
+ }
+
+ if ( arg[0] == '=' ) {
+ arg++;
+ }
+
+ printf("parse_int(): arg = %s\n", arg);
+
+ result = atoi(arg);
+
+ printf("parse_int(): result = %d\n", result);
+
+ return(result);
+}
+
+
+// Parse an int out of a --foo-bar=n type option
+static double parse_double(char *arg) {
+ double result;
+
+ // advance past the '='
+ while ( (arg[0] != '=') && (arg[0] != '\0') ) {
+ arg++;
+ }
+
+ if ( arg[0] == '=' ) {
+ arg++;
+ }
+
+ printf("parse_double(): arg = %s\n", arg);
+
+ result = atof(arg);
+
+ printf("parse_double(): result = %.4f\n", result);
+
+ return(result);
+}
+
+
// parse time string in the form of [+-]hh:mm:ss, returns the value in seconds
static double parse_time(char *time_str) {
char num[256];
}
-// Parse an int out of a --foo-bar=n type option
-static int parse_int(char *arg, int min, int max) {
- int result;
+// Parse --tile-radius=n type option
- // advance past the '='
- while ( (arg[0] != '=') && (arg[0] != '\0') ) {
- arg++;
- }
+#define FG_RADIUS_MIN 3
+#define FG_RADIUS_MAX 9
- if ( arg[0] == '=' ) {
- arg++;
+static int parse_tile_radius(char *arg) {
+ int radius, tmp;
+
+ radius = parse_int(arg);
+
+ // radius must be odd
+ tmp = radius / 2;
+ if ( radius == ( tmp * 2 ) ) {
+ radius -= 1;
}
- printf("parse_int(): arg = %s\n", arg);
+ if ( radius < FG_RADIUS_MIN ) { radius = FG_RADIUS_MIN; }
+ if ( radius > FG_RADIUS_MAX ) { radius = FG_RADIUS_MAX; }
- result = atoi(arg);
+ printf("parse_tile_radius(): radius = %d\n", radius);
- if ( result < min ) { result = min; }
- if ( result > max ) { result = max; }
+ return(radius);
+}
- printf("parse_int(): result = %d\n", result);
- return(result);
+
+// Parse --fov=x.xx type option
+
+#define FG_FOV_MIN 0.1
+#define FG_FOV_MAX 179.9
+
+static double parse_fov(char *arg) {
+ double fov;
+
+ fov = parse_double(arg);
+
+ if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
+ if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
+
+ printf("parse_fov(): result = %.4f\n", fov);
+
+ return(fov);
+}
+
+
+// Parse a single option
+int fgOPTIONS::parse_option( char *arg ) {
+ // General Options
+ if ( (strcmp(arg, "--help") == 0) ||
+ (strcmp(arg, "-h") == 0) ) {
+ // help/usage request
+ return(FG_OPTIONS_HELP);
+ } else if ( strcmp(arg, "--disable-hud") == 0 ) {
+ hud_status = 0;
+ } else if ( strcmp(arg, "--enable-hud") == 0 ) {
+ hud_status = 1;
+ } else if ( strncmp(arg, "--airport-id=", 13) == 0 ) {
+ arg += 13;
+ strncpy(airport_id, arg, 4);
+ } else if ( strncmp(arg, "--fg-root=", 10) == 0 ) {
+ arg += 10;
+ strcpy(fg_root, arg);
+ } else if ( strcmp(arg, "--disable-fog") == 0 ) {
+ fog = 0;
+ } else if ( strcmp(arg, "--enable-fog") == 0 ) {
+ fog = 1;
+ } else if ( strncmp(arg, "--fov=", 6) == 0 ) {
+ fov = parse_fov(arg);
+ } else if ( strcmp(arg, "--disable-fullscreen") == 0 ) {
+ fullscreen = 0;
+ } else if ( strcmp(arg, "--enable-fullscreen") == 0 ) {
+ fullscreen = 1;
+ } else if ( strcmp(arg, "--shading-flat") == 0 ) {
+ shading = 0;
+ } else if ( strcmp(arg, "--shading-smooth") == 0 ) {
+ shading = 1;
+ } else if ( strcmp(arg, "--disable-skyblend") == 0 ) {
+ skyblend = 0;
+ } else if ( strcmp(arg, "--enable-skyblend") == 0 ) {
+ skyblend = 1;
+ } else if ( strcmp(arg, "--disable-textures") == 0 ) {
+ textures = 0;
+ } else if ( strcmp(arg, "--enable-textures") == 0 ) {
+ textures = 1;
+ } else if ( strcmp(arg, "--disable-wireframe") == 0 ) {
+ wireframe = 0;
+ } else if ( strcmp(arg, "--enable-wireframe") == 0 ) {
+ wireframe = 1;
+ } else if ( strncmp(arg, "--tile-radius=", 14) == 0 ) {
+ tile_radius = parse_tile_radius(arg);
+ } else if ( strncmp(arg, "--time-offset=", 14) == 0 ) {
+ time_offset = parse_time_offset(arg);
+ } else {
+ return(FG_OPTIONS_ERROR);
+ }
+
+ return(FG_OPTIONS_OK);
}
// Parse the command line options
-int fgOPTIONS::parse( int argc, char **argv ) {
+int fgOPTIONS::parse_command_line( int argc, char **argv ) {
int i = 1;
+ int result;
- fgPrintf(FG_GENERAL, FG_INFO, "Processing arguments\n");
+ fgPrintf(FG_GENERAL, FG_INFO, "Processing command line arguments\n");
while ( i < argc ) {
fgPrintf(FG_GENERAL, FG_INFO, "argv[%d] = %s\n", i, argv[i]);
- // General Options
- if ( (strcmp(argv[i], "--help") == 0) ||
- (strcmp(argv[i], "-h") == 0) ) {
- // help/usage request
- return(FG_OPTIONS_HELP);
- } else if ( strcmp(argv[i], "--disable-hud") == 0 ) {
- hud_status = 0;
- } else if ( strcmp(argv[i], "--enable-hud") == 0 ) {
- hud_status = 1;
- } else if ( strncmp(argv[i], "--airport-id=", 13) == 0 ) {
- argv[i] += 13;
- strncpy(airport_id, argv[i], 4);
- } else if ( strcmp(argv[i], "--disable-fog") == 0 ) {
- fog = 0;
- } else if ( strcmp(argv[i], "--enable-fog") == 0 ) {
- fog = 1;
- } else if ( strcmp(argv[i], "--disable-fullscreen") == 0 ) {
- fullscreen = 0;
- } else if ( strcmp(argv[i], "--enable-fullscreen") == 0 ) {
- fullscreen = 1;
- } else if ( strcmp(argv[i], "--shading-flat") == 0 ) {
- shading = 0;
- } else if ( strcmp(argv[i], "--shading-smooth") == 0 ) {
- shading = 1;
- } else if ( strcmp(argv[i], "--disable-skyblend") == 0 ) {
- skyblend = 0;
- } else if ( strcmp(argv[i], "--enable-skyblend") == 0 ) {
- skyblend = 1;
- } else if ( strcmp(argv[i], "--disable-textures") == 0 ) {
- textures = 0;
- } else if ( strcmp(argv[i], "--enable-textures") == 0 ) {
- textures = 1;
- } else if ( strcmp(argv[i], "--disable-wireframe") == 0 ) {
- wireframe = 0;
- } else if ( strcmp(argv[i], "--enable-wireframe") == 0 ) {
- wireframe = 1;
- } else if ( strncmp(argv[i], "--tile-radius=", 14) == 0 ) {
- tile_radius = parse_int(argv[i], 3, 9);
- } else if ( strncmp(argv[i], "--time-offset=", 14) == 0 ) {
- time_offset = parse_time_offset(argv[i]);
- } else {
- return(FG_OPTIONS_ERROR);
+ result = parse_option(argv[i]);
+ if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
+ return(result);
}
i++;
}
+// Parse the command line options
+int fgOPTIONS::parse_config_file( char *path ) {
+ char fgpath[256], line[256];
+ fgFile f;
+ int len, result;
+
+ strcpy(fgpath, path);
+ strcat(fgpath, ".gz");
+
+ // first try "path.gz"
+ if ( (f = fgopen(fgpath, "rb")) == NULL ) {
+ // next try "path"
+ if ( (f = fgopen(path, "rb")) == NULL ) {
+ return(FG_OPTIONS_ERROR);
+ }
+ }
+
+ fgPrintf(FG_GENERAL, FG_INFO, "Processing config file: %s\n", path);
+
+ while ( fggets(f, line, 250) != NULL ) {
+ // strip trailing newline if it exists
+ len = strlen(line);
+ if ( line[len-1] == '\n' ) {
+ line[len-1] = '\0';
+ }
+
+ result = parse_option(line);
+ if ( result == FG_OPTIONS_ERROR ) {
+ fgPrintf( FG_GENERAL, FG_EXIT,
+ "Config file parse error: %s '%s'\n", path, line );
+ }
+ }
+
+ fgclose(f);
+ return(FG_OPTIONS_OK);
+}
+
+
// Print usage message
void fgOPTIONS::usage ( void ) {
printf("Usage: fg [ options ... ]\n");
printf("General Options:\n");
printf("\t--help -h: print usage\n");
+ printf("\t--fg-root=path: specify the root path for all the data files\n");
printf("\n");
printf("Features:\n");
printf("Rendering Options:\n");
printf("\t--disable-fog: disable fog/haze\n");
printf("\t--enable-fog: enable fog/haze\n");
+ printf("\t--fov=xx.x: specify the field of view angle in degrees\n");
printf("\t--disable-fullscreen: disable fullscreen mode\n");
printf("\t--enable-fullscreen: enable fullscreen mode\n");
printf("\t--shading-flat: enable flat shading\n");
// $Log$
+// Revision 1.9 1998/05/13 18:29:59 curt
+// Added a keyboard binding to dynamically adjust field of view.
+// Added a command line option to specify fov.
+// Adjusted terrain color.
+// Root path info moved to fgOPTIONS.
+// Added ability to parse options out of a config file.
+//
// Revision 1.8 1998/05/07 23:14:16 curt
// Added "D" key binding to set autopilot heading.
// Made frame rate calculation average out over last 10 frames.