FlightGear-Points of Interest
Jump to navigation
Jump to search
FlightGear Entrypoint
see $FG_SRC/Main/bootstrap.cxx int main(int, char**):
// Main entry point; catch any exceptions that have made it this far.
int main ( int argc, char **argv ) {
_bootstrap_OSInit = 0;
#if defined(__linux__) && defined(__i386__)
// Enable floating-point exceptions for Linux/x86
initFPE();
#elif defined(__FreeBSD__)
// Ignore floating-point exceptions on FreeBSD
signal(SIGFPE, SIG_IGN);
#endif
#if defined(sgi)
flush_fpe();
// Bind all non-rendering threads to CPU1
// This will reduce the jitter caused by them to an absolute minimum,
// but it will only work with superuser authority.
if ( geteuid() == 0 )
{
sysmp(MP_CLOCK, 0); // bind the timer only to CPU0
sysmp(MP_ISOLATE, 1 ); // Isolate CPU1
sysmp(MP_NONPREEMPTIVE, 1 ); // disable process time slicing on CPU1
}
#endif
// Enable floating-point exceptions for Windows
#if defined( _MSC_VER ) && defined( DEBUG )
// Christian, we should document what this does
_control87( _EM_INEXACT, _MCW_EM );
#endif
#if defined( HAVE_BC5PLUS )
_control87(MCW_EM, MCW_EM); /* defined in float.h */
#endif
// Keyboard focus hack
#if defined(__APPLE__) && !defined(OSX_BUNDLE)
{
PSN psn;
fgOSInit (&argc, argv);
_bootstrap_OSInit++;
CPSGetCurrentProcess(&psn);
CPSSetProcessName(&psn, "FlightGear");
CPSEnableFG(&psn);
CPSSetFrontProcess(&psn);
}
#endif
// FIXME: add other, more specific
// exceptions.
try {
std::set_terminate(fg_terminate);
atexit(fgExitCleanup);
fgMainInit(argc, argv);
} catch (const sg_throwable &t) {
// We must use cerr rather than
// logging, since logging may be
// disabled.
cerr << "Fatal error: " << t.getFormattedMessage() << endl;
if (!t.getOrigin().empty())
cerr << " (received from " << t.getOrigin() << ')' << endl;
} catch (const string &s) {
cerr << "Fatal error: " << s << endl;
} catch (const char *s) {
cerr << "Fatal error: " << s << endl;
} catch (...) {
cerr << "Unknown exception in the main loop. Aborting..." << endl;
if (errno)
perror("Possible cause");
}
return 0;
}
Main Initialization
See $FG_SRC/Main/main.cxx: fgMainInit(int, char**):
// Main top level initialization
bool fgMainInit( int argc, char **argv ) {
#if defined( macintosh )
freopen ("stdout.txt", "w", stdout );
freopen ("stderr.txt", "w", stderr );
argc = ccommand( &argv );
#endif
// set default log levels
sglog().setLogLevels( SG_ALL, SG_ALERT );
string version;
#ifdef FLIGHTGEAR_VERSION
version = FLIGHTGEAR_VERSION;
#else
version = "unknown version";
#endif
SG_LOG( SG_GENERAL, SG_INFO, "FlightGear: Version "
<< version );
SG_LOG( SG_GENERAL, SG_INFO, "Built with " << SG_COMPILER_STR << endl );
// Allocate global data structures. This needs to happen before
// we parse command line options
globals = new FGGlobals;
// seed the random number generator
sg_srandom_time();
FGControls *controls = new FGControls;
globals->set_controls( controls );
string_list *col = new string_list;
globals->set_channel_options_list( col );
upper_case_property("/sim/presets/airport-id");
upper_case_property("/sim/presets/runway");
upper_case_property("/sim/tower/airport-id");
// Scan the config file(s) and command line options to see if
// fg_root was specified (ignore all other options for now)
fgInitFGRoot(argc, argv);
// Check for the correct base package version
static char required_version[] = "1.0.0";
string base_version = fgBasePackageVersion();
if ( !(base_version == required_version) ) {
// tell the operator how to use this application
SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on windows
cerr << endl << "Base package check failed ... " \
<< "Found version " << base_version << " at: " \
<< globals->get_fg_root() << endl;
cerr << "Please upgrade to version: " << required_version << endl;
#ifdef _MSC_VER
cerr << "Hit a key to continue..." << endl;
cin.get();
#endif
exit(-1);
}
// Load the configuration parameters. (Command line options
// override config file options. Config file options override
// defaults.)
if ( !fgInitConfig(argc, argv) ) {
SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
exit(-1);
}
// Initialize the Window/Graphics environment.
#if !defined(__APPLE__) || defined(OSX_BUNDLE)
// Mac OS X command line ("non-bundle") applications call this
// from main(), in bootstrap.cxx. Andy doesn't know why, someone
// feel free to add comments...
fgOSInit(&argc, argv);
_bootstrap_OSInit++;
#endif
fgRegisterWindowResizeHandler( &FGRenderer::resize );
fgRegisterIdleHandler( &fgIdleFunction );
fgRegisterDrawHandler( &FGRenderer::update );
#ifdef FG_ENABLE_MULTIPASS_CLOUDS
bool get_stencil_buffer = true;
#else
bool get_stencil_buffer = false;
#endif
// Initialize plib net interface
netInit( &argc, argv );
// Clouds3D requires an alpha channel
// clouds may require stencil buffer
fgOSOpenWindow( fgGetInt("/sim/startup/xsize"),
fgGetInt("/sim/startup/ysize"),
fgGetInt("/sim/rendering/bits-per-pixel"),
fgGetBool("/sim/rendering/clouds3d-enable"),
get_stencil_buffer,
fgGetBool("/sim/startup/fullscreen") );
// Initialize the splash screen right away
fntInit();
fgSplashInit();
// pass control off to the master event handler
fgOSMainLoop();
// we never actually get here ... but to avoid compiler warnings,
// etc.
return false;
}
Parameter Processing
See $FG_SRC/Main/options.cxx:
/*
option has_param type property b_param s_param func
where:
option : name of the option
has_param : option is --name=value if true or --name if false
type : OPTION_BOOL - property is a boolean
OPTION_STRING - property is a string
OPTION_DOUBLE - property is a double
OPTION_INT - property is an integer
OPTION_CHANNEL - name of option is the name of a channel
OPTION_FUNC - the option trigger a function
b_param : if type==OPTION_BOOL,
value set to the property (has_param is false for boolean)
s_param : if type==OPTION_STRING,
value set to the property if has_param is false
func : function called if type==OPTION_FUNC. if has_param is true,
the value is passed to the function as a string, otherwise,
0 is passed.
For OPTION_DOUBLE and OPTION_INT, the parameter value is converted into a
double or an integer and set to the property.
For OPTION_CHANNEL, add_channel is called with the parameter value as the
argument.
*/
enum OptionType { OPTION_BOOL, OPTION_STRING, OPTION_DOUBLE, OPTION_INT, OPTION_CHANNEL, OPTION_FUNC };
struct OptionDesc {
char *option;
bool has_param;
enum OptionType type;
char *property;
bool b_param;
char *s_param;
int (*func)( const char * );
} fgOptionArray[] = {
{"language", true, OPTION_FUNC, "", false, "", fgOptLanguage },
{"disable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", false, "", 0 },
{"enable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", true, "", 0 },
{"disable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", false, "", 0 },
{"enable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", true, "", 0 },
{"disable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", false, "", 0 },
{"enable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", true, "", 0 },
{"disable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
{"enable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
{"disable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", false, "", 0 },
{"enable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", true, "", 0 },
{"disable-real-weather-fetch", false, OPTION_BOOL, "/environment/params/real-world-weather-fetch", false, "", 0 },
{"enable-real-weather-fetch", false, OPTION_BOOL, "/environment/params/real-world-weather-fetch", true, "", 0 },
{"disable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", false, "", 0 },
{"enable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", true, "", 0 },
{"disable-freeze", false, OPTION_BOOL, "/sim/freeze/master", false, "", 0 },
{"enable-freeze", false, OPTION_BOOL, "/sim/freeze/master", true, "", 0 },
{"disable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", false, "", 0 },
{"enable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", true, "", 0 },
{"disable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", false, "", 0 },
{"enable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", true, "", 0 },
{"disable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d", false, "", 0 },
{"enable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d", true, "", 0 },
{"disable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", false, "", 0 },
{"enable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", true, "", 0 },
{"control", true, OPTION_STRING, "/sim/control-mode", false, "", 0 },
{"disable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", false, "", 0 },
{"enable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", true, "", 0 },
{"browser-app", true, OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
{"disable-hud", false, OPTION_BOOL, "/sim/hud/visibility", false, "", 0 },
{"enable-hud", false, OPTION_BOOL, "/sim/hud/visibility", true, "", 0 },
{"disable-panel", false, OPTION_BOOL, "/sim/panel/visibility", false, "", 0 },
{"enable-panel", false, OPTION_BOOL, "/sim/panel/visibility", true, "", 0 },
{"disable-sound", false, OPTION_BOOL, "/sim/sound/pause", true, "", 0 },
{"enable-sound", false, OPTION_BOOL, "/sim/sound/pause", false, "", 0 },
{"airport", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
{"runway", true, OPTION_FUNC, "", false, "", fgOptRunway },
{"vor", true, OPTION_FUNC, "", false, "", fgOptVOR },
{"ndb", true, OPTION_FUNC, "", false, "", fgOptNDB },
{"carrier", true, OPTION_FUNC, "", false, "", fgOptCarrier },
{"parkpos", true, OPTION_FUNC, "", false, "", fgOptParkpos },
{"fix", true, OPTION_FUNC, "", false, "", fgOptFIX },
{"offset-distance", true, OPTION_DOUBLE, "/sim/presets/offset-distance", false, "", 0 },
{"offset-azimuth", true, OPTION_DOUBLE, "/sim/presets/offset-azimuth", false, "", 0 },
{"lon", true, OPTION_FUNC, "", false, "", fgOptLon },
{"lat", true, OPTION_FUNC, "", false, "", fgOptLat },
{"altitude", true, OPTION_FUNC, "", false, "", fgOptAltitude },
{"uBody", true, OPTION_FUNC, "", false, "", fgOptUBody },
{"vBody", true, OPTION_FUNC, "", false, "", fgOptVBody },
{"wBody", true, OPTION_FUNC, "", false, "", fgOptWBody },
{"vNorth", true, OPTION_FUNC, "", false, "", fgOptVNorth },
{"vEast", true, OPTION_FUNC, "", false, "", fgOptVEast },
{"vDown", true, OPTION_FUNC, "", false, "", fgOptVDown },
{"vc", true, OPTION_FUNC, "", false, "", fgOptVc },
{"mach", true, OPTION_FUNC, "", false, "", fgOptMach },
{"heading", true, OPTION_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
{"roll", true, OPTION_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
{"pitch", true, OPTION_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
{"glideslope", true, OPTION_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
{"roc", true, OPTION_FUNC, "", false, "", fgOptRoc },
{"fg-root", true, OPTION_FUNC, "", false, "", fgOptFgRoot },
{"fg-scenery", true, OPTION_FUNC, "", false, "", fgOptFgScenery },
{"fdm", true, OPTION_STRING, "/sim/flight-model", false, "", 0 },
{"aero", true, OPTION_STRING, "/sim/aero", false, "", 0 },
{"aircraft-dir", true, OPTION_STRING, "/sim/aircraft-dir", false, "", 0 },
{"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 },
{"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 },
{"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 },
{"notrim", false, OPTION_BOOL, "/sim/presets/trim", false, "", 0 },
{"on-ground", false, OPTION_BOOL, "/sim/presets/onground", true, "", 0 },
{"in-air", false, OPTION_BOOL, "/sim/presets/onground", false, "", 0 },
{"fog-disable", false, OPTION_STRING, "/sim/rendering/fog", false, "disabled", 0 },
{"fog-fastest", false, OPTION_STRING, "/sim/rendering/fog", false, "fastest", 0 },
{"fog-nicest", false, OPTION_STRING, "/sim/rendering/fog", false, "nicest", 0 },
{"disable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", false, "", 0 },
{"enable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", true, "", 0 },
{"disable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", false, "", 0 },
{"enable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", true, "", 0 },
{"disable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", false, "", 0 },
{"enable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", true, "", 0 },
{"disable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", false, "", 0 },
{"enable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", true, "", 0 },
{"disable-clouds", false, OPTION_BOOL, "/environment/clouds/status", false, "", 0 },
{"enable-clouds", false, OPTION_BOOL, "/environment/clouds/status", true, "", 0 },
{"disable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", false, "", 0 },
{"enable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", true, "", 0 },
{"fov", true, OPTION_FUNC, "", false, "", fgOptFov },
{"aspect-ratio-multiplier", true, OPTION_DOUBLE, "/sim/current-view/aspect-ratio-multiplier", false, "", 0 },
{"disable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", false, "", 0 },
{"enable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", true, "", 0 },
{"disable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", false, "", 0 },
{"enable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", true, "", 0 },
{"shading-flat", false, OPTION_BOOL, "/sim/rendering/shading", false, "", 0 },
{"shading-smooth", false, OPTION_BOOL, "/sim/rendering/shading", true, "", 0 },
{"disable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", false, "", 0 },
{"enable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", true, "", 0 },
{"disable-textures", false, OPTION_BOOL, "/sim/rendering/textures", false, "", 0 },
{"enable-textures", false, OPTION_BOOL, "/sim/rendering/textures", true, "", 0 },
{"texture-filtering", false, OPTION_INT, "/sim/rendering/filtering", 1, "", 0 },
{"disable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", false, "", 0 },
{"enable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", true, "", 0 },
{"geometry", true, OPTION_FUNC, "", false, "", fgOptGeometry },
{"bpp", true, OPTION_FUNC, "", false, "", fgOptBpp },
{"units-feet", false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
{"units-meters", false, OPTION_STRING, "/sim/startup/units", false, "meters", 0 },
{"timeofday", true, OPTION_STRING, "/sim/startup/time-offset-type", false, "noon", 0 },
{"season", true, OPTION_STRING, "/sim/startup/season", false, "summer", 0 },
{"time-offset", true, OPTION_FUNC, "", false, "", fgOptTimeOffset },
{"time-match-real", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
{"time-match-local", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
{"start-date-sys", true, OPTION_FUNC, "", false, "", fgOptStartDateSys },
{"start-date-lat", true, OPTION_FUNC, "", false, "", fgOptStartDateLat },
{"start-date-gmt", true, OPTION_FUNC, "", false, "", fgOptStartDateGmt },
{"hud-tris", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
{"hud-culled", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
{"atcsim", true, OPTION_CHANNEL, "", false, "dummy", 0 },
{"atlas", true, OPTION_CHANNEL, "", false, "", 0 },
{"httpd", true, OPTION_CHANNEL, "", false, "", 0 },
#ifdef FG_JPEG_SERVER
{"jpg-httpd", true, OPTION_CHANNEL, "", false, "", 0 },
#endif
{"native", true, OPTION_CHANNEL, "", false, "", 0 },
{"native-ctrls", true, OPTION_CHANNEL, "", false, "", 0 },
{"native-fdm", true, OPTION_CHANNEL, "", false, "", 0 },
{"native-gui", true, OPTION_CHANNEL, "", false, "", 0 },
{"opengc", true, OPTION_CHANNEL, "", false, "", 0 },
{"AV400", true, OPTION_CHANNEL, "", false, "", 0 },
{"garmin", true, OPTION_CHANNEL, "", false, "", 0 },
{"nmea", true, OPTION_CHANNEL, "", false, "", 0 },
{"generic", true, OPTION_CHANNEL, "", false, "", 0 },
{"props", true, OPTION_CHANNEL, "", false, "", 0 },
{"telnet", true, OPTION_CHANNEL, "", false, "", 0 },
{"pve", true, OPTION_CHANNEL, "", false, "", 0 },
{"ray", true, OPTION_CHANNEL, "", false, "", 0 },
{"rul", true, OPTION_CHANNEL, "", false, "", 0 },
{"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
{"jsclient", true, OPTION_CHANNEL, "", false, "", 0 },
{"proxy", true, OPTION_FUNC, "", false, "", fgSetupProxy },
{"callsign", true, OPTION_STRING, "sim/multiplay/callsign", false, "", 0 },
{"multiplay", true, OPTION_CHANNEL, "", false, "", 0 },
{"trace-read", true, OPTION_FUNC, "", false, "", fgOptTraceRead },
{"trace-write", true, OPTION_FUNC, "", false, "", fgOptTraceWrite },
{"log-level", true, OPTION_FUNC, "", false, "", fgOptLogLevel },
{"view-offset", true, OPTION_FUNC, "", false, "", fgOptViewOffset },
{"visibility", true, OPTION_FUNC, "", false, "", fgOptVisibilityMeters },
{"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles },
{"random-wind", false, OPTION_FUNC, "", false, "", fgOptRandomWind },
{"wind", true, OPTION_FUNC, "", false, "", fgOptWind },
{"turbulence", true, OPTION_FUNC, "", false, "", fgOptTurbulence },
{"ceiling", true, OPTION_FUNC, "", false, "", fgOptCeiling },
{"wp", true, OPTION_FUNC, "", false, "", fgOptWp },
{"flight-plan", true, OPTION_FUNC, "", false, "", fgOptFlightPlan },
{"config", true, OPTION_FUNC, "", false, "", fgOptConfig },
{"aircraft", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
{"vehicle", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
{"failure", true, OPTION_FUNC, "", false, "", fgOptFailure },
{"com1", true, OPTION_DOUBLE, "/instrumentation/comm[0]/frequencies/selected-mhz", false, "", 0 },
{"com2", true, OPTION_DOUBLE, "/instrumentation/comm[1]/frequencies/selected-mhz", false, "", 0 },
{"nav1", true, OPTION_FUNC, "", false, "", fgOptNAV1 },
{"nav2", true, OPTION_FUNC, "", false, "", fgOptNAV2 },
{"adf", true, OPTION_FUNC, "", false, "", fgOptADF },
{"dme", true, OPTION_FUNC, "", false, "", fgOptDME },
{"min-status", true, OPTION_STRING, "/sim/aircraft-min-status", false, "all", 0 },
{"livery", true, OPTION_FUNC, "", false, "", fgOptLivery },
{"ai-scenario", true, OPTION_FUNC, "", false, "", fgOptScenario },
{"parking-id", true, OPTION_FUNC, "", false, "", fgOptParking },
{"version", false, OPTION_FUNC, "", false, "", fgOptVersion },
{0}
};
Main Loop
See $FG_SRC/Main/main.cxx: void fgMainLoop(): (TODO)